Skip to content

Commit

Permalink
new_tests.helpers.call_auth now uses logic.check_access
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbaptista authored and amercader committed Jun 19, 2014
1 parent 599463c commit 9c9481c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
6 changes: 4 additions & 2 deletions ckan/new_tests/helpers.py
Expand Up @@ -19,7 +19,9 @@
'''
import ckan.model as model
import ckan.logic as logic
import ckan.new_authz as new_authz


NotAuthorized = logic.NotAuthorized


def reset_db():
Expand Down Expand Up @@ -112,4 +114,4 @@ def call_auth(auth_name, context, **kwargs):
assert 'model' in context, ('Test methods must put a model in the '
'context dict')

return new_authz.is_authorized(auth_name, context, data_dict=kwargs)
return logic.check_access(auth_name, context, data_dict=kwargs)
32 changes: 15 additions & 17 deletions ckan/new_tests/logic/auth/test_update.py
Expand Up @@ -2,6 +2,7 @@
'''
import mock
import nose

import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
Expand Down Expand Up @@ -32,13 +33,12 @@ def test_user_update_visitor_cannot_update_user(self):
'id': fred.id,
'name': 'updated_user_name',
}
result = helpers.call_auth('user_update', context=context, **params)

assert result['success'] is False
# FIXME: This is a terrible error message, containing both 127.0.0.1
# and Fred's user id (not his name).
assert result['msg'] == ('User 127.0.0.1 not authorized to edit user '
'fred_user_id')
with nose.tools.assert_raises(helpers.NotAuthorized) as cm:
helpers.call_auth('user_update', context=context, **params)

assert cm.exception.extra_msg == ('User 127.0.0.1 not authorized to '
'edit user fred_user_id')

## START-AFTER

Expand Down Expand Up @@ -69,14 +69,14 @@ def test_user_update_user_cannot_update_another_user(self):
'id': fred.id,
'name': 'updated_user_name',
}
result = helpers.call_auth('user_update', context=context, **params)

# 3. Make assertions about the return value and/or side-effects.

assert result['success'] is False
# FIXME: This error message should contain Fred's user name not his id.
assert result['msg'] == ('User bob not authorized to edit user '
'fred_user_id')
with nose.tools.assert_raises(helpers.NotAuthorized) as cm:
helpers.call_auth('user_update', context=context, **params)

assert cm.exception.extra_msg == ('User bob not authorized to edit '
'user fred_user_id')

# 4. Do nothing else!

Expand Down Expand Up @@ -107,9 +107,8 @@ def test_user_update_user_can_update_herself(self):
'id': fred.id,
'name': 'updated_user_name',
}
result = helpers.call_auth('user_update', context=context, **params)

assert result['success'] is True
assert helpers.call_auth('user_update', context=context, **params)

def test_user_update_with_no_user_in_context(self):

Expand All @@ -132,10 +131,9 @@ def test_user_update_with_no_user_in_context(self):
'id': mock_user.id,
'name': 'updated_user_name',
}
result = helpers.call_auth('user_update', context=context, **params)
with nose.tools.assert_raises(helpers.NotAuthorized) as cm:
helpers.call_auth('user_update', context=context, **params)

assert result['success'] is False
# FIXME: Be nice if this error message was a complete sentence.
assert result['msg'] == 'Have to be logged in to edit user'
assert cm.exception.extra_msg == 'Have to be logged in to edit user'

# TODO: Tests for user_update's reset_key behavior.

0 comments on commit 9c9481c

Please sign in to comment.