Skip to content

Commit

Permalink
[#1224] change tests to check for error type instead of message
Browse files Browse the repository at this point in the history
  • Loading branch information
joetsoi committed Oct 24, 2013
1 parent cc4330b commit faf01bc
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 50 deletions.
Expand Up @@ -266,8 +266,7 @@ def _test_visitors_cannot_purge_groups_or_orgs(self, is_org):
result = tests.call_action_api(self.app, action, id=group_or_org['id'],
status=403,
)
assert result == {'__type': 'Authorization Error',
'message': 'Access denied'}
assert result['__type'] == 'Authorization Error'

def test_visitors_cannot_purge_organizations(self):
'''Visitors (who aren't logged in) should not be authorized to purge
Expand Down
22 changes: 11 additions & 11 deletions ckan/tests/functional/api/model/test_vocabulary.py
Expand Up @@ -399,7 +399,7 @@ def test_vocabulary_create_not_logged_in(self):
params=param_string,
status=403)
assert response.json['success'] is False
assert response.json['error']['message'] == 'Access denied'
assert response.json['error']['__type'] == 'Authorization Error'

def test_vocabulary_create_not_authorized(self):
'''Test that users who are not authorized cannot create vocabs.'''
Expand All @@ -412,7 +412,7 @@ def test_vocabulary_create_not_authorized(self):
str(self.normal_user.apikey)},
status=403)
assert response.json['success'] is False
assert response.json['error']['message'] == 'Access denied'
assert response.json['error']['__type'] == 'Authorization Error'

def test_vocabulary_update_id_only(self):
self._update_vocabulary({'id': self.genre_vocab['id']},
Expand Down Expand Up @@ -494,7 +494,7 @@ def test_vocabulary_update_not_logged_in(self):
params=param_string,
status=403)
assert response.json['success'] is False
assert response.json['error']['message'] == 'Access denied'
assert response.json['error']['__type'] == 'Authorization Error'

def test_vocabulary_update_with_tags(self):
tags = [
Expand Down Expand Up @@ -630,7 +630,7 @@ def test_vocabulary_delete_not_logged_in(self):
params=param_string,
status=403)
assert response.json['success'] is False
assert response.json['error']['message'] == 'Access denied'
assert response.json['error']['__type'] == 'Authorization Error'

def test_vocabulary_delete_not_authorized(self):
'''Test that users who are not authorized cannot delete vocabs.'''
Expand All @@ -642,7 +642,7 @@ def test_vocabulary_delete_not_authorized(self):
str(self.normal_user.apikey)},
status=403)
assert response.json['success'] is False
assert response.json['error']['message'] == 'Access denied'
assert response.json['error']['__type'] == 'Authorization Error'

def test_add_tag_to_vocab(self):
'''Test that a tag can be added to and then retrieved from a vocab.'''
Expand Down Expand Up @@ -781,7 +781,7 @@ def test_add_tag_not_logged_in(self):
params=tag_string,
status=403)
assert response.json['success'] is False
assert response.json['error']['message'] == 'Access denied'
assert response.json['error']['__type'] == 'Authorization Error'

def test_add_tag_not_authorized(self):
tag_dict = {
Expand All @@ -795,7 +795,7 @@ def test_add_tag_not_authorized(self):
str(self.normal_user.apikey)},
status=403)
assert response.json['success'] is False
assert response.json['error']['message'] == 'Access denied'
assert response.json['error']['__type'] == 'Authorization Error'

def test_add_vocab_tag_to_dataset(self):
'''Test that a tag belonging to a vocab can be added to a dataset,
Expand Down Expand Up @@ -1116,8 +1116,8 @@ def test_delete_tag_not_logged_in(self):
params=helpers.json.dumps(params),
status=403)
assert response.json['success'] is False
msg = response.json['error']['message']
assert msg == u"Access denied", msg
error = response.json['error']['__type']
assert error == u"Authorization Error", error

def test_delete_tag_not_authorized(self):
vocab = self.genre_vocab
Expand All @@ -1131,5 +1131,5 @@ def test_delete_tag_not_authorized(self):
str(self.normal_user.apikey)},
status=403)
assert response.json['success'] is False
msg = response.json['error']['message']
assert msg == u"Access denied"
msg = response.json['error']['__type']
assert msg == u"Authorization Error"
24 changes: 8 additions & 16 deletions ckan/tests/functional/api/test_follow.py
Expand Up @@ -424,42 +424,36 @@ def test_01_user_follow_user_bad_apikey(self):
error = ckan.tests.call_action_api(self.app, 'follow_user',
id=self.russianfan['id'], apikey=apikey,
status=403)
assert error['message'] == ('Access denied: '
'You must be logged in to follow users')
assert error['__type'] == 'Authorization Error'

def test_01_user_follow_dataset_bad_apikey(self):
for apikey in ('bad api key', '', ' ', 'None', '3', '35.7', 'xxx'):
error = ckan.tests.call_action_api(self.app, 'follow_dataset',
id=self.warandpeace['id'], apikey=apikey,
status=403)
assert error['message'] == ('Access denied: '
'You must be logged in to follow a dataset.')
assert error['__type'] == 'Authorization Error'

def test_01_user_follow_group_bad_apikey(self):
for apikey in ('bad api key', '', ' ', 'None', '3', '35.7', 'xxx'):
error = ckan.tests.call_action_api(self.app, 'follow_group',
id=self.rogers_group['id'], apikey=apikey,
status=403)
assert error['message'] == ('Access denied: '
'You must be logged in to follow a group.')
assert error['__type'] == 'Authorization Error'

