[ckan-changes] commit/ckan: 3 new changesets

Bitbucket commits-noreply at bitbucket.org
Sat May 14 13:28:53 UTC 2011


3 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/8791210e33e8/
changeset:   r3084:8791210e33e8
branch:      feature-1074-authz-wui
user:        John Lawrence Aspden
date:        2011-05-14 14:49:44
summary:     [authz][s]: fix failing test
affected #:  1 file (2.7 KB)

--- a/ckan/tests/functional/test_package_edit_authz.py	Sat May 14 13:22:10 2011 +0100
+++ b/ckan/tests/functional/test_package_edit_authz.py	Sat May 14 13:49:44 2011 +0100
@@ -107,10 +107,6 @@
         assert href in res, res
 
 
-#################################################################
-#################################################################
-
-
     def _prs(self, pkgname):
         pkg = model.Package.by_name(pkgname)
         return dict([ (getattr(r.user, 'name', 'USER NAME IS NONE'), r) for r in pkg.roles ])
@@ -164,23 +160,99 @@
 
     def test_3_sysadmin_changes_role(self):
         self.change_roles(self.sysadmin)
+
+
+
+#################################################################
+#################################################################
+
     
     def test_4_admin_deletes_role(self):
-        pkg = model.Package.by_name(self.pkgname)
-        assert len(pkg.roles) == 3
-        # make sure not admin
-        pr_id = [ r for r in pkg.roles if r.user.name != self.admin ][0].id
-        offset = url_for(controller='package', action='authz', id=self.pkgname,
-                role_to_delete=pr_id)
-        # need this here as o/w conflicts over session binding
-        model.Session.remove()
-        res = self.app.get(offset, extra_environ={'REMOTE_USER':
-            self.admin})
-        assert 'Deleted role' in res, res
-        assert 'error' not in res, res
-        pkg = model.Package.by_name(self.pkgname)
-        assert len(pkg.roles) == 2
-        assert model.Session.query(model.PackageRole).filter_by(id=pr_id).count() == 0
+        # get the authz page, check that visitor's in there
+        # remove visitor's role on the package
+        # re-get the page and make sure that visitor's not in there at all
+        offset = url_for(controller='package', action='authz', id=self.pkgname)
+        res = self.app.get(offset, extra_environ={'REMOTE_USER':self.admin})
+        assert self.pkgname in res
+
+        prs=package_roles(self.pkgname)
+        assert len(prs) == 3
+        assert ('madeup-administrator', 'admin') in prs 
+        assert ('visitor', 'editor') in prs 
+        assert ('logged_in', 'editor') in prs
+
+        assert 'visitor' in res
+        assert 'madeup-administrator' in res
+        assert 'logged_in' in res
+
+        #admin removes visitor's only role
+        form = res.forms['theform']
+        check_and_set_checkbox(form, u'visitor', u'editor', True, False)
+        res = form.submit('save', extra_environ={'REMOTE_USER': self.admin})
+
+        # ensure db was changed
+        prs=package_roles(self.pkgname)
+        assert len(prs) == 2
+        assert ('madeup-administrator', 'admin') in prs 
+        assert ('logged_in', 'editor') in prs
+
+        # ensure rerender of form is changed
+        offset = url_for(controller='package', action='authz', id=self.pkgname)
+        res = self.app.get(offset, extra_environ={'REMOTE_USER':self.admin})
+        assert self.pkgname in res
+
+        assert 'visitor' not in res
+        assert 'madeup-administrator' in res
+        assert 'logged_in' in res
+
+        # check that the checkbox states are what we think they should be
+        form = res.forms['theform']
+        check_and_set_checkbox(form, u'logged_in', u'editor', True, True)
+        check_and_set_checkbox(form, u'madeup-administrator', u'admin', True, True)
+
+        # now we should add visitor back in, let's make him a reader
+        form = res.forms['addform']
+        form.fields['new_user_name'][0].value='visitor'
+        checkbox = [x for x in form.fields['reader'] \
+                      if x.__class__.__name__ == 'Checkbox'][0]
+        # check it's currently unticked
+        assert checkbox.checked == False
+        # tick it and submit
+        checkbox.checked=True
+        res = form.submit('add', extra_environ={'REMOTE_USER':self.admin})
+        assert "User Added" in res, "don't see flash message"
+
+       # check that the page contains strings for everyone
+        assert 'visitor' in res
+        assert 'madeup-administrator' in res
+        assert 'logged_in' in res
+
+        # check that the roles in the db are back to normal
+        prs=package_roles(self.pkgname)
+        assert len(prs) == 3
+        assert ('madeup-administrator', 'admin') in prs 
+        assert ('visitor', 'reader') in prs 
+        assert ('logged_in', 'editor') in prs
+
+        # now change him back to being an editor
+        form = res.forms['theform']
+        check_and_set_checkbox(form, u'visitor', u'reader', True, False)
+        check_and_set_checkbox(form, u'visitor', u'editor', False, True)
+        res = form.submit('save', extra_environ={'REMOTE_USER': self.admin})
+ 
+        # check that the page contains strings for everyone
+        assert 'visitor' in res
+        assert 'madeup-administrator' in res
+        assert 'logged_in' in res
+
+        # check that the roles in the db are back to normal
+        prs=package_roles(self.pkgname)
+        assert len(prs) == 3
+        assert ('madeup-administrator', 'admin') in prs 
+        assert ('visitor', 'editor') in prs 
+        assert ('logged_in', 'editor') in prs
+
+
 
     def test_4_sysadmin_deletes_role(self):
         pkg = model.Package.by_name(self.pkgname2)


