Skip to content

Commit

Permalink
Bug 922759 - Test that BasketException has the right error code
Browse files Browse the repository at this point in the history
  • Loading branch information
dpoirier committed Oct 8, 2013
1 parent e8aa690 commit 4ef07f8
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions basket/tests.py
Expand Up @@ -3,8 +3,8 @@
from requests.exceptions import ConnectionError, Timeout
from mock import ANY, Mock, patch

from basket import (BasketException, confirm, confirm_email_change, debug_user, get_newsletters,
lookup_user, request, send_recovery_message,
from basket import (BasketException, confirm, confirm_email_change, debug_user,
errors, get_newsletters, lookup_user, request, send_recovery_message,
start_email_change, subscribe,
unsubscribe, update_user, user)
from basket.base import basket_url, get_env_or_setting, parse_response
Expand Down Expand Up @@ -48,8 +48,25 @@ def test_response_error(self):
content = json.dumps({'status': 'error', 'desc': 'ERROR', 'code': 3})
res = Mock(status_code=200, content=content,
content_type='application/json')
with self.assertRaises(BasketException):
try:
parse_response(res)
except BasketException as e:
self.assertEqual(3, e.code)
else:
self.fail("parse_response should have raised BasketException")

def test_response_error_no_code(self):
"""if response has no code, and is error, then the code in
the exception is the UNKNOWN code"""
content = json.dumps({'status': 'error', 'desc': 'ERROR'})
res = Mock(status_code=200, content=content,
content_type='application/json')
try:
parse_response(res)
except BasketException as e:
self.assertEqual(errors.BASKET_UNKNOWN_ERROR, e.code)
else:
self.fail("parse_response should have raised BasketException")

def test_response_content(self):
"""parse_response() returns parsed response content if no error"""
Expand Down

0 comments on commit 4ef07f8

Please sign in to comment.