Skip to content

Commit

Permalink
[#1117] Remove uses of assert_raises as context manager
Browse files Browse the repository at this point in the history
Using assert_raises as a context manager isn't supported in Python 2.6.
Tests were failing on Travis when run with Python 2.6. Hopefully this
fixes them.
  • Loading branch information
Sean Hammond committed Aug 1, 2013
1 parent 282545c commit 135c59b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ckan/new_tests/logic/action/test_update.py
Expand Up @@ -73,15 +73,15 @@ 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:
with 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:
with nose.tools.assert_raises(logic.ValidationError):
helpers.call_action('user_update', **user_dict)

def test_user_update_with_invalid_name(self):
Expand All @@ -91,7 +91,7 @@ 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:
with nose.tools.assert_raises(logic.ValidationError):
helpers.call_action('user_update', **user)

def test_user_update_to_name_that_already_exists(self):
Expand All @@ -101,7 +101,7 @@ 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:
with nose.tools.assert_raises(logic.ValidationError):
helpers.call_action('user_update', **fred)

def test_user_update_password(self):
Expand All @@ -126,7 +126,7 @@ 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:
with nose.tools.assert_raises(logic.ValidationError):
helpers.call_action('user_update', **user)

def test_user_update_with_empty_password(self):
Expand All @@ -152,15 +152,15 @@ def test_user_update_with_null_password(self):
user = factories.User()

user['password'] = None
with nose.tools.assert_raises(logic.ValidationError) as context:
with 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:
with 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.
Expand Down

0 comments on commit 135c59b

Please sign in to comment.