http://bitbucket.org/okfn/ckan/changeset/dd639d6ded20/
changeset:   r3085:dd639d6ded20
branch:      feature-1074-authz-wui
user:        John Lawrence Aspden
date:        2011-05-14 15:08:43
summary:     [authz][s]: all tests fixed
affected #:  1 file (2.8 KB)

--- a/ckan/tests/functional/test_package_edit_authz.py	Sat May 14 13:49:44 2011 +0100
+++ b/ckan/tests/functional/test_package_edit_authz.py	Sat May 14 14:08:43 2011 +0100
@@ -91,20 +91,13 @@
         res = self.app.get(offset, extra_environ={'REMOTE_USER':
             self.admin})
         assert self.pkgname in res
+
+        # all the package's users and roles should appear in tables
         assert '<tr' in res
-        assert self.admin in res
-        assert 'Role' in res
-        for uname in [ model.PSEUDO_USER__VISITOR, self.admin ]:
-            assert '%s' % uname in res
-        # crude but roughly correct
-        pkg = model.Package.by_name(self.pkgname)
-        for r in pkg.roles:
-            assert '<select id="PackageRole-%s-role' % r.id in res
+        for (user,role) in package_roles(self.pkgname):
+            assert user in res
+            assert role in res
 
-        # now test delete links
-        pr = pkg.roles[0]
-        href = '%s' % pr.id
-        assert href in res, res
 
 
     def _prs(self, pkgname):
@@ -165,14 +158,15 @@
 
 #################################################################
 #################################################################
+    
+    
 
-    
-    def test_4_admin_deletes_role(self):
+    def delete_role_as(self,user):
         # get the authz page, check that visitor's in there
         # remove visitor's role on the package
         # re-get the page and make sure that visitor's not in there at all
         offset = url_for(controller='package', action='authz', id=self.pkgname)
-        res = self.app.get(offset, extra_environ={'REMOTE_USER':self.admin})
+        res = self.app.get(offset, extra_environ={'REMOTE_USER':user})
         assert self.pkgname in res
 
         prs=package_roles(self.pkgname)
@@ -188,7 +182,7 @@
         #admin removes visitor's only role
         form = res.forms['theform']
         check_and_set_checkbox(form, u'visitor', u'editor', True, False)
-        res = form.submit('save', extra_environ={'REMOTE_USER': self.admin})
+        res = form.submit('save', extra_environ={'REMOTE_USER': user})
 
         # ensure db was changed
         prs=package_roles(self.pkgname)
@@ -198,7 +192,7 @@
 
         # ensure rerender of form is changed
         offset = url_for(controller='package', action='authz', id=self.pkgname)
-        res = self.app.get(offset, extra_environ={'REMOTE_USER':self.admin})
+        res = self.app.get(offset, extra_environ={'REMOTE_USER':user})
         assert self.pkgname in res
 
         assert 'visitor' not in res
@@ -219,7 +213,7 @@
         assert checkbox.checked == False
         # tick it and submit
         checkbox.checked=True
-        res = form.submit('add', extra_environ={'REMOTE_USER':self.admin})
+        res = form.submit('add', extra_environ={'REMOTE_USER':user})
         assert "User Added" in res, "don't see flash message"
 
        # check that the page contains strings for everyone
@@ -238,7 +232,7 @@
         form = res.forms['theform']
         check_and_set_checkbox(form, u'visitor', u'reader', True, False)
         check_and_set_checkbox(form, u'visitor', u'editor', False, True)
-        res = form.submit('save', extra_environ={'REMOTE_USER': self.admin})
+        res = form.submit('save', extra_environ={'REMOTE_USER': user})
  
         # check that the page contains strings for everyone
         assert 'visitor' in res
@@ -253,67 +247,10 @@
         assert ('logged_in', 'editor') in prs
 
 
