|
Pierre-Yves Chibon |
17b6f6 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
"""
|
|
Pierre-Yves Chibon |
17b6f6 |
(c) 2017 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
Authors:
|
|
Pierre-Yves Chibon |
17b6f6 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
"""
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
17b6f6 |
import pkg_resources
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
import unittest
|
|
Pierre-Yves Chibon |
17b6f6 |
import shutil
|
|
Pierre-Yves Chibon |
17b6f6 |
import sys
|
|
Pierre-Yves Chibon |
17b6f6 |
import os
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
import mock
|
|
Pierre-Yves Chibon |
a1fca3 |
import munch
|
|
Pierre-Yves Chibon |
17b6f6 |
import pygit2
|
|
Pierre-Yves Chibon |
17b6f6 |
import werkzeug
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
17b6f6 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
import pagure.lib
|
|
Pierre-Yves Chibon |
17b6f6 |
import pagure.lib.model
|
|
Pierre-Yves Chibon |
17b6f6 |
import tests
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
17b6f6 |
class PagureGetRemoteRepoPath(tests.Modeltests):
|
|
Pierre-Yves Chibon |
17b6f6 |
""" Tests for pagure """
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
def setUp(self):
|
|
Pierre-Yves Chibon |
17b6f6 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
17b6f6 |
super(PagureGetRemoteRepoPath, self).setUp()
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
17b6f6 |
tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
|
|
Pierre-Yves Chibon |
17b6f6 |
tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test2.git'))
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
@mock.patch(
|
|
Pierre-Yves Chibon |
17b6f6 |
'pagure.lib.repo.PagureRepo.pull',
|
|
Pierre-Yves Chibon |
17b6f6 |
mock.MagicMock(side_effect=pygit2.GitError))
|
|
Pierre-Yves Chibon |
17b6f6 |
def test_passing(self):
|
|
Pierre-Yves Chibon |
17b6f6 |
""" Test get_remote_repo_path in pagure. """
|
|
Pierre-Yves Chibon |
17b6f6 |
output = pagure.get_remote_repo_path(
|
|
Patrick Uiterwijk |
7d2547 |
os.path.join(self.path, 'repos', 'test2.git'), 'master',
|
|
Patrick Uiterwijk |
7d2547 |
ignore_non_exist=True)
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
self.assertTrue(output.endswith('repos_test2.git_master'))
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
a1fca3 |
def test_is_repo_committer_logged_out(self):
|
|
Pierre-Yves Chibon |
a1fca3 |
""" Test is_repo_committer in pagure when there is no logged in user.
|
|
Pierre-Yves Chibon |
a1fca3 |
"""
|
|
Pierre-Yves Chibon |
a1fca3 |
repo = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
a1fca3 |
output = pagure.is_repo_committer(repo)
|
|
Pierre-Yves Chibon |
a1fca3 |
self.assertFalse(output)
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
def test_is_repo_committer_logged_in(self):
|
|
Pierre-Yves Chibon |
a1fca3 |
""" Test is_repo_committer in pagure with the appropriate user logged
|
|
Pierre-Yves Chibon |
a1fca3 |
in. """
|
|
Pierre-Yves Chibon |
a1fca3 |
repo = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
g = munch.Munch()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
a1fca3 |
with mock.patch('pagure.flask.g', g):
|
|
Pierre-Yves Chibon |
a1fca3 |
output = pagure.is_repo_committer(repo)
|
|
Pierre-Yves Chibon |
a1fca3 |
self.assertTrue(output)
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
def test_is_repo_committer_logged_in_wrong_user(self):
|
|
Pierre-Yves Chibon |
a1fca3 |
""" Test is_repo_committer in pagure with the wrong user logged in.
|
|
Pierre-Yves Chibon |
a1fca3 |
"""
|
|
Pierre-Yves Chibon |
a1fca3 |
repo = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
g = munch.Munch()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
a1fca3 |
with mock.patch('pagure.flask.g', g):
|
|
Pierre-Yves Chibon |
a1fca3 |
output = pagure.is_repo_committer(repo)
|
|
Pierre-Yves Chibon |
a1fca3 |
self.assertFalse(output)
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
# Mocked config
|
|
Pierre-Yves Chibon |
a1fca3 |
config = {
|
|
Pierre-Yves Chibon |
a1fca3 |
'provenpackager': {}
|
|
Pierre-Yves Chibon |
a1fca3 |
}
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
@mock.patch.dict('pagure.APP.config', {'EXTERNAL_COMMITTER': config})
|
|
Pierre-Yves Chibon |
a1fca3 |
def test_is_repo_committer_external_committer_generic_no_member(self):
|
|
Pierre-Yves Chibon |
a1fca3 |
""" Test is_repo_committer in pagure with EXTERNAL_COMMITTER
|
|
Pierre-Yves Chibon |
a1fca3 |
configured to give access to all the provenpackager, but the user
|
|
Pierre-Yves Chibon |
a1fca3 |
is not one.
|
|
Pierre-Yves Chibon |
a1fca3 |
"""
|
|
Pierre-Yves Chibon |
a1fca3 |
repo = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
a1fca3 |
g = munch.Munch()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user = user
|
|
Pierre-Yves Chibon |
a1fca3 |
with mock.patch('pagure.flask.g', g):
|
|
Pierre-Yves Chibon |
a1fca3 |
output = pagure.is_repo_committer(repo)
|
|
Pierre-Yves Chibon |
a1fca3 |
self.assertFalse(output)
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
@mock.patch.dict('pagure.APP.config', {'EXTERNAL_COMMITTER': config})
|
|
Pierre-Yves Chibon |
a1fca3 |
def test_is_repo_committer_external_committer_generic_member(self):
|
|
Pierre-Yves Chibon |
a1fca3 |
""" Test is_repo_committer in pagure with EXTERNAL_COMMITTER
|
|
Pierre-Yves Chibon |
a1fca3 |
configured to give access to all the provenpackager, and the user
|
|
Pierre-Yves Chibon |
a1fca3 |
is one
|
|
Pierre-Yves Chibon |
a1fca3 |
"""
|
|
Pierre-Yves Chibon |
a1fca3 |
repo = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
g = munch.Munch()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user.groups.append('provenpackager')
|
|
Pierre-Yves Chibon |
a1fca3 |
with mock.patch('pagure.flask.g', g):
|
|
Pierre-Yves Chibon |
a1fca3 |
output = pagure.is_repo_committer(repo)
|
|
Pierre-Yves Chibon |
a1fca3 |
self.assertTrue(output)
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
config = {
|
|
Pierre-Yves Chibon |
a1fca3 |
'provenpackager': {
|
|
Pierre-Yves Chibon |
a1fca3 |
'exclude': ['test']
|
|
Pierre-Yves Chibon |
a1fca3 |
}
|
|
Pierre-Yves Chibon |
a1fca3 |
}
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
@mock.patch.dict('pagure.APP.config', {'EXTERNAL_COMMITTER': config})
|
|
Pierre-Yves Chibon |
a1fca3 |
def test_is_repo_committer_external_committer_excluding_one(self):
|
|
Pierre-Yves Chibon |
a1fca3 |
""" Test is_repo_committer in pagure with EXTERNAL_COMMITTER
|
|
Pierre-Yves Chibon |
a1fca3 |
configured to give access to all the provenpackager but for this
|
|
Pierre-Yves Chibon |
a1fca3 |
one repo
|
|
Pierre-Yves Chibon |
a1fca3 |
"""
|
|
Pierre-Yves Chibon |
a1fca3 |
repo = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
g = munch.Munch()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user.groups.append('provenpackager')
|
|
Pierre-Yves Chibon |
a1fca3 |
with mock.patch('pagure.flask.g', g):
|
|
Pierre-Yves Chibon |
a1fca3 |
output = pagure.is_repo_committer(repo)
|
|
Pierre-Yves Chibon |
a1fca3 |
self.assertFalse(output)
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
config = {
|
|
Pierre-Yves Chibon |
a1fca3 |
'provenpackager': {
|
|
Pierre-Yves Chibon |
a1fca3 |
'restrict': ['test']
|
|
Pierre-Yves Chibon |
a1fca3 |
}
|
|
Pierre-Yves Chibon |
a1fca3 |
}
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
@mock.patch.dict('pagure.APP.config', {'EXTERNAL_COMMITTER': config})
|
|
Pierre-Yves Chibon |
a1fca3 |
def test_is_repo_committer_external_committer_restricted_not_member(self):
|
|
Pierre-Yves Chibon |
a1fca3 |
""" Test is_repo_committer in pagure with EXTERNAL_COMMITTER
|
|
Pierre-Yves Chibon |
a1fca3 |
configured to give access the provenpackager just for one repo
|
|
Pierre-Yves Chibon |
a1fca3 |
"""
|
|
Pierre-Yves Chibon |
a1fca3 |
repo = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
g = munch.Munch()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
a1fca3 |
with mock.patch('pagure.flask.g', g):
|
|
Pierre-Yves Chibon |
a1fca3 |
output = pagure.is_repo_committer(repo)
|
|
Pierre-Yves Chibon |
a1fca3 |
self.assertFalse(output)
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
@mock.patch.dict('pagure.APP.config', {'EXTERNAL_COMMITTER': config})
|
|
Pierre-Yves Chibon |
a1fca3 |
def test_is_repo_committer_external_committer_restricting_to_one(self):
|
|
Pierre-Yves Chibon |
a1fca3 |
""" Test is_repo_committer in pagure with EXTERNAL_COMMITTER
|
|
Pierre-Yves Chibon |
a1fca3 |
configured to give access the provenpackager just for one repo
|
|
Pierre-Yves Chibon |
a1fca3 |
"""
|
|
Pierre-Yves Chibon |
a1fca3 |
repo = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
g = munch.Munch()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user.groups.append('provenpackager')
|
|
Pierre-Yves Chibon |
a1fca3 |
with mock.patch('pagure.flask.g', g):
|
|
Pierre-Yves Chibon |
a1fca3 |
output = pagure.is_repo_committer(repo)
|
|
Pierre-Yves Chibon |
a1fca3 |
self.assertTrue(output)
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
@mock.patch.dict('pagure.APP.config', {'EXTERNAL_COMMITTER': config})
|
|
Pierre-Yves Chibon |
a1fca3 |
def test_is_repo_committer_external_committer_restricting_another_one(self):
|
|
Pierre-Yves Chibon |
a1fca3 |
""" Test is_repo_committer in pagure with EXTERNAL_COMMITTER
|
|
Pierre-Yves Chibon |
a1fca3 |
configured to give access the provenpackager just for one repo not
|
|
Pierre-Yves Chibon |
a1fca3 |
this one
|
|
Pierre-Yves Chibon |
a1fca3 |
"""
|
|
Pierre-Yves Chibon |
a1fca3 |
repo = pagure.lib._get_project(self.session, 'test2')
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
a1fca3 |
g = munch.Munch()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
a1fca3 |
g.fas_user.groups.append('provenpackager')
|
|
Pierre-Yves Chibon |
a1fca3 |
with mock.patch('pagure.flask.g', g):
|
|
Pierre-Yves Chibon |
a1fca3 |
output = pagure.is_repo_committer(repo)
|
|
Pierre-Yves Chibon |
a1fca3 |
self.assertFalse(output)
|
|
Pierre-Yves Chibon |
a1fca3 |
|
|
Pierre-Yves Chibon |
17b6f6 |
|
|
Pierre-Yves Chibon |
17b6f6 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
78e6f4 |
unittest.main(verbosity=2)
|