Merge pull request #3174 from quay/move-repo-visibility-tests

Move repo visibility tests into pytest
This commit is contained in:
Joseph Schorr 2018-07-19 11:24:33 -04:00 committed by GitHub
commit fa354d695a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 98 deletions

View file

@ -0,0 +1,89 @@
from data import model
from test.fixtures import *
NO_ACCESS_USER = 'freshuser'
READ_ACCESS_USER = 'reader'
ADMIN_ACCESS_USER = 'devtable'
PUBLIC_USER = 'public'
RANDOM_USER = 'randomuser'
OUTSIDE_ORG_USER = 'outsideorg'
ADMIN_ROBOT_USER = 'devtable+dtrobot'
ORGANIZATION = 'buynlarge'
SIMPLE_REPO = 'simple'
PUBLIC_REPO = 'publicrepo'
RANDOM_REPO = 'randomrepo'
OUTSIDE_ORG_REPO = 'coolrepo'
ORG_REPO = 'orgrepo'
ANOTHER_ORG_REPO = 'anotherorgrepo'
# Note: The shared repo has devtable as admin, public as a writer and reader as a reader.
SHARED_REPO = 'shared'
def assertDoesNotHaveRepo(username, name):
repos = list(model.repository.get_visible_repositories(username))
names = [repo.name for repo in repos]
assert not name in names
def assertHasRepo(username, name):
repos = list(model.repository.get_visible_repositories(username))
names = [repo.name for repo in repos]
assert name in names
def test_noaccess(initialized_db):
repos = list(model.repository.get_visible_repositories(NO_ACCESS_USER))
names = [repo.name for repo in repos]
assert not names
# Try retrieving public repos now.
repos = list(model.repository.get_visible_repositories(NO_ACCESS_USER, include_public=True))
names = [repo.name for repo in repos]
assert PUBLIC_REPO in names
def test_public(initialized_db):
assertHasRepo(PUBLIC_USER, PUBLIC_REPO)
assertHasRepo(PUBLIC_USER, SHARED_REPO)
assertDoesNotHaveRepo(PUBLIC_USER, SIMPLE_REPO)
assertDoesNotHaveRepo(PUBLIC_USER, RANDOM_REPO)
assertDoesNotHaveRepo(PUBLIC_USER, OUTSIDE_ORG_REPO)
def test_reader(initialized_db):
assertHasRepo(READ_ACCESS_USER, SHARED_REPO)
assertHasRepo(READ_ACCESS_USER, ORG_REPO)
assertDoesNotHaveRepo(READ_ACCESS_USER, SIMPLE_REPO)
assertDoesNotHaveRepo(READ_ACCESS_USER, RANDOM_REPO)
assertDoesNotHaveRepo(READ_ACCESS_USER, OUTSIDE_ORG_REPO)
assertDoesNotHaveRepo(READ_ACCESS_USER, PUBLIC_REPO)
def test_random(initialized_db):
assertHasRepo(RANDOM_USER, RANDOM_REPO)
assertDoesNotHaveRepo(RANDOM_USER, SIMPLE_REPO)
assertDoesNotHaveRepo(RANDOM_USER, SHARED_REPO)
assertDoesNotHaveRepo(RANDOM_USER, ORG_REPO)
assertDoesNotHaveRepo(RANDOM_USER, ANOTHER_ORG_REPO)
assertDoesNotHaveRepo(RANDOM_USER, PUBLIC_REPO)
def test_admin(initialized_db):
assertHasRepo(ADMIN_ACCESS_USER, SIMPLE_REPO)
assertHasRepo(ADMIN_ACCESS_USER, SHARED_REPO)
assertHasRepo(ADMIN_ACCESS_USER, ORG_REPO)
assertHasRepo(ADMIN_ACCESS_USER, ANOTHER_ORG_REPO)
assertDoesNotHaveRepo(ADMIN_ACCESS_USER, OUTSIDE_ORG_REPO)

View file