+    def test_4_admin_deletes_role(self):
+        self.delete_role_as(self.admin)
 
     def test_4_sysadmin_deletes_role(self):
-        pkg = model.Package.by_name(self.pkgname2)
-        assert len(pkg.roles) == 3
-        # make sure not admin
-        pr_id = [ r for r in pkg.roles if r.user.name != self.admin ][0].id
-        offset = url_for(controller='package', action='authz', id=self.pkgname2,
-                role_to_delete=pr_id)
-        # need this here as o/w conflicts over session binding
-        model.Session.remove()
-        res = self.app.get(offset, extra_environ={'REMOTE_USER':
-            self.sysadmin})
-        assert 'Deleted role' in res, res
-        assert 'error' not in res, res
-        pkg = model.Package.by_name(self.pkgname2)
-        assert len(pkg.roles) == 2
-        assert model.Session.query(model.PackageRole).filter_by(id=pr_id).count() == 0
+        self.delete_role_as(self.sysadmin)
 
-    def test_5_admin_adds_role(self):
-        offset = url_for(controller='package', action='authz', id=self.pkgname)
-        res = self.app.get(offset, extra_environ={'REMOTE_USER':
-            self.admin})
-        assert self.pkgname in res
-        prs = self._prs(self.pkgname) 
-        startlen = len(prs)
-        # could be 2 or 3 depending on whether we ran this test alone or not
-        # assert len(prs) == 2, prs
 
-        assert 'Create New User Roles' in res
-        assert '<select id=' in res, res
-        form = res.forms['package-authz']
-        another = model.User.by_name(self.another)
-        form.select('PackageRole--user_id', another.id)
-        form.select('PackageRole--role', model.Role.ADMIN)
-        res = form.submit('save', extra_environ={'REMOTE_USER': self.admin})
-        model.Session.remove()
-
-        prs = self._prs(self.pkgname)
-        assert len(prs) == startlen+1, prs
-        assert prs[self.another].role == model.Role.ADMIN
-
-    def test_5_sysadmin_adds_role(self):
-        offset = url_for(controller='package', action='authz', id=self.pkgname2)
-        res = self.app.get(offset, extra_environ={'REMOTE_USER':
-            self.sysadmin})
-        assert self.pkgname2 in res
-        prs = self._prs(self.pkgname2) 
-        startlen = len(prs)
-        # could be 2 or 3 depending on whether we ran this test alone or not
-        # assert len(prs) == 2, prs
-
-        assert 'Create New User Roles' in res
-        assert '<select id=' in res, res
-        form = res.forms['package-authz']
-        another = model.User.by_name(self.another)
-        form.select('PackageRole--user_id', another.id)
-        form.select('PackageRole--role', model.Role.ADMIN)
-        res = form.submit('save', extra_environ={'REMOTE_USER': self.sysadmin})
-        model.Session.remove()
-
-        prs = self._prs(self.pkgname2)
-        assert len(prs) == startlen+1, prs
-        assert prs[self.another].role == model.Role.ADMIN
-


http://bitbucket.org/okfn/ckan/changeset/1f72a83087ab/
changeset:   r3086:1f72a83087ab
branch:      feature-1074-authz-wui
user:        John Lawrence Aspden
date:        2011-05-14 15:20:51
summary:     [authz][s]: waypoint. full test run passes.
affected #:  1 file (447 bytes)

--- a/ckan/tests/functional/test_package_edit_authz.py	Sat May 14 14:08:43 2011 +0100
+++ b/ckan/tests/functional/test_package_edit_authz.py	Sat May 14 14:20:51 2011 +0100
@@ -72,10 +72,7 @@
         res = self.app.get(offset, status=[302, 401])
         res = res.follow()
         assert res.request.url.startswith('/user/login')
-        # Alternative if we allowed read-only access
-        # res = self.app.get(offset)
-        # assert not '<form' in res, res
-    
+     
     def test_1_admin_has_access(self):
         offset = url_for(controller='package', action='authz', id=self.pkgname)
         res = self.app.get(offset, extra_environ={'REMOTE_USER':
@@ -98,13 +95,6 @@
             assert user in res
             assert role in res
 
-
-
-    def _prs(self, pkgname):
-        pkg = model.Package.by_name(pkgname)
-        return dict([ (getattr(r.user, 'name', 'USER NAME IS NONE'), r) for r in pkg.roles ])
-
-
     def change_roles(self, user):
         # load authz page
         offset = url_for(controller='package', action='authz', id=self.pkgname)
@@ -154,13 +144,6 @@
     def test_3_sysadmin_changes_role(self):
         self.change_roles(self.sysadmin)
 
-
-
-#################################################################
-#################################################################
-    
-    
-
     def delete_role_as(self,user):
         # get the authz page, check that visitor's in there
         # remove visitor's role on the package

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list