コード例 #1
0
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)])
コード例 #2
0
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)])
コード例 #3
0
ファイル: repository.py プロジェクト: lmz2932/pyolite
    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)
コード例 #4
0
ファイル: test_repository.py プロジェクト: Codevolve/pyolite
    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)
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
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)])
コード例 #8
0
ファイル: test_repository.py プロジェクト: Codevolve/pyolite
    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)
コード例 #9
0
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
コード例 #10
0
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 == """
コード例 #11
0
ファイル: repository.py プロジェクト: lmz2932/pyolite
 def get(self, lookup_repo):
     return Repository.get_by_name(lookup_repo, self.path, self.git)
コード例 #12
0
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+')
コード例 #13
0
ファイル: repository.py プロジェクト: sona1111/pyolite
 def get(self, entity):
     return Repository.get_by_name(entity, self.path, self.git)
コード例 #14
0
ファイル: repository.py プロジェクト: quietshu/pyolite
 def get(self, lookup_repo):
   return Repository.get_by_name(lookup_repo, self.path, self.git)