示例#1
0
 def test_response_not_200(self):
     """parse_response() raises exception on non-200 status code"""
     # and puts the status code on the exception
     res = Mock(status_code=666)
     try:
         parse_response(res)
     except BasketException as e:
         self.assertEqual(666, e.status_code)
     else:
         self.fail("parse_response should have raised BasketException")
示例#2
0
 def test_response_not_200(self):
     """parse_response() raises exception on non-200 status code"""
     # and puts the status code on the exception
     res = Mock(status_code=666)
     try:
         parse_response(res)
     except BasketException as e:
         self.assertEqual(666, e.status_code)
     else:
         self.fail("parse_response should have raised BasketException")
示例#3
0
 def test_response_error(self):
     """parse_response() raises exception on status=error"""
     content = json.dumps({'status': 'error', 'desc': 'ERROR', 'code': 3})
     res = Mock(status_code=200, content=content,
                content_type='application/json')
     try:
         parse_response(res)
     except BasketException as e:
         self.assertEqual(3, e.code)
     else:
         self.fail("parse_response should have raised BasketException")
示例#4
0
 def test_response_error(self):
     """parse_response() raises exception on status=error"""
     content = json.dumps({'status': 'error', 'desc': 'ERROR', 'code': 3})
     res = Mock(status_code=200, content=content,
                content_type='application/json')
     try:
         parse_response(res)
     except BasketException as e:
         self.assertEqual(3, e.code)
     else:
         self.fail("parse_response should have raised BasketException")
示例#5
0
 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")
示例#6
0
 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")
示例#7
0
 def test_response_no_content_type(self):
     """parse_response() doesn't fail if the response is missing a content type"""
     #(probably only an issue in testing, but still...)
     data = {u'status': u'ok', u'foo': u'bar'}
     content = json.dumps(data)
     res = Mock(status_code=200, content=content)
     result = parse_response(res)
     self.assertEqual(data, result)
示例#8
0
 def test_response_content(self):
     """parse_response() returns parsed response content if no error"""
     data = {u'status': u'ok', u'foo': u'bar'}
     content = json.dumps(data)
     res = Mock(status_code=200, content=content,
                content_type='application/json')
     result = parse_response(res)
     self.assertEqual(data, result)
示例#9
0
 def test_response_no_content_type(self):
     """parse_response() doesn't fail if the response is missing a content type"""
     # probably only an issue in testing, but still...
     data = {u'status': u'ok', u'foo': u'bar'}
     content = json.dumps(data)
     res = Mock(status_code=200, content=content)
     result = parse_response(res)
     self.assertEqual(data, result)
示例#10
0
 def test_response_content(self):
     """parse_response() returns parsed response content if no error"""
     data = {u'status': u'ok', u'foo': u'bar'}
     content = json.dumps(data)
     res = Mock(status_code=200, content=content,
                content_type='application/json')
     result = parse_response(res)
     self.assertEqual(data, result)