@@ -140,6 +140,9 @@ def test_handle_query_invalid_query(self):
140140 self .assertEqual (resp ["status_code" ], - 1 )
141141
142142 def test_handle_query_invalid_response (self ):
143+ # Check that the API key is defined (troubleshooting failures)
144+ self .assertIsInstance (self .api ._api_key , str )
145+ self .assertGreater (len (self .api ._api_key ), 0 )
143146 resp = self .api .handle_query (api = "short" ,
144147 query = "i like" ,
145148 units = "metric" ,
@@ -154,14 +157,19 @@ def test_handle_query_invalid_key(self):
154157
155158 resp = self .api .handle_query (query = "how far away is mars" )
156159 self .assertIsInstance (resp , dict )
157- self .assertEqual (resp ["status_code" ], 403 )
160+ # Response code should indicate a 4xx error for a bad request
161+ self .assertGreaterEqual (resp ["status_code" ], 400 )
162+ self .assertLess (resp ["status_code" ], 500 )
158163 self .assertIsInstance (resp ["content" ], bytes )
159164 self .assertIsInstance (resp ["encoding" ], str )
160165 self .assertIsInstance (resp ["content" ].decode (resp ["encoding" ]), str )
161166
162167 self .api ._api_key = valid_key
163168
164169 def test_handle_query_valid_ip (self ):
170+ # Check that the API key is defined (troubleshooting failures)
171+ self .assertIsInstance (self .api ._api_key , str )
172+ self .assertGreater (len (self .api ._api_key ), 0 )
165173 resp = self .api .handle_query (api = "short" ,
166174 query = "how far away is the moon?" ,
167175 units = "metric" ,
@@ -178,6 +186,9 @@ def test_handle_query_valid_ip(self):
178186 self .assertEqual (resp , cached )
179187
180188 def test_handle_query_valid_lat_lng (self ):
189+ # Check that the API key is defined (troubleshooting failures)
190+ self .assertIsInstance (self .api ._api_key , str )
191+ self .assertGreater (len (self .api ._api_key ), 0 )
181192 resp = self .api .handle_query (api = "short" ,
182193 query = "how far away is the moon?" ,
183194 units = "metric" ,
@@ -190,6 +201,9 @@ def test_handle_query_valid_lat_lng(self):
190201 self .assertIsInstance (resp ["content" ].decode (resp ["encoding" ]), str )
191202
192203 def test_handle_query_valid_latlong (self ):
204+ # Check that the API key is defined (troubleshooting failures)
205+ self .assertIsInstance (self .api ._api_key , str )
206+ self .assertGreater (len (self .api ._api_key ), 0 )
193207 resp = self .api .handle_query (api = "short" ,
194208 query = "how far away is the moon?" ,
195209 units = "metric" ,
0 commit comments