def test_get_user_by_nothing_it_should_raise_value_error(): mocks = set_mocks() with patch.multiple('pyolite.models.user', Path=mocks['path'], ListKeys=mocks['keys']): User.get(MagicMock(), mocks['git'], mocks['path'])
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('vtemian', mocks['initial_path'], mocks['git'], 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 >'
def test_get_user_by_nothing_it_should_raise_value_error(): mocks = set_mocks() with patch.multiple('pyolite.models.user', Path=mocks['path'], ListKeys=mocks['keys']): with pytest.raises(ValueError): User.get(MagicMock(), mocks['git'], mocks['path'])
def decorated(self, string_user, *args, **kwargs): try: user = User.get(string_user, self.repository_model.path, self.repository_model.git) except ValueError: user = User(self.repository_model.path, self.repository_model.git, string_user) return func(self, user, *args, **kwargs)
def test_if_user_is_admin(): 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']]) assert not user.is_admin user.repos = ['/path/to/gitolite/admin/gitolite.conf'] assert user.is_admin
def test_if_user_is_admin(self): mocks = self.set_mocks() with patch.multiple('pyolite.models.user', Path=mocks['path'], ListKeys=mocks['keys']): user = User(mocks['initial_path'], mocks['git'], 'vtemian', [], [mocks['first_key']]) eq_(user.is_admin, False) user.repos = ['/path/to/gitolite/admin/gitolite.conf'] eq_(user.is_admin, True)
def test_if_user_is_admin(): mocks = set_mocks() with patch.multiple('pyolite.models.user', Path=mocks['path'], ListKeys=mocks['keys']): user = User('vtemian', mocks['initial_path'], mocks['git'], repos=None, keys=[mocks['first_key']]) assert not user.is_admin user.repos = ['/path/to/gitolite/admin/gitolite.conf'] assert user.is_admin
def create(self, name, key=None, key_path=None): if key is None and key_path is None: raise ValueError('You need to specify a key or key_path') user = User(self.path, self.git, name) user.keys.append(key or key_path) return user
def all(self): users = [] key_dir = Path(self.path, 'keydir') for obj in key_dir.walk(): if obj.isdir(): continue files = re.compile('(\w+.pub)').findall(str(obj)) if files: users += files return [User.get_by_name(user[:-4], self.path, self.git) for user in set(users)]
def all(self): users = [] key_dir = Path(self.path, 'keydir') for obj in key_dir.walk(): if obj.isdir(): continue files = re.compile(r'(\w+.pub)').findall(str(obj)) if files: users += files return [User.get_by_name(user[:-4], self.path, self.git) for user in set(users)]
def test_if_a_user_can_be_retrieved_by_name(self): mocks = self.set_mocks() with patch.multiple('pyolite.models.user', Path=mocks['path'], ListKeys=mocks['keys']): user = User(mocks['initial_path'], mocks['git'], 'vtemian', [], [mocks['first_key']]) test_user = User.get_by_name('vtemian', mocks['initial_path'], mocks['git']) eq_(test_user.name, user.name) eq_(test_user.repos, user.repos) eq_(test_user.keys, user.keys) eq_(test_user.path, user.path) eq_(test_user.git, user.git) mocks['path'].has_calls( [call('path', 'keydir'), call('path', 'conf/')]) eq_(str(test_user), '< vtemian >') eq_(repr(test_user), '< vtemian >')
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 >'
def test_if_a_user_can_be_retrieved_by_name(self): mocks = self.set_mocks() with patch.multiple('pyolite.models.user', Path=mocks['path'], ListKeys=mocks['keys']): user = User(mocks['initial_path'], mocks['git'], 'vtemian', [], [mocks['first_key']]) test_user = User.get_by_name('vtemian', mocks['initial_path'], mocks['git']) eq_(test_user.name, user.name) eq_(test_user.repos, user.repos) eq_(test_user.keys, user.keys) eq_(test_user.path, user.path) eq_(test_user.git, user.git) mocks['path'].has_calls([ call('path', 'keydir'), call('path', 'conf/') ]) eq_(str(test_user), '< vtemian >') eq_(repr(test_user), '< vtemian >')
def get(self, name): return User.get_by_name(name, self.path, self.git)