def test_01_user_follow_user_missing_apikey(self):
error = ckan.tests.call_action_api(self.app, 'follow_user',
id=self.russianfan['id'], status=403)
assert error['message'] == ('Access denied: '
'You must be logged in to follow users')
assert error['__type'] == 'Authorization Error'

def test_01_user_follow_dataset_missing_apikey(self):
error = ckan.tests.call_action_api(self.app, 'follow_dataset',
id=self.warandpeace['id'], status=403)
assert error['message'] == ('Access denied: '
'You must be logged in to follow a dataset.')
assert error['__type'] == 'Authorization Error'

def test_01_user_follow_group_missing_apikey(self):
error = ckan.tests.call_action_api(self.app, 'follow_group',
id=self.rogers_group['id'], status=403)
assert error['message'] == ('Access denied: '
'You must be logged in to follow a group.')
assert error['__type'] == 'Authorization Error'

def test_01_follow_bad_object_id(self):
for action in ('follow_user', 'follow_dataset', 'follow_group'):
Expand Down Expand Up @@ -884,16 +878,14 @@ def test_01_unfollow_bad_apikey(self):
'xxx'):
error = ckan.tests.call_action_api(self.app, action,
apikey=apikey, status=403, id=self.joeadmin['id'])
assert error['message'] == ('Access denied: '
'You must be logged in to unfollow something.')
assert error['__type'] == 'Authorization Error'

def test_01_unfollow_missing_apikey(self):
'''Test error response when calling unfollow_* without api key.'''
for action in ('unfollow_user', 'unfollow_dataset', 'unfollow_group'):
error = ckan.tests.call_action_api(self.app, action, status=403,
id=self.joeadmin['id'])
assert error['message'] == ('Access denied: '
'You must be logged in to unfollow something.')
assert error['__type'] == 'Authorization Error'

def test_01_unfollow_bad_object_id(self):
'''Test error response when calling unfollow_* with bad object id.'''
Expand Down
3 changes: 1 addition & 2 deletions ckan/tests/functional/test_related.py
Expand Up @@ -498,5 +498,4 @@ def test_api_delete_fail(self):
extra_environ=extra)
r = json.loads(res.body)
assert r['success'] == False, r
error_msg = u'Access denied: Only the owner can delete a related item'
assert r[u'error'][u'message'] == error_msg, r
assert r[u'error'][u'__type'] == "Authorization Error", r
11 changes: 2 additions & 9 deletions ckan/tests/logic/test_action.py
Expand Up @@ -528,12 +528,7 @@ def test_12_user_update(self):

res_obj = json.loads(res.body)
assert res_obj['help'].startswith("Update a user account.")
error_msg = u'Access denied: User annafan not authorized to edit user {0}'.format(
sysadmin_user_dict['id'])
assert res_obj['error'] == {
'__type': 'Authorization Error',
'message': error_msg,
}
assert res_obj['error']['__type'] == 'Authorization Error'
assert res_obj['success'] is False

def test_12_user_update_errors(self):
Expand Down Expand Up @@ -895,9 +890,7 @@ def test_22_task_status_normal_user_not_authorized(self):
res_obj = json.loads(res.body)
assert res_obj['help'].startswith("Update a task status.")
assert res_obj['success'] is False
error_msg = (u'Access denied: User annafan not authorized to update '
'task_status table')
assert res_obj['error'] == {'message': error_msg, '__type': 'Authorization Error'}
assert res_obj['error']['__type'] == 'Authorization Error'

def test_23_task_status_validation(self):
task_status = {}
Expand Down
3 changes: 1 addition & 2 deletions ckan/tests/logic/test_tag.py
Expand Up @@ -151,8 +151,7 @@ def test_08_user_create_not_authorized(self):
res_obj = json.loads(res.body)
assert res_obj['help'].startswith("Create a new user.")
assert res_obj['success'] is False
error_msg = 'Access denied: User not authorized to create users'
assert res_obj['error'] == {'message': error_msg, '__type': 'Authorization Error'}
assert res_obj['error']['__type'] == 'Authorization Error'

def test_09_user_create(self):
user_dict = {'name':'test_create_from_action_api',
Expand Down
Expand Up @@ -103,8 +103,7 @@ def test_group_create_with_visitor(self):
result = tests.call_action_api(self.app, 'group_create',
name='this_group_should_not_be_created',
status=403)
assert result == {'__type': 'Authorization Error',
'message': 'Access denied'}
assert result['__type'] == 'Authorization Error'

def test_group_create_with_non_curator(self):
'''A user who isn't a member of the curators group should not be able
Expand All @@ -116,8 +115,7 @@ def test_group_create_with_non_curator(self):
name='this_group_should_not_be_created',
apikey=noncurator['apikey'],
status=403)
assert result == {'__type': 'Authorization Error',
'message': 'Access denied'}
assert result['__type'] == 'Authorization Error'

def test_group_create_with_curator(self):
'''A member of the curators group should be able to create a group.
Expand Down Expand Up @@ -174,8 +172,7 @@ def test_group_create_with_visitor(self):
response = tests.call_action_api(self.app, 'group_create',
name='this_group_shouldnt_be_created',
status=403)
assert response == {'__type': 'Authorization Error',
'message': 'Access denied'}
assert response['__type'] == 'Authorization Error'


class TestExampleIAuthFunctionsPluginV2(TestExampleIAuthFunctionsPlugin):
Expand Down Expand Up @@ -203,5 +200,4 @@ def test_group_create_with_curator(self):
name='this_group_should_not_be_created',
apikey=curator['apikey'],
status=403)
assert result == {'__type': 'Authorization Error',
'message': 'Access denied'}
assert result['__type'] == 'Authorization Error'

0 comments on commit faf01bc

Please sign in to comment.