# Path: nuka/tasks/file.py
# class exists(Task):
# class mkdir(Task):
# class mkdirs(Task):
# class rm(Task):
# class mv(Task):
# class chmod(Task):
# class chown(Task):
# class put(Task):
# class scripts(put):
# class cat(Task):
# class update(Task):
#     def __init__(self, dst=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, dst=None, mod=None, own=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, directories=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, dst=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, src=None, dst=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, dst=None, mod='644', recursive=False, **kwargs):
#     def do(self):
#     def __init__(self, dst=None, own='root:root', recursive=False, **kwargs):
#     def do(self):
#     def __init__(self, files=None, **kwargs):
#     def pre_process(self):
#     def do(self):
#     def diff(self):
#     def do(self):
#     def __init__(self, src=None, **kwargs):
#     def do(self):
#     def __init__(self, dst=None, replaces=None, appends=None, **kwargs):
#     def pre_process(self):
#     def update(self, data):
#     def do(self):
#     def diff(self, dst=None, **kwargs):
# 
# Path: nuka/tasks/user.py
# class delete_user(Task):
# class create_user(Task):
# class create_www_user(create_user):
# class authorized_keys(file.put):
#     def __init__(self, username=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, username=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, username=None, keys=None, keysfile=None, **kwargs):
#     def do(self):
# 
# Path: nuka/tasks/shell.py
# class shell(Task):
#     """run a shell line (allow pipes)"""
# 
#     def __init__(self, cmd=None, **kwargs):
#         kwargs.setdefault('name', cmd)
#         super(shell, self).__init__(cmd=cmd, **kwargs)
# 
#     def do(self):
#         kwargs = {'shell': True}
#         watch = self.args.get('watch')
#         if watch:  # pragma: no cover
#             kwargs['watcher'] = utils.default_watcher(delay=watch)
#         cmd = self.args['cmd']
#         if isinstance(cmd, list):
#             cmd = ' '.join(cmd)
#         res = self.sh(cmd, **kwargs)
#         res.pop('stderr')
#         return res


import pytest
from nuka.tasks import file
from nuka.tasks import user
from nuka.tasks import shell

@pytest.mark.asyncio
async def test_create_user(host, diff_mode):
    diff_mode(False)
    assert (await user.delete_user('test_user1'))

    with diff_mode:
        res = await user.delete_user(username='test_user1')
        assert '-test_user1' not in res.res['diff']

        res = await user.create_user(username='test_user1')
        assert '+test_user1' in res.res['diff']

    assert (await user.create_user(username='test_user1'))

    with diff_mode:
        res = await user.delete_user(username='test_user1')
        assert '-test_user1' in res.res['diff']

        res = await user.create_user(username='test_user1')
        assert '+test_user1' not in res.res['diff']

    assert (await user.delete_user('test_user1'))
    assert not (await file.exists('/home/test_user1'))
    assert (await user.create_user(username='test_user1'))
    assert (await file.exists('/home/test_user1'))
    res = await shell.shell(['whoami'], switch_user='test_user1')
    assert res.stdout.strip() == 'test_user1'

    assert (await user.delete_user('test_user1'))

# Path: nuka/tasks/file.py
# class exists(Task):
# class mkdir(Task):
# class mkdirs(Task):
# class rm(Task):
# class mv(Task):
# class chmod(Task):
# class chown(Task):
# class put(Task):
# class scripts(put):
# class cat(Task):
# class update(Task):
#     def __init__(self, dst=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, dst=None, mod=None, own=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, directories=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, dst=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, src=None, dst=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, dst=None, mod='644', recursive=False, **kwargs):
#     def do(self):
#     def __init__(self, dst=None, own='root:root', recursive=False, **kwargs):
#     def do(self):
#     def __init__(self, files=None, **kwargs):
#     def pre_process(self):
#     def do(self):
#     def diff(self):
#     def do(self):
#     def __init__(self, src=None, **kwargs):
#     def do(self):
#     def __init__(self, dst=None, replaces=None, appends=None, **kwargs):
#     def pre_process(self):
#     def update(self, data):
#     def do(self):
#     def diff(self, dst=None, **kwargs):
# 
# Path: nuka/tasks/user.py
# class delete_user(Task):
# class create_user(Task):
# class create_www_user(create_user):
# class authorized_keys(file.put):
#     def __init__(self, username=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, username=None, **kwargs):
#     def do(self):
#     def diff(self):
#     def __init__(self, username=None, keys=None, keysfile=None, **kwargs):
#     def do(self):
# 
# Path: nuka/tasks/shell.py
# class shell(Task):
#     """run a shell line (allow pipes)"""
# 
#     def __init__(self, cmd=None, **kwargs):
#         kwargs.setdefault('name', cmd)
#         super(shell, self).__init__(cmd=cmd, **kwargs)
# 
#     def do(self):
#         kwargs = {'shell': True}
#         watch = self.args.get('watch')
#         if watch:  # pragma: no cover
#             kwargs['watcher'] = utils.default_watcher(delay=watch)
#         cmd = self.args['cmd']
#         if isinstance(cmd, list):
#             cmd = ' '.join(cmd)
#         res = self.sh(cmd, **kwargs)
#         res.pop('stderr')
#         return res


# Path: tests/tasks/test_user.py
import pytest
from nuka.tasks import file
from nuka.tasks import user
from nuka.tasks import shell


@pytest.mark.asyncio
async def test_create_user(host, diff_mode):
    diff_mode(False)
    assert (await user.delete_user('test_user1'))

    with diff_mode:
        res = await user.delete_user(username='test_user1')
        assert '-test_user1' not in res.res['diff']

        res = await user.create_user(username='test_user1')
        assert '+test_user1' in res.res['diff']

    assert (await user.create_user(username='test_user1'))

    with diff_mode:
        res = await user.delete_user(username='test_user1')
        assert '-test_user1' in res.res['diff']

        res = await user.create_user(username='test_user1')
        assert '+test_user1' not in res.res['diff']

    assert (await user.delete_user('test_user1'))
    assert not (await file.exists('/home/test_user1'))
    assert (await user.create_user(username='test_user1'))
    assert (await file.exists('/home/test_user1'))
    res = await shell.shell(['whoami'], switch_user='test_user1')
    assert res.stdout.strip() == 'test_user1'

    assert (await user.delete_user('test_user1'))

    assert not (await file.exists('/home/test_user1'))