@ -1,98 +0,0 @@
import unittest
from app import app
from initdb import setup_database_for_testing, finished_database_for_testing
from data import model
NO_ACCESS_USER = 'freshuser'
READ_ACCESS_USER = 'reader'
ADMIN_ACCESS_USER = 'devtable'
PUBLIC_USER = 'public'
RANDOM_USER = 'randomuser'
OUTSIDE_ORG_USER = 'outsideorg'
ADMIN_ROBOT_USER = 'devtable+dtrobot'
ORGANIZATION = 'buynlarge'
SIMPLE_REPO = 'simple'
PUBLIC_REPO = 'publicrepo'
RANDOM_REPO = 'randomrepo'
OUTSIDE_ORG_REPO = 'coolrepo'
ORG_REPO = 'orgrepo'
ANOTHER_ORG_REPO = 'anotherorgrepo'
# Note: The shared repo has devtable as admin, public as a writer and reader as a reader.
SHARED_REPO = 'shared'
class TestVisibleRepositories(unittest.TestCase):
def setUp(self):
setup_database_for_testing(self)
self.app = app.test_client()
self.ctx = app.test_request_context()
self.ctx.__enter__()
def tearDown(self):
finished_database_for_testing(self)
self.ctx.__exit__(True, None, None)
def assertDoesNotHaveRepo(self, username, name):
repos = list(model.repository.get_visible_repositories(username))
names = [repo.name for repo in repos]
self.assertNotIn(name, names)
def assertHasRepo(self, username, name):
repos = list(model.repository.get_visible_repositories(username))
names = [repo.name for repo in repos]
self.assertIn(name, names)
def test_noaccess(self):
repos = list(model.repository.get_visible_repositories(NO_ACCESS_USER))
names = [repo.name for repo in repos]
self.assertEquals(0, len(names))
# Try retrieving public repos now.
repos = list(model.repository.get_visible_repositories(NO_ACCESS_USER, include_public=True))
names = [repo.name for repo in repos]
self.assertIn(PUBLIC_REPO, names)
def test_public(self):
self.assertHasRepo(PUBLIC_USER, PUBLIC_REPO)
self.assertHasRepo(PUBLIC_USER, SHARED_REPO)
self.assertDoesNotHaveRepo(PUBLIC_USER, SIMPLE_REPO)
self.assertDoesNotHaveRepo(PUBLIC_USER, RANDOM_REPO)
self.assertDoesNotHaveRepo(PUBLIC_USER, OUTSIDE_ORG_REPO)
def test_reader(self):
self.assertHasRepo(READ_ACCESS_USER, SHARED_REPO)
self.assertHasRepo(READ_ACCESS_USER, ORG_REPO)
self.assertDoesNotHaveRepo(READ_ACCESS_USER, SIMPLE_REPO)
self.assertDoesNotHaveRepo(READ_ACCESS_USER, RANDOM_REPO)
self.assertDoesNotHaveRepo(READ_ACCESS_USER, OUTSIDE_ORG_REPO)
self.assertDoesNotHaveRepo(READ_ACCESS_USER, PUBLIC_REPO)
def test_random(self):
self.assertHasRepo(RANDOM_USER, RANDOM_REPO)
self.assertDoesNotHaveRepo(RANDOM_USER, SIMPLE_REPO)
self.assertDoesNotHaveRepo(RANDOM_USER, SHARED_REPO)
self.assertDoesNotHaveRepo(RANDOM_USER, ORG_REPO)
self.assertDoesNotHaveRepo(RANDOM_USER, ANOTHER_ORG_REPO)
self.assertDoesNotHaveRepo(RANDOM_USER, PUBLIC_REPO)
def test_admin(self):
self.assertHasRepo(ADMIN_ACCESS_USER, SIMPLE_REPO)
self.assertHasRepo(ADMIN_ACCESS_USER, SHARED_REPO)
self.assertHasRepo(ADMIN_ACCESS_USER, ORG_REPO)
self.assertHasRepo(ADMIN_ACCESS_USER, ANOTHER_ORG_REPO)
self.assertDoesNotHaveRepo(ADMIN_ACCESS_USER, OUTSIDE_ORG_REPO)
if __name__ == '__main__':
unittest.main()