[copr] bkabrda-workspace: More tests (a94e877)

bkabrda at fedoraproject.org bkabrda at fedoraproject.org
Fri Nov 23 10:36:13 UTC 2012


Repository : http://git.fedorahosted.org/cgit/copr.git

On branch  : bkabrda-workspace

>---------------------------------------------------------------

commit a94e87767843afe7d15eb8eabe7c76c802707eaf
Author: Bohuslav Kabrda <bkabrda at redhat.com>
Date:   Fri Nov 23 11:36:04 2012 +0100

    More tests


>---------------------------------------------------------------

 wsgi/tests/coprs_test_case.py                      |    2 +-
 .../tests/test_views/test_coprs_ns/test_general.py |   58 +++++++++++++++++++-
 2 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/wsgi/tests/coprs_test_case.py b/wsgi/tests/coprs_test_case.py
index ea4903e..a70d721 100644
--- a/wsgi/tests/coprs_test_case.py
+++ b/wsgi/tests/coprs_test_case.py
@@ -60,7 +60,7 @@ class CoprsTestCase(object):
     @pytest.fixture
     def f_copr_permissions(self):
         self.cp1 = models.CoprPermission(copr = self.c2, user = self.u1, approved = True)
-        self.cp2 = models.CoprPermission(copr = self.c3, user = self.u2, approved = False)
+        self.cp2 = models.CoprPermission(copr = self.c3, user = self.u3, approved = False)
         self.cp3 = models.CoprPermission(copr = self.c3, user = self.u1, approved = False)
 
         self.db.session.add_all([self.cp1, self.cp2, self.cp3])
diff --git a/wsgi/tests/test_views/test_coprs_ns/test_general.py b/wsgi/tests/test_views/test_coprs_ns/test_general.py
index e5f6478..4eb54c4 100644
--- a/wsgi/tests/test_views/test_coprs_ns/test_general.py
+++ b/wsgi/tests/test_views/test_coprs_ns/test_general.py
@@ -112,7 +112,7 @@ class TestCoprDetail(CoprsTestCase):
     def test_copr_detail_contains_permissions(self, f_users, f_coprs, f_copr_permissions):
         r = self.tc.get('/coprs/detail/{0}/{1}/'.format(self.u2.name, self.c3.name))
         assert '<table class=permissions' in r.data
-        assert '<tr><td>{0}'.format(self.u2.name) in r.data
+        assert '<tr><td>{0}'.format(self.u3.name) in r.data
         assert '<tr><td>{0}'.format(self.u1.name) in r.data
 
     def test_copr_detail_doesnt_contain_forms_for_anonymous_user(self, f_users, f_coprs):
@@ -158,6 +158,17 @@ class TestCoprEdit(CoprsTestCase):
             # to the precise format of the tag
             assert '<input hidden id="id" name="id" type="hidden" value="{0}">'.format(self.c1.id) in r.data
 
+    def test_edit_has_correct_permissions_form(self, f_users, f_coprs, f_copr_permissions):
+        with self.tc as c:
+            with c.session_transaction() as s:
+                s['openid'] = self.u2.openid_name
+
+            self.db.session.add_all([self.u2, self.c3])
+            r = c.get('/coprs/detail/{0}/{1}/edit/'.format(self.u2.name, self.c3.name))
+            assert '<input id="user_3" name="user_3" type="checkbox" value="y">' in r.data
+            assert '<input id="user_1" name="user_1" type="checkbox" value="y">' in r.data
+
+
 class TestCoprUpdate(CoprsTestCase):
     def test_update_no_changes(self, f_users, f_coprs):
         with self.tc as c:
@@ -179,7 +190,6 @@ class TestCoprApplyForBuilding(CoprsTestCase):
             self.db.session.add_all([self.u1, self.u2, self.c1])
             r = c.post('/coprs/detail/{0}/{1}/apply_for_building/'.format(self.u1.name, self.c1.name),
                        follow_redirects = True)
-            print r.data
             assert 'You have successfuly applied' in r.data
 
             self.db.session.add_all([self.u1, self.u2, self.c1])
@@ -187,3 +197,47 @@ class TestCoprApplyForBuilding(CoprsTestCase):
                                                         filter(self.models.CoprPermission.copr_id == self.c1.id).\
                                                         first()
             assert not new_perm.approved
+
+class TestCoprGiveUpBuilding(CoprsTestCase):
+    def test_give_up(self, f_users, f_coprs, f_copr_permissions):
+        with self.tc as c:
+            with c.session_transaction() as s:
+                s['openid'] = self.u1.openid_name
+
+            self.db.session.add_all([self.u1, self.u2, self.c2])
+            r = c.post('/coprs/detail/{0}/{1}/give_up_building/'.format(self.u2.name, self.c2.name),
+                       follow_redirects = True)
+            assert 'You have successfuly given up' in r.data
+
+            self.db.session.add_all([self.u1, self.u2, self.c2])
+            exists = self.models.CoprPermission.query.filter(self.models.CoprPermission.user_id == self.u1.id).\
+                                                      filter(self.models.CoprPermission.copr_id == self.c2.id).\
+                                                      first()
+            assert not exists
+
+class TestCoprUpdatePermissions(CoprsTestCase):
+    def test_cancel_permission(self, f_users, f_coprs, f_copr_permissions):
+        with self.tc as c:
+            with c.session_transaction() as s:
+                s['openid'] = self.u2.openid_name
+
+            self.db.session.add_all([self.u2, self.c2])
+            # Although it shouldn't be needed, preset some data: https://github.com/ajford/flask-wtf/issues/55
+            r = c.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c2.name),
+                       data = {'csrf_token': u'20121123111948##1653cb2ef73cb9f7b4670472df7354416e61cf2d'},
+                       follow_redirects = True)
+            self.db.session.add_all([self.u1])
+            assert '<tr><td>{0}</td><td>{1}</td></tr>'.format(self.u1.name, 'True') not in r.data
+
+    def test_update_more_permissions(self, f_users, f_coprs, f_copr_permissions):
+        with self.tc as c:
+            with c.session_transaction() as s:
+                s['openid'] = self.u2.openid_name
+
+            self.db.session.add_all([self.u2, self.c3])
+            r = c.post('/coprs/detail/{0}/{1}/update_permissions/'.format(self.u2.name, self.c3.name),
+                       data = {'user_1': 'y', 'user_3': 'y'},
+                       follow_redirects = True)
+            self.db.session.add_all([self.u1, self.u3])
+            assert '<tr><td>{0}</td><td>{1}</td></tr>'.format(self.u1.name, 'True') in r.data
+            assert '<tr><td>{0}</td><td>{1}</td></tr>'.format(self.u3.name, 'True') in r.data



More information about the copr-devel mailing list