Skip to content

Commit

Permalink
[#2035] Further fixes to auth tests
Browse files Browse the repository at this point in the history
The old auth tests are terrible in that they depend on each other to
run. Also the auth cache thing masked some bad assumptions.

The whole file should be rewritten as new tests.
  • Loading branch information
amercader committed Nov 10, 2014
1 parent 3665e38 commit 00b192d
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions ckan/tests/logic/test_auth.py
Expand Up @@ -16,7 +16,7 @@ def setup_class(cls):
{'model': model, 'ignore_auth': True}, {})['apikey']
## This is a mutable dict on the class level so tests can
## add apikeys as they go along
cls.apikeys = {'sysadmin': admin_api, 'random_key': 'moo'}
cls.apikeys = {'sysadmin': str(admin_api), 'random_key': 'moo'}

cls._original_config = config.copy()

Expand Down Expand Up @@ -89,13 +89,19 @@ def test_auth_deleted_users_are_always_unauthorized(self):


class TestAuthOrgs(TestAuth):
def test_01_create_users(self):

@classmethod
def setup_class(cls):

super(TestAuthOrgs, cls).setup_class()

# actual roles assigned later
self.create_user('org_admin')
self.create_user('no_org')
self.create_user('org_editor')
self.create_user('editor_wannabe')
cls.create_user('org_admin')
cls.create_user('no_org')
cls.create_user('org_editor')
cls.create_user('editor_wannabe')

def test_01_create_users(self):
user = {'name': 'user_no_auth',
'password': 'pass',
'email': 'moo@moo.com'}
Expand Down Expand Up @@ -153,15 +159,13 @@ def test_05_add_users_to_org(self):
'id': 'org_with_user'}
self._call_api('organization_member_create', member, 'org_admin')

## admin user should be able to add users now
## editor should not be able to approve others as editors
member = {'username': 'editor_wannabe',
'role': 'editor',
'id': 'org_with_user'}
self._call_api('organization_member_create', member, 'org_editor', 403)

def _add_datasets(self, user):

#org admin/editor should be able to add dataset to org.
dataset = {'name': user + '_dataset', 'owner_org': 'org_with_user'}
self._call_api('package_create', dataset, user, 200)
Expand Down Expand Up @@ -238,8 +242,10 @@ class TestAuthOrgHierarchy(TestAuth):

@classmethod
def setup_class(cls):
TestAuth.setup_class()
# TestAuth.setup_class()
CreateTestData.create_group_hierarchy_test_data()

cls.apikeys = {}
for user in model.Session.query(model.User):
cls.apikeys[user.name] = str(user.apikey)

Expand Down Expand Up @@ -409,10 +415,7 @@ def test_10_edit_org_1(self):
def test_10_edit_org_2(self):
org = {'id': 'national-health-service', 'title': 'test'}
self._flesh_out_organization(org)
import pprint; pprint.pprint(org)
print model.Session.query(model.Member).filter_by(state='deleted').all()
self._call_api('organization_update', org, 'nhsadmin', 200)
print model.Session.query(model.Member).filter_by(state='deleted').all()

def test_10_edit_org_3(self):
org = {'id': 'nhs-wirral-ccg', 'title': 'test'}
Expand Down Expand Up @@ -441,7 +444,7 @@ def test_11_delete_org_1(self):

def test_11_delete_org_2(self):
org = {'id': 'national-health-service'}
self._call_api('organization_delete', org, 'nhsadmin', 403)
self._call_api('organization_delete', org, 'nhsadmin', 200)
self._call_api('organization_delete', org, 'nhseditor', 403)

def test_11_delete_org_3(self):
Expand Down

0 comments on commit 00b192d

Please sign in to comment.