def test_it_should_add_a_new_user_to_repo_if_is_valid(tmpolite): name, path, git = tmpolite repo = Repository(name, path, git) repo.users.add('test', 'RW+') content = ' RW+ = test\n' assert content in open(repo.config).read() message = 'User test added to repo test_repo ' \ 'with permissions: RW+' git.commit.has_calls([call(['conf'], message)])
def test_user_removing(tmpolite): name, path, git = tmpolite repo = Repository(name, path, git) # repo.users.add('test', 'RW+') content = ' RW+ = test\n' assert content in open(repo.config).read() # repo.users.remove('test') assert '' in open(repo.config).read() message = "Deleted user test from repository test_repo" git.commit.has_calls([call(['conf'], message)])
def create(self, lookup_repo): repo_file = Path(self.path, 'conf/repos/%s.conf' % lookup_repo) if repo_file.exists(): raise ValueError('Repository %s already exists' % lookup_repo) # If there are missing parent paths in the repo path, create them so we don't get IOErrors # In the case of a repo having names with slashes (e.g. "username/reponame") elif repo_file.parent != Path(""): repo_file.parent.mkdir(parents=True) repo_file.write_file("repo %s\n" % lookup_repo) self.git.commit([str(repo_file)], 'Created repo %s' % lookup_repo) return Repository(lookup_repo, self.path, self.git)
def test_if_we_find_only_directories_should_return_none(self): mocked_users = MagicMock() mocked_dir = MagicMock() mocked_path = MagicMock() mocked_dir.isdir.return_value = True mocked_path.walk.return_value = [mocked_dir] with patch.multiple('pyolite.models.repository', Path=MagicMock(return_value=mocked_path), ListUsers=MagicMock(return_value=mocked_users)): repo = Repository.get_by_name('new_one', 'simple_path', 'git') eq_(repo, None)
def test_if_we_find_only_directories_should_return_none(): mocked_users = MagicMock() mocked_dir = MagicMock() mocked_path = MagicMock() mocked_dir.isdir.return_value = True mocked_path.walk.return_value = [mocked_dir] with patch.multiple('pyolite.models.repository', Path=MagicMock(return_value=mocked_path), ListUsers=MagicMock(return_value=mocked_users)): repo = Repository.get_by_name('new_one', 'simple_path', 'git') assert repo is None
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
def test_user_edit_permissions(tmpolite): name, path, git = tmpolite repo = Repository(name, path, git) # repo.users.add('test', 'RW+') repo.users.add('toto', 'RW+') content = ' RW+ = test\n' assert content in open(repo.config).read() content = ' RW+ = toto\n' assert content in open(repo.config).read() # repo.users.edit('test', 'R') content = ' R = test\n' assert content in open(repo.config).read() content = ' RW+ = toto\n' assert content in open(repo.config).read() # message = "User another_user has R permission for repository test_repo" git.commit.has_calls([call(['conf'], message)])
def test_it_should_be_possible_to_retrieve_by_name_a_repo(self): 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/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)): repo = Repository.get_by_name('new_one', 'simple_path', 'git') eq_(repo.name, 'new_one') eq_(repo.path, 'simple_path') eq_(repo.git, 'git') eq_(repo.users, mocked_users)
def test_it_should_be_possible_to_retrieve_by_name_a_repo(): 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/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)): repo = Repository.get_by_name('new_one', 'simple_path', 'git') assert repo.name == 'new_one' assert repo.path == 'simple_path' assert repo.git == 'git' assert repo.users == mocked_users
def test_set_new_configs(): repository = Repository('empty_repo', 'tests/fixtures/', MagicMock()) repository.repo.overwrite(''' repo test-repo RW+ = @support R = gitweb config test = testconfig ''') repository.add_config(('test', 'anothertest')) repository.add_config(('another', 'test')) content = repository.repo.read() repository.repo.overwrite("") assert content == """
def get(self, lookup_repo): return Repository.get_by_name(lookup_repo, self.path, self.git)
def test_if_we_add_invalid_permissions_it_should_raise_ValueError(tmpolite): name, path, git = tmpolite repo = Repository(name, path, git) with pytest.raises(ValueError): repo.users.add('test', 'hiRW+')
def get(self, entity): return Repository.get_by_name(entity, self.path, self.git)