1515
1616import ubersmith_client
1717from mock import Mock , patch
18-
19- from hamcrest import assert_that , raises , calling
18+ from hamcrest import assert_that , raises , calling , equal_to
2019from requests .exceptions import ConnectionError , Timeout
21-
22- from ubersmith_client . exceptions import UbersmithException , BadRequest , UnknownError , Forbidden , NotFound , Unauthorized , UbersmithConnectionError , \
20+ from ubersmith_client . exceptions import UbersmithException , BadRequest , UnknownError , Forbidden , NotFound , Unauthorized , \
21+ UbersmithConnectionError , \
2322 UbersmithTimeout
2423from tests .ubersmith_json .response_data_structure import a_response_data
2524from ubersmith_client .ubersmith_request import UbersmithRequest
@@ -32,8 +31,8 @@ def setUp(self):
3231 self .password = 'test'
3332
3433 def test_process_ubersmith_response (self ):
35- response = Mock ()
36- response . status_code = 200
34+ response = Mock (status_code = 200 , headers = { 'content-type' : 'application/json' } )
35+
3736 json_data = {
3837 'client_id' : '1' ,
3938 'first' : 'Rick' ,
@@ -45,9 +44,12 @@ def test_process_ubersmith_response(self):
4544
4645 self .assertDictEqual (json_data , UbersmithRequest .process_ubersmith_response (response ))
4746
47+ def test_process_ubersmith_response_not_application_json (self ):
48+ response = Mock (status_code = 200 , headers = {'content-type' : 'text/html' }, content = '42' )
49+ assert_that (response .content , equal_to (UbersmithRequest .process_ubersmith_response (response )))
50+
4851 def test_process_ubersmith_response_raise_exception (self ):
49- response = Mock ()
50- response .status_code = 400
52+ response = Mock (status_code = 400 , headers = {'content-type' : 'application/json' })
5153 assert_that (calling (UbersmithRequest .process_ubersmith_response ).with_args (response ), raises (BadRequest ))
5254
5355 response .status_code = 401
@@ -65,7 +67,7 @@ def test_process_ubersmith_response_raise_exception(self):
6567 response .status_code = 200
6668 response .json = Mock (return_value = {'status' : False , 'error_code' : 42 , 'error_message' : 'come and watch tv' })
6769 assert_that (calling (UbersmithRequest .process_ubersmith_response ).with_args (response ),
68- raises (UbersmithException , " Error code 42 - message: come and watch tv" ))
70+ raises (UbersmithException , ' Error code 42 - message: come and watch tv' ))
6971
7072 @patch ('ubersmith_client.ubersmith_request_post.requests' )
7173 def test_api_method_returns_handle_connection_error_exception (self , requests_mock ):
0 commit comments