[copr] bkabrda-workspace: Some more fixes (30aee74)

bkabrda at fedorahosted.org bkabrda at fedorahosted.org
Mon Nov 26 12:43:28 UTC 2012


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

On branch  : bkabrda-workspace

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

commit 30aee74e8f0f8162643b090b5f268cf8b2cdef02
Author: Bohuslav Kabrda <bkabrda at redhat.com>
Date:   Mon Nov 26 13:43:19 2012 +0100

    Some more fixes


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

 wsgi/coprs/views/coprs_ns/coprs_general.py         |   12 +++++--
 wsgi/tests/coprs_test_case.py                      |    1 +
 .../tests/test_views/test_coprs_ns/test_general.py |   34 +++++++------------
 3 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/wsgi/coprs/views/coprs_ns/coprs_general.py b/wsgi/coprs/views/coprs_ns/coprs_general.py
index bc32dc4..e1638f1 100644
--- a/wsgi/coprs/views/coprs_ns/coprs_general.py
+++ b/wsgi/coprs/views/coprs_ns/coprs_general.py
@@ -189,13 +189,19 @@ def copr_update_permissions(username, coprname):
     if permissions_form.validate_on_submit():
         # we don't change owner (yet)
         for perm in permissions:
-            copr_builder = helpers.PermissionEnum.num('Request')
-            copr_admin = helpers.PermissionEnum.num('Request')
+            copr_builder = perm.copr_builder
+            copr_admin = perm.copr_admin
+            # if the permission is granted, use Approved
+            # otherwise if it was Approved and it is ungranted, use Request,
+            # else use original value
             if permissions_form['copr_builder_{0}'.format(perm.user_id)].data:
                 copr_builder = helpers.PermissionEnum.num('Approved')
+            elif copr_builder == helpers.PermissionEnum.num('Approved'):
+                copr_builder = helpers.PermissionEnum.num('Request')
             if permissions_form['copr_admin_{0}'.format(perm.user_id)].data:
                 copr_admin = helpers.PermissionEnum.num('Approved')
-
+            elif copr_admin == helpers.PermissionEnum.num('Approved'):
+                copr_admin = helpers.PermissionEnum.num('Request')
 
             models.CoprPermission.query.filter(models.CoprPermission.copr_id == copr.id).\
                                         filter(models.CoprPermission.user_id == perm.user_id).\
diff --git a/wsgi/tests/coprs_test_case.py b/wsgi/tests/coprs_test_case.py
index 3aa7496..732200e 100644
--- a/wsgi/tests/coprs_test_case.py
+++ b/wsgi/tests/coprs_test_case.py
@@ -15,6 +15,7 @@ class CoprsTestCase(object):
         self.app.testing = True
         self.db = coprs.db
         self.models = models
+        self.helpers = helpers
         # create datadir if it doesn't exist
         datadir = os.path.commonprefix([self.app.config['DATABASE'], self.app.config['OPENID_STORE']])
         if not os.path.exists(datadir):
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 6e11d2a..d02c473 100644
--- a/wsgi/tests/test_views/test_coprs_ns/test_general.py
+++ b/wsgi/tests/test_views/test_coprs_ns/test_general.py
@@ -193,23 +193,6 @@ class TestCoprApplyForPermissions(CoprsTestCase):
             assert new_perm.copr_builder == 1
             assert new_perm.copr_admin == 0
 
-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:
@@ -231,8 +214,17 @@ class TestCoprUpdatePermissions(CoprsTestCase):
 
             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'},
+                       data = {'copr_builder_1': 'y', 'copr_admin_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
+            self.db.session.add_all([self.c3, self.u1, self.u3])
+            u1_c3_perms = self.models.CoprPermission.query.filter(self.models.CoprPermission.copr_id == self.c3.id).\
+                                                           filter(self.models.CoprPermission.user_id == self.u1.id).\
+                                                           first()
+            assert u1_c3_perms.copr_builder == self.helpers.PermissionEnum.num('Approved')
+            assert u1_c3_perms.copr_admin == self.helpers.PermissionEnum.num('Request')
+
+            u3_c3_perms = self.models.CoprPermission.query.filter(self.models.CoprPermission.copr_id == self.c3.id).\
+                                                           filter(self.models.CoprPermission.user_id == self.u3.id).\
+                                                           first()
+            assert u3_c3_perms.copr_builder == self.helpers.PermissionEnum.num('No Action')
+            assert u3_c3_perms.copr_admin == self.helpers.PermissionEnum.num('Approved')



More information about the copr-devel mailing list