Python mock.patch.multiple() Examples

The following are 30 code examples of mock.patch.multiple(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mock.patch , or try the search function .
Example #1
Source File: test_current.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_release_without_stage(self):
        message = "No need to stage this"
        mocked_os = MagicMock()
        mocked_stage = MagicMock()

        mocked_os.close.return_value = 0

        with patch.multiple("gitfs.views.current", os=mocked_os):
            current = CurrentView(
                repo="repo", repo_path="repo_path", ignore=CachedIgnore()
            )
            current._stage = mocked_stage
            current.dirty = {4: {"message": message, "stage": False}}

            assert current.release("/path", 4) == 0

            mocked_os.close.assert_called_once_with(4)
            assert mocked_stage.call_count == 0 
Example #2
Source File: test_manager.py    From pyolite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def test_get_or_create_method():
    mocked_path = MagicMock()
    mocked_git = MagicMock()

    mocked_get = MagicMock(return_value='user')
    mocked_create = MagicMock()

    Manager.get = mocked_get
    Manager.create = mocked_create

    with patch.multiple('pyolite.managers.manager',
                        Path=MagicMock(return_value=mocked_path),
                        Git=MagicMock(return_value=mocked_git)):
        with patch.multiple('pyolite.managers.manager.Manager',
                            __abstractmethods__=set()):
            manager = Manager('/path/to/admin/repo')

            assert manager.get_or_create('mine', 'key') == 'user'
            mocked_get.assert_called_once_with('mine') 
Example #3
Source File: test_repository.py    From pyolite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def test_it_should_not_be_valid_a_repo_starting_with_the_same_name():
    mocked_users = MagicMock()
    mocked_file = MagicMock()
    mocked_dir = MagicMock()
    mocked_path = MagicMock()

    mocked_dir.isdir.return_value = True
    mocked_file.isdir.return_value = False
    mocked_file.__str__ = lambda x: 'tests/fixtures/almost_get_repo_by_name.conf'

    mocked_path.walk.return_value = [mocked_file, mocked_dir]

    with patch.multiple('pyolite.models.repository',
                        Path=MagicMock(return_value=mocked_path),
                        ListUsers=MagicMock(return_value=mocked_users)):
        assert Repository.get_by_name('new_one', 'simple_path', 'git') is None 
Example #4
Source File: test_rds.py    From awslimitchecker with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_usage(self):
        mock_conn = Mock()

        with patch('%s.connect' % self.pb) as mock_connect:
            with patch.multiple(
                    self.pb,
                    _find_usage_instances=DEFAULT,
                    _find_usage_subnet_groups=DEFAULT,
                    _find_usage_security_groups=DEFAULT,
                    _update_limits_from_api=DEFAULT,
            ) as mocks:
                cls = _RDSService(21, 43, {}, None)
                cls.conn = mock_conn
                assert cls._have_usage is False
                cls.find_usage()
        assert mock_connect.mock_calls == [call()]
        assert cls._have_usage is True
        for x in [
                '_find_usage_instances',
                '_find_usage_subnet_groups',
                '_find_usage_security_groups',
                '_update_limits_from_api',
        ]:
            assert mocks[x].mock_calls == [call()] 
Example #5
Source File: test_route53.py    From awslimitchecker with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_update_limits_from_api(self):
        """test _update_limits_from_api method calls other methods"""

        mock_conn = Mock()
        with patch('%s.connect' % pb) as mock_connect:
            with patch.multiple(
                    pb,
                    _find_limit_hosted_zone=DEFAULT,
            ) as mocks:
                cls = _Route53Service(21, 43, {}, None)
                cls.conn = mock_conn
                cls._update_limits_from_api()
        assert mock_connect.mock_calls == [call()]
        assert mock_conn.mock_calls == []
        for x in [
            '_find_limit_hosted_zone',
        ]:
            assert mocks[x].mock_calls == [call()] 
Example #6
Source File: test_router.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_destroy(self):
        mocked_fetch = MagicMock()
        mocked_sync = MagicMock()

        router, mocks = self.get_new_router()
        router.workers = [mocked_fetch, mocked_sync]

        with patch.multiple(
            "gitfs.router",
            shutil=mocks["shutil"],
            fetch=mocks["fetch"],
            shutting_down=mocks["shutting"],
        ):
            router.destroy("path")

        assert mocked_fetch.join.call_count == 1
        assert mocked_sync.join.call_count == 1
        assert mocks["fetch"].set.call_count == 1
        assert mocks["shutting"].set.call_count == 1
        mocks["shutil"].rmtree.assert_called_once_with(mocks["repo_path"]) 
Example #7
Source File: test_user.py    From pyolite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def test_if_a_user_can_be_retrieved_by_name():
    mocks = set_mocks()

    with patch.multiple('pyolite.models.user', Path=mocks['path'],
                        ListKeys=mocks['keys']):
        user = User(mocks['initial_path'], mocks['git'], 'vtemian', repos=None,
                    keys=[mocks['first_key']])
        test_user = User.get_by_name('vtemian', mocks['initial_path'],
                                     mocks['git'])

        assert test_user.name == user.name
        assert test_user.repos == user.repos
        assert test_user.keys == user.keys
        assert test_user.path == user.path
        assert test_user.git == user.git

        mocks['path'].has_calls([
            call('path', 'keydir'),
            call('path', 'conf/')
        ])

        assert str(test_user) == '< vtemian >'
        assert repr(test_user) == '< vtemian >' 
Example #8
Source File: test_router.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_call_with_valid_operation(self):
        mocked_view = MagicMock()
        mocked_cache = MagicMock()
        mocked_idle_event = MagicMock()

        router, mocks = self.get_new_router()

        router.register([("/", MagicMock(return_value=mocked_view))])
        with patch.multiple(
            "gitfs.router", idle=mocked_idle_event, lru_cache=mocked_cache
        ):
            mocked_cache.get_if_exists.return_value = None
            result = router("random_operation", "/")

            assert result == mocked_view.random_operation("/")
            assert mocked_idle_event.clear.call_count == 1 
Example #9
Source File: test_decorators.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_while_not(self):
        an_event = Event()
        an_event.set()

        mocked_method = MagicMock()
        mocked_time = MagicMock()

        mocked_time.sleep.side_effect = lambda x: an_event.clear()
        mocked_method.__name__ = "name"

        with patch.multiple(
            "gitfs.utils.decorators.while_not", wraps=MockedWraps, time=mocked_time
        ):
            not_now = while_not(an_event)
            not_now(mocked_method)("arg", kwarg="kwarg")

            mocked_time.sleep.assert_called_once_with(0.2) 
Example #10
Source File: test_mount.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_args(self):
        mocked_parser = MagicMock()
        mocked_args = MagicMock()

        mocked_args.return_value = "args"

        with patch.multiple("gitfs.mounter", Args=mocked_args):
            assert parse_args(mocked_parser) == "args"
            asserted_calls = [
                call("remote_url", help="repo to be cloned"),
                call("mount_point", help="where the repo should be mount"),
                call(
                    "-o",
                    help="other options: repo_path, "
                    + "user, group, branch, max_size, "
                    + "max_offset, fetch_timeout, merge_timeout",
                ),
            ]
            mocked_parser.add_argument.has_calls(asserted_calls) 
Example #11
Source File: test_apigateway.py    From awslimitchecker with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_usage(self):
        mock_conn = Mock()
        with patch('%s.connect' % pb) as mock_connect:
            with patch.multiple(
                pb,
                autospec=True,
                _find_usage_apis=DEFAULT,
                _find_usage_api_keys=DEFAULT,
                _find_usage_certs=DEFAULT,
                _find_usage_plans=DEFAULT,
                _find_usage_vpc_links=DEFAULT
            ) as mocks:
                cls = _ApigatewayService(21, 43, {}, None)
                cls.conn = mock_conn
                assert cls._have_usage is False
                cls.find_usage()
        assert mock_connect.mock_calls == [call()]
        assert cls._have_usage is True
        assert mock_conn.mock_calls == []
        assert mocks['_find_usage_apis'].mock_calls == [call(cls)]
        assert mocks['_find_usage_api_keys'].mock_calls == [call(cls)]
        assert mocks['_find_usage_certs'].mock_calls == [call(cls)]
        assert mocks['_find_usage_plans'].mock_calls == [call(cls)]
        assert mocks['_find_usage_vpc_links'].mock_calls == [call(cls)] 
Example #12
Source File: test_elasticbeanstalk.py    From awslimitchecker with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_usage(self):
        """test find usage method calls other methods"""
        mock_conn = Mock()
        with patch('%s.connect' % pb) as mock_connect:
            with patch.multiple(
                pb,
                _find_usage_applications=DEFAULT,
                _find_usage_application_versions=DEFAULT,
                _find_usage_environments=DEFAULT,
            ) as mocks:
                cls = _ElasticBeanstalkService(21, 43, {}, None)
                cls.conn = mock_conn
                assert cls._have_usage is False
                cls.find_usage()
        assert mock_connect.mock_calls == [call()]
        assert cls._have_usage is True
        assert mock_conn.mock_calls == []
        for x in [
            '_find_usage_applications',
            '_find_usage_application_versions',
            '_find_usage_environments',
        ]:
            assert mocks[x].mock_calls == [call()] 
Example #13
Source File: test_current.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_open(self):
        mocked_full = MagicMock(return_value="full_path")
        mocked_repo = MagicMock(_full_path=mocked_full)
        mocked_os = MagicMock()

        mocked_os.open.return_value = 1

        with patch.multiple("gitfs.views.current", os=mocked_os):
            current = CurrentView(
                repo=mocked_repo, repo_path="repo_path", ignore=CachedIgnore()
            )

            current._full_path = mocked_full
            current.writing = set([])

            assert current.open("path/", os.O_WRONLY) == 1
            mocked_os.open.assert_called_once_with("full_path", os.O_WRONLY) 
Example #14
Source File: test_redshift.py    From awslimitchecker with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_find_usage(self):
        """test find usage method calls other methods"""
        mock_conn = Mock()
        with patch('%s.connect' % pb) as mock_connect:
            with patch.multiple(
                pb,
                _find_cluster_manual_snapshots=DEFAULT,
                _find_cluster_subnet_groups=DEFAULT,
            ) as mocks:
                cls = _RedshiftService(21, 43, {}, None)
                cls.conn = mock_conn
                assert cls._have_usage is False
                cls.find_usage()
        assert mock_connect.mock_calls == [call()]
        assert cls._have_usage is True
        assert mock_conn.mock_calls == []
        for x in [
            '_find_cluster_manual_snapshots',
            '_find_cluster_subnet_groups',
        ]:
            assert mocks[x].mock_calls == [call()] 
Example #15
Source File: test_gitignore.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_init(self):
        mocked_os = MagicMock()
        mocked_os.path.exists.return_value = True
        mocked_re = MagicMock()
        mocked_re.findall.return_value = [[None, None, "found"]]

        with patch("gitfs.cache.gitignore.open", create=True) as mocked_open:
            mocked_file = mocked_open.return_value.__enter__.return_value
            mocked_file.read.return_value = "file"

            with patch.multiple("gitfs.cache.gitignore", os=mocked_os, re=mocked_re):
                gitignore = CachedIgnore("some_file", "some_file")

                assert gitignore.items == [
                    ".git",
                    ".git/*",
                    "/.git/*",
                    "*.keep",
                    "*.gitmodules",
                    "/found/*",
                    "/found",
                    "found",
                ] 
Example #16
Source File: test_fetch.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_work(self):
        mocked_peasant = MagicMock()
        mocked_fetch = MagicMock(side_effect=ValueError)
        mocked_fetch_event = MagicMock()

        with patch.multiple(
            "gitfs.worker.fetch", Peasant=mocked_peasant, fetch=mocked_fetch_event
        ):
            worker = FetchWorker()
            worker.fetch = mocked_fetch
            worker.timeout = 5

            with pytest.raises(ValueError):
                worker.work()

            assert mocked_fetch.call_count == 1
            mocked_fetch_event.wait.assert_called_once_with(5) 
Example #17
Source File: test_checker.py    From awslimitchecker with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_check_version_not_old(self):
        with patch.multiple(
            'awslimitchecker.checker',
            logger=DEFAULT,
            _get_version_info=DEFAULT,
            TrustedAdvisor=DEFAULT,
            _get_latest_version=DEFAULT,
            autospec=True,
        ) as mocks:
            mocks['_get_version_info'].return_value = self.mock_ver_info
            mocks['_get_latest_version'].return_value = None
            AwsLimitChecker()
        assert mocks['_get_latest_version'].mock_calls == [call()]
        assert mocks['logger'].mock_calls == [
            call.debug('Connecting to region %s', None)
        ] 
Example #18
Source File: test_checker.py    From awslimitchecker with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_check_version_old(self):
        with patch.multiple(
            'awslimitchecker.checker',
            logger=DEFAULT,
            _get_version_info=DEFAULT,
            TrustedAdvisor=DEFAULT,
            _get_latest_version=DEFAULT,
            autospec=True,
        ) as mocks:
            mocks['_get_version_info'].return_value = self.mock_ver_info
            mocks['_get_latest_version'].return_value = '3.4.5'
            AwsLimitChecker()
        assert mocks['_get_latest_version'].mock_calls == [call()]
        assert mocks['logger'].mock_calls == [
            call.warning(
                'You are running awslimitchecker %s, but the latest version'
                ' is %s; please consider upgrading.', '1.2.3', '3.4.5'
            ),
            call.debug('Connecting to region %s', None)
        ] 
Example #19
Source File: test_users.py    From pyolite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def test_user_get_or_create(self):
        mocked_repo = MagicMock()
        mocked_repository = MagicMock()

        mocked_repository.name = 'test_repo'
        mocked_repository.path = 'path'

        with patch.multiple('pyolite.models.lists.users',
                            Repo=MagicMock(return_value=mocked_repo)):
            found_user = object()
            mocked_user_get = MagicMock(return_value=found_user)

            with patch.multiple('pyolite.models.user.User', get=mocked_user_get):
                repo_users = ListUsers(mocked_repository)

                # user found
                user = repo_users.get_or_create('test_user')
                assert user is found_user

                # user created
                mocked_user_get.side_effect = ValueError
                user = repo_users.get_or_create('test_user')
                assert user.name is 'test_user' 
Example #20
Source File: test_fetch.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_fetch_remote_is_down(self):
        mocked_fetch_ok = MagicMock()
        mocked_fetch = MagicMock()
        mocked_repo = MagicMock()

        mocked_repo.fetch = MagicMock(side_effect=ValueError)
        mocked_fetch_ok.set.side_effect = ValueError

        with patch.multiple(
            "gitfs.worker.fetch", fetch_successful=mocked_fetch_ok, fetch=mocked_fetch
        ):
            worker = FetchWorker(
                repository=mocked_repo,
                upstream="origin",
                credentials="credentials",
                branch="master",
            )
            worker.fetch()

            mocked_repo.fetch.assert_called_once_with("origin", "master", "credentials")
            assert mocked_fetch_ok.clear.call_count == 1
            assert mocked_fetch.clear.call_count == 1 
Example #21
Source File: test_fetch.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_fetch_in_idle_mode(self):
        mocked_peasant = MagicMock()
        mocked_fetch = MagicMock(side_effect=ValueError)
        mocked_fetch_event = MagicMock()
        mocked_idle = MagicMock()

        mocked_idle.is_set.return_value = True

        with patch.multiple(
            "gitfs.worker.fetch",
            Peasant=mocked_peasant,
            fetch=mocked_fetch_event,
            idle=mocked_idle,
        ):
            worker = FetchWorker()
            worker.fetch = mocked_fetch
            worker.timeout = 5
            worker.idle_timeout = 20

            with pytest.raises(ValueError):
                worker.work()

            assert mocked_fetch.call_count == 1
            mocked_fetch_event.wait.assert_called_once_with(20) 
Example #22
Source File: test_repo.py    From pyolite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def test_it_should_retrieve_all_users_from_repo():
    path = 'tests/fixtures/repo_users.conf'
    mocked_path = MagicMock()
    mocked_path.__str__ = lambda x: path

    mocked_path.exists.return_value = True

    mocked_re = MagicMock()
    mocked_user1 = MagicMock()
    mocked_user2 = MagicMock()

    mocked_re.compile('=( *)(\w+)').finditer.return_value = [mocked_user1,
                                                             mocked_user2]
    mocked_user1.group.return_value = 'user1'
    mocked_user2.group.return_value = 'user2'

    with patch.multiple('pyolite.repo', re=mocked_re):
        repo = Repo(mocked_path)
        assert repo.users == ['user1', 'user2'] 
Example #23
Source File: test_StateMachineDevice.py    From lewis with GNU General Public License v3.0 6 votes vote down vote up
def test_not_implemented_errors(self):
        # Construction of the base class should not be possible
        self.assertRaises(NotImplementedError, StateMachineDevice)

        mandatory_methods = {
            '_get_state_handlers': Mock(return_value={'test': MagicMock()}),
            '_get_initial_state': Mock(return_value='test'),
            '_get_transition_handlers': Mock(
                return_value={('test', 'test'): Mock(return_value=True)})
        }

        # If any of the mandatory methods is missing, a NotImplementedError must be raised
        for methods in itertools.combinations(mandatory_methods.items(), 2):
            with patch.multiple('lewis.devices.StateMachineDevice', **dict(methods)):
                self.assertRaises(NotImplementedError, StateMachineDevice)

        # If all are implemented, no exception should be raised
        with patch.multiple('lewis.devices.StateMachineDevice', **mandatory_methods):
            assertRaisesNothing(self, StateMachineDevice) 
Example #24
Source File: test_repo.py    From pyolite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_write_filelocking():
    path = 'tests/fixtures/empty_repo.conf'
    mocked_path = MagicMock()
    mocked_path.__str__ = lambda x: path

    mocked_fcntl = MagicMock()
    mocked_open = MagicMock()

    with patch('pyolite.repo.open', mocked_open, create=True):
        manager = mocked_open.return_value.__enter__.return_value

        # asserts file locking has been put in place before writing
        manager.write = lambda text: ([
            mocked_fcntl.flock.assert_called_once_with(
                manager, mocked_fcntl.LOCK_EX
            ),
            mocked_fcntl.reset_mock()
        ])

        with patch.multiple('pyolite.repo', fcntl=mocked_fcntl):
            repo = Repo(path)

            mocked_fcntl.reset_mock()
            repo.write('some_text')

            # asserts lock has been removed after writing
            mocked_fcntl.flock.assert_called_once_with(manager,
                                                       mocked_fcntl.LOCK_UN) 
Example #25
Source File: test_pyolite.py    From pyolite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_if_pyolite_object_has_all_attributes():
    mocked_repository = MagicMock()
    mocked_user = MagicMock()

    with patch.multiple('pyolite.pyolite',
                        RepositoryManager=mocked_repository,
                        UserManager=mocked_user):
        pyolite = Pyolite('my_repo')

        assert pyolite.admin_repository == 'my_repo'
        mocked_repository.assert_called_once_with('my_repo')
        mocked_user.assert_called_once_with('my_repo') 
Example #26
Source File: test_repo.py    From pyolite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_it_should_replace_a_given_string_in_repo_conf():
    mocked_re = MagicMock()
    path = 'tests/fixtures/config.conf'

    mocked_re.sub.return_value = 'another_text'

    with patch.multiple('pyolite.repo', re=mocked_re):
        repo = Repo(path)
        repo.replace('pattern', 'string')

        with open('tests/fixtures/config.conf') as f:
            assert f.read() == 'another_text'

        mocked_re.sub.assert_called_once_with('pattern', 'string',
                                              'another_text') 
Example #27
Source File: test_repo.py    From pyolite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_users_filelocking():
    path = 'tests/fixtures/repo_users.conf'
    mocked_path = MagicMock()
    mocked_path.__str__ = lambda x: path

    mocked_path.exists.return_value = True

    mocked_re = MagicMock()
    mocked_fcntl = MagicMock()
    mocked_open = MagicMock()

    with patch('pyolite.repo.open', mocked_open, create=True):
        manager = mocked_open.return_value.__enter__.return_value

        # asserts file locking has been put in place before reading
        manager.read = lambda: ([
            mocked_fcntl.flock.assert_called_once_with(
                manager, mocked_fcntl.LOCK_EX
            ),
            mocked_fcntl.reset_mock()
        ])

        with patch.multiple('pyolite.repo', re=mocked_re,
                            fcntl=mocked_fcntl):
            repo = Repo(mocked_path)

            mocked_fcntl.reset_mock()
            repo.users

            # asserts lock has been removed after reading
            mocked_fcntl.flock.assert_called_once_with(manager,
                                                       mocked_fcntl.LOCK_UN) 
Example #28
Source File: test_repo.py    From pyolite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_replace_filelocking():
    mocked_re = MagicMock()
    mocked_fcntl = MagicMock()

    mocked_open = MagicMock()
    path = 'tests/fixtures/config.conf'

    with patch('pyolite.repo.open', mocked_open, create=True):
        manager = mocked_open.return_value.__enter__.return_value

        # asserts file locking has been put in place before reading
        manager.read = lambda: ([
            mocked_fcntl.flock.assert_called_once_with(
                manager, mocked_fcntl.LOCK_EX
            ),
            mocked_fcntl.reset_mock()
        ])

        with patch.multiple('pyolite.repo', re=mocked_re,
                            fcntl=mocked_fcntl):
            repo = Repo(path)

            mocked_fcntl.reset_mock()
            repo.replace('pattern', 'string')

            # asserts lock has been removed after operating on file
            mocked_fcntl.flock.assert_called_once_with(manager,
                                                       mocked_fcntl.LOCK_UN) 
Example #29
Source File: test_repository.py    From pyolite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_it_should_commit_if_a_new_repository_was_succesfully_created():
    mocked_repository = MagicMock()

    mocked_file = MagicMock()
    mocked_file.__str__ = lambda x: 'dont_exists'

    mocked_file.exists.return_value = False
    mocked_path.return_value = mocked_file

    mocked_repository.return_value = 'new repo'

    RepositoryManager.__bases__ = (MockManager,)

    with patch.multiple('pyolite.managers.repository',
                        Path=mocked_path,
                        Repository=mocked_repository):
        repos = RepositoryManager('/path/to/admin/repo/')
        repo = repos.create('dont_exists')

        mocked_path.has_calls(call(mocked_path,
                                   'conf/repos/dont_exists.conf'))
        assert mocked_file.exists.call_count == 1
        mocked_file.write_file.assert_called_once_with(
            'repo dont_exists\n')
        mocked_git.commit.has_calls(call(['dont_exists'],
                                         'Created repo dont_exists'))
        mocked_repository.assert_called_once_with('dont_exists',
                                                  mocked_path,
                                                  mocked_git)
        assert repo == 'new repo' 
Example #30
Source File: test_user.py    From pyolite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_create_user_with_no_key():
    with patch.multiple('pyolite.managers.manager',
                        Git=MagicMock(),
                        Path=MagicMock()):
        with pytest.raises(ValueError):
            users = UserManager('~/path/to/admin/gitolite/repo')
            users.create('test_username')