@@ -45,7 +45,10 @@ def test_receive_non_json_response(self, session_mock):
4545
4646 session_mock .return_value = mock .MagicMock (
4747 status_code = 404 ,
48- content = data
48+ content = data ,
49+ headers = {
50+ "Content-Type" : "application/json"
51+ }
4952 )
5053
5154 with self .assertRaises (HyperwalletAPIException ) as exc :
@@ -70,7 +73,10 @@ def test_receive_valid_json_error_response(self, session_mock):
7073
7174 session_mock .return_value = mock .MagicMock (
7275 status_code = 400 ,
73- content = json .dumps (data )
76+ content = json .dumps (data ),
77+ headers = {
78+ "Content-Type" : "application/json"
79+ }
7480 )
7581
7682 with self .assertRaises (HyperwalletAPIException ) as exc :
@@ -100,7 +106,10 @@ def test_receive_valid_json_response(self, session_mock):
100106
101107 session_mock .return_value = mock .MagicMock (
102108 status_code = 200 ,
103- content = json .dumps (data )
109+ content = json .dumps (data ),
110+ headers = {
111+ "Content-Type" : "application/json"
112+ }
104113 )
105114
106115 encoded = json .dumps (data )
@@ -112,6 +121,29 @@ def test_receive_valid_json_response(self, session_mock):
112121 json .loads (encoded )
113122 )
114123
124+ @mock .patch ('requests.Session.request' )
125+ def test_receive_json_error_response_when_content_type_is_not_valid (self , session_mock ):
126+
127+ data = {
128+ 'key' : 'value'
129+ }
130+
131+ session_mock .return_value = mock .MagicMock (
132+ status_code = 200 ,
133+ content = json .dumps (data ),
134+ headers = {
135+ "Content-Type" : "wrongContentType"
136+ }
137+ )
138+
139+ with self .assertRaises (HyperwalletAPIException ) as exc :
140+ self .client ._makeRequest ()
141+
142+ self .assertEqual (
143+ exc .exception .message ,
144+ 'Invalid Content-Type specified in Response Header'
145+ )
146+
115147
116148if __name__ == '__main__' :
117149 unittest .main ()
0 commit comments