diff --git a/ckan/new_tests/lib/navl/test_validators.py b/ckan/new_tests/lib/navl/test_validators.py index d4f10f8b2bc..129f3a04ea3 100644 --- a/ckan/new_tests/lib/navl/test_validators.py +++ b/ckan/new_tests/lib/navl/test_validators.py @@ -40,9 +40,9 @@ def test_ignore_missing_with_value_missing(self): original_data = copy.deepcopy(data) original_errors = copy.deepcopy(errors) - with nose.tools.assert_raises(df.StopOnError) as context: - validators.ignore_missing(key=key, data=data, errors=errors, - context={}) + nose.tools.assert_raises(df.StopOnError, + validators.ignore_missing, key=key, + data=data, errors=errors, context={}) assert key not in data, ('When given a value of {value} ' 'ignore_missing() should remove the item ' diff --git a/ckan/new_tests/logic/action/test_update.py b/ckan/new_tests/logic/action/test_update.py index 47de201a664..f33641ba3af 100644 --- a/ckan/new_tests/logic/action/test_update.py +++ b/ckan/new_tests/logic/action/test_update.py @@ -79,16 +79,16 @@ def test_user_update_with_id_that_does_not_exist(self): user_dict = factories.User.attributes() user_dict['id'] = "there's no user with this id" - with nose.tools.assert_raises(logic.NotFound) as context: - helpers.call_action('user_update', **user_dict) + nose.tools.assert_raises(logic.NotFound, helpers.call_action, + 'user_update', **user_dict) # TODO: Could assert the actual error message, not just the exception? # (Could also do this with many of the tests below.) def test_user_update_with_no_id(self): user_dict = factories.User.attributes() assert 'id' not in user_dict - with nose.tools.assert_raises(logic.ValidationError) as context: - helpers.call_action('user_update', **user_dict) + nose.tools.assert_raises(logic.ValidationError, helpers.call_action, + 'user_update', **user_dict) def test_user_update_with_invalid_name(self): user = factories.User() @@ -97,8 +97,9 @@ def test_user_update_with_invalid_name(self): 'a'*200, 'Hi!', ) for name in invalid_names: user['name'] = name - with nose.tools.assert_raises(logic.ValidationError) as context: - helpers.call_action('user_update', **user) + nose.tools.assert_raises(logic.ValidationError, + helpers.call_action, 'user_update', + **user) def test_user_update_to_name_that_already_exists(self): fred = factories.User(name='fred') @@ -107,8 +108,8 @@ def test_user_update_to_name_that_already_exists(self): # Try to update fred and change his user name to bob, which is already # bob's user name fred['name'] = bob['name'] - with nose.tools.assert_raises(logic.ValidationError) as context: - helpers.call_action('user_update', **fred) + nose.tools.assert_raises(logic.ValidationError, helpers.call_action, + 'user_update', **fred) def test_user_update_password(self): '''Test that updating a user's password works successfully.''' @@ -132,8 +133,8 @@ def test_user_update_with_short_password(self): user = factories.User() user['password'] = 'xxx' # This password is too short. - with nose.tools.assert_raises(logic.ValidationError) as context: - helpers.call_action('user_update', **user) + nose.tools.assert_raises(logic.ValidationError, helpers.call_action, + 'user_update', **user) def test_user_update_with_empty_password(self): '''If an empty password is passed to user_update, nothing should @@ -158,16 +159,17 @@ def test_user_update_with_null_password(self): user = factories.User() user['password'] = None - with nose.tools.assert_raises(logic.ValidationError) as context: - helpers.call_action('user_update', **user) + nose.tools.assert_raises(logic.ValidationError, helpers.call_action, + 'user_update', **user) def test_user_update_with_invalid_password(self): user = factories.User() for password in (False, -1, 23, 30.7): user['password'] = password - with nose.tools.assert_raises(logic.ValidationError) as context: - helpers.call_action('user_update', **user) + nose.tools.assert_raises(logic.ValidationError, + helpers.call_action, 'user_update', + **user) # TODO: Valid and invalid values for the rest of the user model's fields. diff --git a/ckan/new_tests/logic/test_validators.py b/ckan/new_tests/logic/test_validators.py index bbc5cb17a79..8293edfadc2 100644 --- a/ckan/new_tests/logic/test_validators.py +++ b/ckan/new_tests/logic/test_validators.py @@ -78,8 +78,7 @@ def call_validator(*args, **kwargs): ''' def call_and_assert(*args, **kwargs): import ckan.lib.navl.dictization_functions as df - with nose.tools.assert_raises(df.Invalid) as context: - return function(*args, **kwargs) + nose.tools.assert_raises(df.Invalid, function, *args, **kwargs) return call_and_assert