Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit b82f73a8fe189be54ee0733b2f3b337f44bcaee8 Author: Bohuslav Kabrda bkabrda@redhat.com Date: Thu Feb 14 14:02:12 2013 +0100
Few tweaks to testsuite
- make some testing values unicode explicitly in preparation for whoosh integration - commit all fixtures as once before test to achieve a little speedup
coprs_frontend/tests/coprs_test_case.py | 23 +++---- .../test_views/test_backend_ns/test_general.py | 10 ++-- .../tests/test_views/test_coprs_ns/test_builds.py | 14 ++-- .../tests/test_views/test_coprs_ns/test_general.py | 65 +++++++++----------- 4 files changed, 53 insertions(+), 59 deletions(-)
diff --git a/coprs_frontend/tests/coprs_test_case.py b/coprs_frontend/tests/coprs_test_case.py index 6a9d675..7756343 100644 --- a/coprs_frontend/tests/coprs_test_case.py +++ b/coprs_frontend/tests/coprs_test_case.py @@ -22,8 +22,8 @@ class CoprsTestCase(object): datadir = os.path.commonprefix([self.app.config['DATABASE'], self.app.config['OPENID_STORE']]) if not os.path.exists(datadir): os.makedirs(datadir) - coprs.db.create_all() + self.db.session.commit()
def teardown_method(self, method): # delete just data, not the tables @@ -35,22 +35,24 @@ class CoprsTestCase(object): return {'Authorization': 'Basic ' + base64.b64encode('doesntmatter:{0}'.format(self.backend_passwd))}
@pytest.fixture + def f_db(self): + self.db.session.commit() + + @pytest.fixture def f_users(self): - self.u1 = models.User(openid_name = 'http://user1.id.fedoraproject.org/', proven = False, mail = 'user1@foo.bar') - self.u2 = models.User(openid_name = 'http://user2.id.fedoraproject.org/', proven = False, mail = 'user2@spam.foo') - self.u3 = models.User(openid_name = 'http://user3.id.fedoraproject.org/', proven = False, mail = 'baz@bar.bar') + self.u1 = models.User(openid_name = u'http://user1.id.fedoraproject.org/', proven = False, mail = 'user1@foo.bar') + self.u2 = models.User(openid_name = u'http://user2.id.fedoraproject.org/', proven = False, mail = 'user2@spam.foo') + self.u3 = models.User(openid_name = u'http://user3.id.fedoraproject.org/', proven = False, mail = 'baz@bar.bar')
self.db.session.add_all([self.u1, self.u2, self.u3]) - self.db.session.commit()
@pytest.fixture def f_coprs(self): - self.c1 = models.Copr(name = 'foocopr', owner = self.u1) - self.c2 = models.Copr(name = 'foocopr', owner = self.u2) - self.c3 = models.Copr(name = 'barcopr', owner = self.u2) + self.c1 = models.Copr(name = u'foocopr', owner = self.u1) + self.c2 = models.Copr(name = u'foocopr', owner = self.u2) + self.c3 = models.Copr(name = u'barcopr', owner = self.u2)
self.db.session.add_all([self.c1, self.c2, self.c3]) - self.db.session.commit()
@pytest.fixture def f_mock_chroots(self): @@ -78,7 +80,6 @@ class CoprsTestCase(object): self.db.session.add_all([cc1, cc2, cc3, cc4])
self.db.session.add_all([self.mc1, self.mc2, self.mc3, self.mc4]) - self.db.session.commit()
@pytest.fixture def f_builds(self): @@ -88,7 +89,6 @@ class CoprsTestCase(object): self.b4 = models.Build(copr = self.c2, user = self.u2, chroots = 'fedora-17-x86_64 fedora-17-i386', submitted_on = 100)
self.db.session.add_all([self.b1, self.b2, self.b3, self.b4]) - self.db.session.commit()
@pytest.fixture def f_copr_permissions(self): @@ -97,4 +97,3 @@ class CoprsTestCase(object): self.cp3 = models.CoprPermission(copr = self.c3, user = self.u1, copr_builder = helpers.PermissionEnum.num('request'), copr_admin = helpers.PermissionEnum.num('approved'))
self.db.session.add_all([self.cp1, self.cp2, self.cp3]) - self.db.session.commit() diff --git a/coprs_frontend/tests/test_views/test_backend_ns/test_general.py b/coprs_frontend/tests/test_views/test_backend_ns/test_general.py index d7df4c2..f7328a1 100644 --- a/coprs_frontend/tests/test_views/test_backend_ns/test_general.py +++ b/coprs_frontend/tests/test_views/test_backend_ns/test_general.py @@ -8,18 +8,18 @@ class TestWaitingBuilds(CoprsTestCase): def test_no_waiting_builds(self): assert '"builds": []' in self.tc.get('/backend/waiting_builds/').data
- def test_waiting_build_only_lists_not_started_or_ended(self, f_users, f_coprs, f_builds): + def test_waiting_build_only_lists_not_started_or_ended(self, f_users, f_coprs, f_builds, f_db): r = self.tc.get('/backend/waiting_builds/') assert len(json.loads(r.data)['builds']) == 2
class TestUpdateBuilds(CoprsTestCase): - def test_updating_requires_password(self, f_users, f_coprs, f_builds): + def test_updating_requires_password(self, f_users, f_coprs, f_builds, f_db): r = self.tc.post('/backend/update_builds/', content_type = 'application/json', data = '') assert 'You have to provide the correct password' in r.data
- def test_update_build_started(self, f_users, f_coprs, f_builds): + def test_update_build_started(self, f_users, f_coprs, f_builds, f_db): data = """ { "builds":[ @@ -43,7 +43,7 @@ class TestUpdateBuilds(CoprsTestCase): assert updated.results == 'http://server/results/foo/bar/' assert updated.started_on == 1234
- def test_update_build_ended(self, f_users, f_coprs, f_builds): + def test_update_build_ended(self, f_users, f_coprs, f_builds, f_db): data = """ { "builds":[ @@ -67,7 +67,7 @@ class TestUpdateBuilds(CoprsTestCase): assert updated.status == 1 assert updated.ended_on == 12345
- def test_update_more_existent_and_non_existent_builds(self, f_users, f_coprs, f_builds): + def test_update_more_existent_and_non_existent_builds(self, f_users, f_coprs, f_builds, f_db): data = """ { "builds":[ diff --git a/coprs_frontend/tests/test_views/test_coprs_ns/test_builds.py b/coprs_frontend/tests/test_views/test_coprs_ns/test_builds.py index 71c869b..574ca57 100644 --- a/coprs_frontend/tests/test_views/test_coprs_ns/test_builds.py +++ b/coprs_frontend/tests/test_views/test_coprs_ns/test_builds.py @@ -3,12 +3,12 @@ import flask from tests.coprs_test_case import CoprsTestCase
class TestCoprShowBuilds(CoprsTestCase): - def test_copr_show_builds(self, f_users, f_coprs, f_builds): + def test_copr_show_builds(self, f_users, f_coprs, f_builds, f_db): r = self.tc.get('/coprs/detail/{0}/{1}/builds/'.format(self.u2.name, self.c2.name)) assert r.data.count('<tr class="build-') == 2
class TestCoprAddBuild(CoprsTestCase): - def test_copr_owner_can_add_build(self, f_users, f_coprs): + def test_copr_owner_can_add_build(self, f_users, f_coprs, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -19,7 +19,7 @@ class TestCoprAddBuild(CoprsTestCase): follow_redirects = True) assert self.models.Build.query.first().pkgs == 'http://testing'
- def test_copr_allowed_user_can_add_build(self, f_users, f_coprs, f_copr_permissions): + def test_copr_allowed_user_can_add_build(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -30,7 +30,7 @@ class TestCoprAddBuild(CoprsTestCase): follow_redirects = True) assert self.models.Build.query.first().pkgs == 'http://testing'
- def test_copr_not_yet_allowed_user_cant_add_build(self, f_users, f_coprs, f_copr_permissions): + def test_copr_not_yet_allowed_user_cant_add_build(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -41,7 +41,7 @@ class TestCoprAddBuild(CoprsTestCase): follow_redirects = True) assert not self.models.Build.query.first()
- def test_copr_user_without_permission_cant_add_build(self, f_users, f_coprs, f_copr_permissions): + def test_copr_user_without_permission_cant_add_build(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u3.openid_name @@ -53,7 +53,7 @@ class TestCoprAddBuild(CoprsTestCase): assert not self.models.Build.query.first()
class TestCoprCancelBuild(CoprsTestCase): - def test_copr_build_submitter_can_cancel_build(self, f_users, f_coprs, f_builds): + def test_copr_build_submitter_can_cancel_build(self, f_users, f_coprs, f_builds, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -65,7 +65,7 @@ class TestCoprCancelBuild(CoprsTestCase): self.db.session.add(self.b1) assert self.b1.canceled == True
- def test_copr_build_non_submitter_cannot_cancel_build(self, f_users, f_coprs, f_builds): + def test_copr_build_non_submitter_cannot_cancel_build(self, f_users, f_coprs, f_builds, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u2.openid_name diff --git a/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py b/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py index e81b857..f57ecde 100644 --- a/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py +++ b/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py @@ -6,12 +6,12 @@ class TestCoprsShow(CoprsTestCase): def test_show_no_entries(self): assert 'No coprs...' in self.tc.get('/').data
- def test_show_more_entries(self, f_users, f_coprs): + def test_show_more_entries(self, f_users, f_coprs, f_db): r = self.tc.get('/') assert r.data.count('<div class="copr">') == 3
class TestCoprsOwned(CoprsTestCase): - def test_owned_none(self, f_users, f_coprs): + def test_owned_none(self, f_users, f_coprs, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u3.openid_name @@ -20,7 +20,7 @@ class TestCoprsOwned(CoprsTestCase): r = c.get('/coprs/owned/{0}/'.format(self.u3.name)) assert 'No coprs...' in r.data
- def test_owned_one(self, f_users, f_coprs): + def test_owned_one(self, f_users, f_coprs, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -30,7 +30,7 @@ class TestCoprsOwned(CoprsTestCase): assert r.data.count('<div class="copr">') == 1
class TestCoprsAllowed(CoprsTestCase): - def test_allowed_none(self, f_users, f_coprs, f_copr_permissions): + def test_allowed_none(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u3.openid_name @@ -39,7 +39,7 @@ class TestCoprsAllowed(CoprsTestCase): r = c.get('/coprs/allowed/{0}/'.format(self.u3.name)) assert 'No coprs...' in r.data
- def test_allowed_one(self, f_users, f_coprs, f_copr_permissions): + def test_allowed_one(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u2.openid_name @@ -48,7 +48,7 @@ class TestCoprsAllowed(CoprsTestCase): r = c.get('/coprs/allowed/{0}/'.format(self.u1.name)) assert r.data.count('<div class="copr">') == 1
- def test_allowed_one_but_asked_for_one_more(self, f_users, f_coprs, f_copr_permissions): + def test_allowed_one_but_asked_for_one_more(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -60,7 +60,7 @@ class TestCoprsAllowed(CoprsTestCase): class TestCoprNew(CoprsTestCase): success_string = 'New copr was successfully created'
- def test_copr_new_normal(self, f_users, f_mock_chroots): + def test_copr_new_normal(self, f_users, f_mock_chroots, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -72,7 +72,7 @@ class TestCoprNew(CoprsTestCase): # make sure no initial build was submitted assert self.models.Build.query.first() == None
- def test_copr_new_exists_for_another_user(self, f_users, f_coprs, f_mock_chroots): + def test_copr_new_exists_for_another_user(self, f_users, f_coprs, f_mock_chroots, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u3.openid_name @@ -82,12 +82,11 @@ class TestCoprNew(CoprsTestCase): assert foocoprs > 0
r = c.post('/coprs/new/', data = {'name': self.c1.name, 'fedora-rawhide-i386': 'y'}, follow_redirects = True) - print r.data self.db.session.add(self.c1) assert len(self.models.Copr.query.filter(self.models.Copr.name == self.c1.name).all()) == foocoprs + 1 assert self.success_string in r.data
- def test_copr_new_exists_for_this_user(self, f_users, f_coprs, f_mock_chroots): + def test_copr_new_exists_for_this_user(self, f_users, f_coprs, f_mock_chroots, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -101,7 +100,7 @@ class TestCoprNew(CoprsTestCase): assert len(self.models.Copr.query.filter(self.models.Copr.name == self.c1.name).all()) == foocoprs assert "You already have copr named" in r.data
- def test_copr_new_with_initial_pkgs(self, f_users, f_mock_chroots): + def test_copr_new_with_initial_pkgs(self, f_users, f_mock_chroots, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -120,28 +119,26 @@ class TestCoprDetail(CoprsTestCase): r = self.tc.get('/coprs/detail/foo/bar/') assert r.status_code == 404
- def test_copr_detail_normal(self, f_users, f_coprs): + def test_copr_detail_normal(self, f_users, f_coprs, f_db): r = self.tc.get('/coprs/detail/{0}/{1}/'.format(self.u1.name, self.c1.name)) assert r.status_code == 200 assert self.c1.name in r.data
- def test_copr_detail_contains_builds(self, f_users, f_coprs, f_builds): + def test_copr_detail_contains_builds(self, f_users, f_coprs, f_builds, f_db): r = self.tc.get('/coprs/detail/{0}/{1}/builds/'.format(self.u1.name, self.c1.name)) - print r.data assert r.data.count('<tr class="build') == 2
- def test_copr_detail_anonymous_doesnt_contain_permissions_table_when_no_permissions(self, f_users, f_coprs, f_copr_permissions): + def test_copr_detail_anonymous_doesnt_contain_permissions_table_when_no_permissions(self, f_users, f_coprs, f_copr_permissions, f_db): r = self.tc.get('/coprs/detail/{0}/{1}/permissions/'.format(self.u1.name, self.c1.name)) assert '<table class="permissions"' not in r.data
- def test_copr_detail_contains_permissions_table(self, f_users, f_coprs, f_copr_permissions): + def test_copr_detail_contains_permissions_table(self, f_users, f_coprs, f_copr_permissions, f_db): r = self.tc.get('/coprs/detail/{0}/{1}/permissions/'.format(self.u2.name, self.c3.name)) - print r.data assert '<table class="permissions-table"' in r.data assert '<td>{0}'.format(self.u3.name) in r.data assert '<td>{0}'.format(self.u1.name) in r.data
- def test_copr_detail_allows_asking_for_permissions(self, f_users, f_coprs, f_copr_permissions): + def test_copr_detail_allows_asking_for_permissions(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -151,7 +148,7 @@ class TestCoprDetail(CoprsTestCase): # u1 is approved builder, check for that assert '/permissions_applier_change/' in r.data
- def test_copr_detail_doesnt_allow_owner_to_ask_for_permissions(self, f_users, f_coprs): + def test_copr_detail_doesnt_allow_owner_to_ask_for_permissions(self, f_users, f_coprs, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u2.openid_name @@ -160,7 +157,7 @@ class TestCoprDetail(CoprsTestCase): r = c.get('/coprs/detail/{0}/{1}/permissions/'.format(self.u2.name, self.c2.name)) assert '/permissions_applier_change/' not in r.data
- def test_detail_has_correct_permissions_form(self, f_users, f_coprs, f_copr_permissions): + def test_detail_has_correct_permissions_form(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u2.openid_name @@ -172,11 +169,11 @@ class TestCoprDetail(CoprsTestCase): assert '<select id="copr_builder_1" name="copr_builder_1">' in r.data assert '<select id="copr_admin_1" name="copr_admin_1">' in r.data
- def test_copr_detail_doesnt_show_cancel_build_for_anonymous(self, f_users, f_coprs, f_builds): + def test_copr_detail_doesnt_show_cancel_build_for_anonymous(self, f_users, f_coprs, f_builds, f_db): r = self.tc.get('/coprs/detail/{0}/{1}/'.format(self.u2.name, self.c2.name)) assert '/cancel_build/' not in r.data
- def test_copr_detail_doesnt_allow_non_submitter_to_cancel_build(self, f_users, f_coprs, f_builds): + def test_copr_detail_doesnt_allow_non_submitter_to_cancel_build(self, f_users, f_coprs, f_builds, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -185,7 +182,7 @@ class TestCoprDetail(CoprsTestCase): r = c.get('/coprs/detail/{0}/{1}/builds/'.format(self.u2.name, self.c2.name)) assert '/cancel_build/' not in r.data
- def test_copr_detail_allows_submitter_to_cancel_build(self, f_users, f_coprs, f_builds): + def test_copr_detail_allows_submitter_to_cancel_build(self, f_users, f_coprs, f_builds, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u2.openid_name @@ -196,7 +193,7 @@ class TestCoprDetail(CoprsTestCase):
class TestCoprEdit(CoprsTestCase): - def test_edit_prefills_id(self, f_users, f_coprs): + def test_edit_prefills_id(self, f_users, f_coprs, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -209,7 +206,7 @@ class TestCoprEdit(CoprsTestCase):
class TestCoprUpdate(CoprsTestCase): - def test_update_no_changes(self, f_users, f_coprs, f_mock_chroots): + def test_update_no_changes(self, f_users, f_coprs, f_mock_chroots, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -220,7 +217,7 @@ class TestCoprUpdate(CoprsTestCase): follow_redirects = True) assert 'Copr was updated successfully' in r.data
- def test_copr_admin_can_update(self, f_users, f_coprs, f_copr_permissions, f_mock_chroots): + def test_copr_admin_can_update(self, f_users, f_coprs, f_copr_permissions, f_mock_chroots, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -229,10 +226,9 @@ class TestCoprUpdate(CoprsTestCase): r = c.post('/coprs/detail/{0}/{1}/update/'.format(self.u2.name, self.c3.name), data = {'name': self.c3.name, 'fedora-rawhide-i386': 'y', 'id': self.c3.id}, follow_redirects = True) - print r.data assert 'Copr was updated successfully' in r.data
- def test_update_multiple_chroots(self, f_users, f_coprs, f_copr_permissions, f_mock_chroots): + def test_update_multiple_chroots(self, f_users, f_coprs, f_copr_permissions, f_mock_chroots, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -251,7 +247,7 @@ class TestCoprUpdate(CoprsTestCase): assert self.mc3.chroot_name in mock_chroots_names assert self.mc1.chroot_name not in mock_chroots_names
- def test_update_deletes_multiple_chroots(self, f_users, f_coprs, f_copr_permissions, f_mock_chroots): + def test_update_deletes_multiple_chroots(self, f_users, f_coprs, f_copr_permissions, f_mock_chroots, f_db): # https://fedorahosted.org/copr/ticket/42 with self.tc as c: with c.session_transaction() as s: @@ -274,7 +270,7 @@ class TestCoprUpdate(CoprsTestCase): assert len(mock_chroots) == 1
class TestCoprApplyForPermissions(CoprsTestCase): - def test_apply(self, f_users, f_coprs): + def test_apply(self, f_users, f_coprs, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u2.openid_name @@ -292,7 +288,7 @@ class TestCoprApplyForPermissions(CoprsTestCase): assert new_perm.copr_builder == 1 assert new_perm.copr_admin == 0
- def test_apply_doesnt_lower_other_values_from_admin_to_request(self, f_users, f_coprs, f_copr_permissions): + def test_apply_doesnt_lower_other_values_from_admin_to_request(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -311,7 +307,7 @@ class TestCoprApplyForPermissions(CoprsTestCase): assert new_perm.copr_admin == 1
class TestCoprUpdatePermissions(CoprsTestCase): - def test_cancel_permission(self, f_users, f_coprs, f_copr_permissions): + def test_cancel_permission(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u2.openid_name @@ -326,7 +322,7 @@ class TestCoprUpdatePermissions(CoprsTestCase): check_string += 'request</option><option selected value="2">approved</option></select>' assert check_string not in r.data
- def test_update_more_permissions(self, f_users, f_coprs, f_copr_permissions): + def test_update_more_permissions(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u2.openid_name @@ -348,7 +344,7 @@ class TestCoprUpdatePermissions(CoprsTestCase): assert u3_c3_perms.copr_builder == self.helpers.PermissionEnum.num('nothing') assert u3_c3_perms.copr_admin == self.helpers.PermissionEnum.num('approved')
- def test_copr_admin_can_update_permissions(self, f_users, f_coprs, f_copr_permissions): + def test_copr_admin_can_update_permissions(self, f_users, f_coprs, f_copr_permissions, f_db): with self.tc as c: with c.session_transaction() as s: s['openid'] = self.u1.openid_name @@ -357,5 +353,4 @@ class TestCoprUpdatePermissions(CoprsTestCase): r = c.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c3.name), data = {'copr_builder_1': '2', 'copr_admin_3': '2'}, follow_redirects = True) - print r.data assert 'Copr permissions were updated' in r.data
copr-devel@lists.fedorahosted.org