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_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 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_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+')