From 910f4b0bde1d92e0a5e4219b6eb7a74baa2f8fd0 Mon Sep 17 00:00:00 2001 From: tobes Date: Wed, 10 Oct 2012 13:38:29 +0100 Subject: [PATCH] [#2939] remove another authz test --- ckan/tests/functional/test_edit_authz.py | 303 ----------------------- 1 file changed, 303 deletions(-) delete mode 100644 ckan/tests/functional/test_edit_authz.py diff --git a/ckan/tests/functional/test_edit_authz.py b/ckan/tests/functional/test_edit_authz.py deleted file mode 100644 index d3c01607990..00000000000 --- a/ckan/tests/functional/test_edit_authz.py +++ /dev/null @@ -1,303 +0,0 @@ -import ckan.model as model -from ckan.tests import * -from ckan.lib.base import * -import ckan.authz as authz - - -def check_and_set_checkbox(theform, user, role, should_be, set_to): - '''Given an authz form, find the checkbox associated with the strings user and role, - assert that it\'s in the state 'should_be', and set it to 'set_to' ''' - user_id = model.User.get(user).id - user_role_string = '%s$%s' % (user_id, role) - checkboxes = [x for x in theform.fields[user_role_string] \ - if x.__class__.__name__ == 'Checkbox'] - - assert(len(checkboxes)==1), \ - "there should only be one checkbox for %s/%s" % (user, role) - checkbox = checkboxes[0] - - #checkbox should be unticked - assert checkbox.checked==should_be, \ - "%s/%s checkbox in unexpected state" % (user, role) - - #tick or untick the box and return the form - checkbox.checked=set_to - return theform - - -class TestEditAuthz(TestController): - @classmethod - def setup_class(self): - # for the authorization editing tests we set up test data so: - # three users, sysadmin , administrator, and another - # one group, one package - # and administrator is admin on all three - model.repo.init_db() - model.repo.new_revision() - - self.sysadmin = 'sysadmin' - sysadmin_user = model.User(name=unicode(self.sysadmin)) - self.admin = 'administrator' - admin_user = model.User(name=unicode(self.admin)) - self.another = 'another' - another_user = model.User(name=unicode(self.another)) - self.group = 'group' - group = model.Group(name=unicode(self.group)) - - - for obj in sysadmin_user, admin_user, another_user, group: - model.Session.add(obj) - - model.add_user_to_role(sysadmin_user, model.Role.ADMIN, model.System()) - model.repo.commit_and_remove() - - model.repo.new_revision() - - self.pkg = u'dataset' - pkg = model.Package(name=self.pkg) - model.Session.add(pkg) - - admin_user = model.User.by_name(unicode(self.admin)) - assert admin_user - - # setup all three authorization objects to have logged in and visitor as editors, and the admin as admin - model.setup_user_roles(pkg, ['editor'], ['editor'], [admin_user]) - model.setup_user_roles(group, ['editor'], ['editor'], [admin_user]) - - model.repo.commit_and_remove() - - @classmethod - def teardown_class(self): - model.repo.rebuild_db() - - def test_access_to_authz(self): - #for each of the three authz pages, check that the access permissions work correctly - for (c,i) in [('package', self.pkg),('group', self.group)]: - offset = url_for(controller=c, action='authz', id=i) - - # attempt to access the authz pages without credentials should result in getting redirected to the login page - res = self.app.get(offset, status=[302]) - res = res.follow() - assert res.request.url.startswith('/user/login') - - # for an ordinary user, it should result in access denied - # which is weird, because in the app proper he'd get redirected too. - # it behaves differently in the test setup, but this is a known strangeness. - res = self.app.get(offset, status=[401], extra_environ={'REMOTE_USER':self.another}) - - # going there as the package administrator or system administrator should be fine - for u in [self.admin,self.sysadmin]: - res = self.app.get(offset, status=[200], extra_environ={'REMOTE_USER':u}) - # the name of the object should appear in the page - assert i in res - assert "Authorization" in res, res - - - def roles_list(self, authzobj): - # get a list of username/roles for a given authorizable object - return [ (r.user.name, r.role) for r in authzobj.roles if r.user] - - # get the users/roles for the specific objects created in our test data - def package_roles(self): - return self.roles_list(model.Package.by_name(self.pkg)) - - def group_roles(self): - return self.roles_list(model.Group.by_name(self.group)) - - - # check that the authz page for each object contains certain key strings - def test_2_read_ok(self): - for (c,i,m) in [('package', self.pkg, self.package_roles),\ - ('group', self.group, self.group_roles)]: - offset = url_for(controller=c, action='authz', id=i) - res = self.app.get(offset, extra_environ={'REMOTE_USER': self.admin}) - assert i in res, res - assert "Authorization" in res, res - - # all the package's users and roles should appear in tables - assert '