@@ -22,7 +22,7 @@ def load_json(json_file: str) -> Any:
2222
2323class TestStarmapClient (TestCase ):
2424 @pytest .fixture (autouse = True )
25- def inject_fixtures (self , caplog : LogCaptureFixture ):
25+ def inject_fixtures (self , caplog : LogCaptureFixture ) -> None :
2626 self ._caplog = caplog
2727
2828 def setUp (self ) -> None :
@@ -40,12 +40,14 @@ def setUp(self) -> None:
4040 self .mock_resp_success .status_code = 200
4141 self .mock_resp_not_found = mock .MagicMock ()
4242 self .mock_resp_not_found .status_code = 404
43- self .mock_resp_not_found .raise_for_status .side_effect = HTTPError ("Not found" ) # type: ignore # noqa: E501
43+ self .mock_resp_not_found .raise_for_status .side_effect = HTTPError (
44+ "Not found" , response = self .mock_resp_not_found
45+ )
4446
45- def tearDown (self ):
47+ def tearDown (self ) -> None :
4648 mock .patch .stopall ()
4749
48- def test_query_image_success_APIv2 (self ):
50+ def test_query_image_success_APIv2 (self ) -> None :
4951 fpath = "tests/data/query_v2/query_response_container/valid_qrc1.json"
5052 self .mock_resp_success .json .return_value = load_json (fpath )
5153 self .mock_session_v2 .get .return_value = self .mock_resp_success
@@ -56,19 +58,20 @@ def test_query_image_success_APIv2(self):
5658 self .mock_session_v2 .get .assert_called_once_with ("/query" , params = expected_params )
5759 self .mock_resp_success .raise_for_status .assert_called_once ()
5860 # Note: JSON need to be loaded twice as `from_json` pops its original data
59- self . assertEqual ( res , QueryResponseContainer .from_json (load_json (fpath ) ))
61+ assert res == QueryResponseContainer .from_json (load_json (fpath ))
6062
61- def test_in_memory_query_image_APIv2 (self ):
63+ def test_in_memory_query_image_APIv2 (self ) -> None :
6264 fpath = "tests/data/query_v2/query_response_container/valid_qrc1.json"
6365 data = QueryResponseContainer .from_json (load_json (fpath ))
6466 provider = InMemoryMapProviderV2 (data )
6567
6668 self .svc_v2 = StarmapClient ("https://test.starmap.com" , api_version = "v2" , provider = provider )
6769
6870 res = self .svc_v2 .query_image ("product-test-1.0-1.raw.xz" , workflow = "stratosphere" )
69- self .assertEqual (res .responses , [data .responses [0 ]])
71+ assert res
72+ assert res .responses == [data .responses [0 ]]
7073
71- def test_in_memory_api_mismatch (self ):
74+ def test_in_memory_api_mismatch (self ) -> None :
7275 fpath = "tests/data/query_v2/query_response_container/valid_qrc1.json"
7376 data = QueryResponseContainer .from_json (load_json (fpath ))
7477 provider_v2 = InMemoryMapProviderV2 (data )
@@ -77,7 +80,7 @@ def test_in_memory_api_mismatch(self):
7780 with pytest .raises (ValueError , match = err ):
7881 StarmapClient ("foo" , api_version = "v1" , provider = provider_v2 )
7982
80- def test_query_image_not_found (self ):
83+ def test_query_image_not_found (self ) -> None :
8184 self .mock_session_v2 .get .return_value = self .mock_resp_not_found
8285 self .mock_session_v2 .get .return_value = self .mock_resp_not_found
8386
@@ -86,9 +89,9 @@ def test_query_image_not_found(self):
8689 res = svc .query_image (self .image )
8790 expected_msg = "Marketplace mappings not defined for {'image': '%s'}" % self .image
8891 assert expected_msg in self ._caplog .text
89- self . assertIsNone ( res )
92+ assert res is None
9093
91- def test_query_image_by_name_APIv2 (self ):
94+ def test_query_image_by_name_APIv2 (self ) -> None :
9295 fpath = "tests/data/query_v2/query_response_container/valid_qrc1.json"
9396 self .mock_resp_success .json .return_value = load_json (fpath )
9497 self .mock_session_v2 .get .return_value = self .mock_resp_success
@@ -99,20 +102,21 @@ def test_query_image_by_name_APIv2(self):
99102 self .mock_session_v2 .get .assert_called_once_with ("/query" , params = expected_params )
100103 self .mock_resp_success .raise_for_status .assert_called_once ()
101104 # Note: JSON need to be loaded twice as `from_json` pops its original data
102- self . assertEqual ( res , QueryResponseContainer .from_json (load_json (fpath ) ))
105+ assert res == QueryResponseContainer .from_json (load_json (fpath ))
103106
104- def test_in_memory_query_image_by_name_APIv2 (self ):
107+ def test_in_memory_query_image_by_name_APIv2 (self ) -> None :
105108 fpath = "tests/data/query_v2/query_response_container/valid_qrc1.json"
106109 data = QueryResponseContainer .from_json (load_json (fpath ))
107110 provider = InMemoryMapProviderV2 (data )
108111
109112 self .svc_v2 = StarmapClient ("https://test.starmap.com" , api_version = "v2" , provider = provider )
110113
111114 res = self .svc_v2 .query_image_by_name (name = "product-test" , workflow = "stratosphere" )
115+ assert res
112116 self .mock_session_v2 .get .assert_not_called ()
113- self . assertEqual ( res .responses , [data .responses [0 ]])
117+ assert res .responses == [data .responses [0 ]]
114118
115- def test_query_image_by_name_version_APIv2 (self ):
119+ def test_query_image_by_name_version_APIv2 (self ) -> None :
116120 fpath = "tests/data/query_v2/query_response_container/valid_qrc1.json"
117121 self .mock_resp_success .json .return_value = load_json (fpath )
118122 self .mock_session_v2 .get .return_value = self .mock_resp_success
@@ -126,9 +130,9 @@ def test_query_image_by_name_version_APIv2(self):
126130 self .mock_session_v2 .get .assert_called_once_with ("/query" , params = expected_params )
127131 self .mock_resp_success .raise_for_status .assert_called_once ()
128132 # Note: JSON need to be loaded twice as `from_json` pops its original data
129- self . assertEqual ( res , QueryResponseContainer .from_json (load_json (fpath ) ))
133+ assert res == QueryResponseContainer .from_json (load_json (fpath ))
130134
131- def test_policies_single_page (self ):
135+ def test_policies_single_page (self ) -> None :
132136 fpath = "tests/data/policy/valid_pol1.json"
133137 single_page = {
134138 "items" : [load_json (fpath )],
@@ -150,14 +154,14 @@ def test_policies_single_page(self):
150154 # Iterate over all policies from StarmapClient property and
151155 # ensure each of them has a valid format.
152156 for p in self .svc_v2 .policies :
153- self . assertEqual ( p , Policy .from_json (load_json (fpath ) ))
157+ assert p == Policy .from_json (load_json (fpath ))
154158
155159 expected_params = {"page" : 1 , "per_page" : 1 }
156160 self .mock_session_v2 .get .assert_called_once_with ("policy" , params = expected_params )
157161 self .mock_session_v2 .get .call_count == 1
158162 self .mock_resp_success .raise_for_status .assert_called_once ()
159163
160- def test_policies_multi_page (self ):
164+ def test_policies_multi_page (self ) -> None :
161165 fpath = "tests/data/policy/valid_pol1.json"
162166 page1 = {
163167 "items" : [load_json (fpath )],
@@ -173,16 +177,16 @@ def test_policies_multi_page(self):
173177 },
174178 }
175179 page2 = deepcopy (page1 )
176- page2 ["nav" ]["next" ] = None
177- page2 ["nav" ]["page" ] = 2
180+ page2 ["nav" ]["next" ] = None # type: ignore[index]
181+ page2 ["nav" ]["page" ] = 2 # type: ignore[index]
178182 self .svc_v2 .POLICIES_PER_PAGE = 1
179183 self .mock_resp_success .json .side_effect = [page1 , page2 ]
180184 self .mock_session_v2 .get .return_value = self .mock_resp_success
181185
182186 # Iterate over all policies from StarmapClient property and
183187 # ensure each of them has a valid format.
184188 for p in self .svc_v2 .policies :
185- self . assertEqual ( p , Policy .from_json (load_json (fpath ) ))
189+ assert p == Policy .from_json (load_json (fpath ))
186190
187191 get_calls = [
188192 mock .call ("policy" , params = {"page" : 1 , "per_page" : 1 }),
@@ -196,7 +200,7 @@ def test_policies_multi_page(self):
196200 self .mock_session_v2 .get .call_count == 2
197201 self .mock_resp_success .raise_for_status .call_count == 2
198202
199- def test_policies_not_found (self ):
203+ def test_policies_not_found (self ) -> None :
200204 self .svc_v2 .POLICIES_PER_PAGE = 1
201205 self .mock_session_v2 .get .return_value = self .mock_resp_not_found
202206
@@ -206,7 +210,7 @@ def test_policies_not_found(self):
206210 assert "No policies registered in StArMap." in self ._caplog .text
207211
208212 @mock .patch ('starmap_client.StarmapClient.policies' )
209- def test_list_policies (self , mock_policies : mock .MagicMock ):
213+ def test_list_policies (self , mock_policies : mock .MagicMock ) -> None :
210214 fpath = "tests/data/policy/valid_pol1.json"
211215 pol = Policy .from_json (load_json (fpath ))
212216 pol_list = [pol ]
@@ -216,15 +220,15 @@ def test_list_policies(self, mock_policies: mock.MagicMock):
216220 self .svc_v2 ._policies = pol_list
217221 res = self .svc_v2 .list_policies ()
218222 mock_policies .__iter__ .assert_not_called ()
219- self . assertEqual ( res , self .svc_v2 ._policies )
223+ assert res == self .svc_v2 ._policies
220224
221225 # Test uncached policies list
222226 self .svc_v2 ._policies = []
223227 res = self .svc_v2 .list_policies ()
224228 mock_policies .__iter__ .assert_called_once ()
225- self . assertEqual ( res , pol_list )
229+ assert res == pol_list
226230
227- def test_get_policy (self ):
231+ def test_get_policy (self ) -> None :
228232 fpath = "tests/data/policy/valid_pol1.json"
229233 self .mock_resp_success .json .return_value = load_json (fpath )
230234 self .mock_session_v2 .get .return_value = self .mock_resp_success
@@ -234,9 +238,9 @@ def test_get_policy(self):
234238 self .mock_session_v2 .get .assert_called_once_with ("/policy/policy-id" )
235239 self .mock_resp_success .raise_for_status .assert_called_once ()
236240 # Note: JSON need to be loaded twice as `from_json` pops its original data
237- self . assertEqual ( res , Policy .from_json (load_json (fpath ) ))
241+ assert res == Policy .from_json (load_json (fpath ))
238242
239- def test_get_policy_not_found (self ):
243+ def test_get_policy_not_found (self ) -> None :
240244 self .mock_session_v2 .get .return_value = self .mock_resp_not_found
241245
242246 with self ._caplog .at_level (logging .ERROR ):
@@ -245,7 +249,7 @@ def test_get_policy_not_found(self):
245249 expected_msg = "Policy not found with ID = \" policy-id\" "
246250 assert expected_msg in self ._caplog .text
247251
248- self . assertIsNone ( res )
252+ assert res is None
249253
250254 @mock .patch ("starmap_client.StarmapClient.get_policy" )
251255 def test_list_mappings (self , mock_get_policy : mock .MagicMock ) -> None :
@@ -256,7 +260,7 @@ def test_list_mappings(self, mock_get_policy: mock.MagicMock) -> None:
256260 res = self .svc_v2 .list_mappings (policy_id = "policy-id" )
257261
258262 mock_get_policy .assert_called_once_with ("policy-id" )
259- self . assertEqual ( res , p .mappings )
263+ assert res == p .mappings
260264
261265 @mock .patch ("starmap_client.StarmapClient.get_policy" )
262266 def test_list_mappings_not_found (self , mock_get_policy : mock .MagicMock ) -> None :
@@ -265,9 +269,9 @@ def test_list_mappings_not_found(self, mock_get_policy: mock.MagicMock) -> None:
265269
266270 mock_get_policy .assert_called_once_with ("policy-id" )
267271
268- self . assertEqual ( res , [])
272+ assert res == []
269273
270- def test_get_mapping (self ):
274+ def test_get_mapping (self ) -> None :
271275 fpath = "tests/data/mapping/valid_map1.json"
272276 self .mock_resp_success .json .return_value = load_json (fpath )
273277 self .mock_session_v2 .get .return_value = self .mock_resp_success
@@ -277,9 +281,9 @@ def test_get_mapping(self):
277281 self .mock_session_v2 .get .assert_called_once_with ("/mapping/mapping-id" )
278282 self .mock_resp_success .raise_for_status .assert_called_once ()
279283 # Note: JSON need to be loaded twice as `from_json` pops its original data
280- self . assertEqual ( res , Mapping .from_json (load_json (fpath ) ))
284+ assert res == Mapping .from_json (load_json (fpath ))
281285
282- def test_get_mapping_not_found (self ):
286+ def test_get_mapping_not_found (self ) -> None :
283287 self .mock_session_v2 .get .return_value = self .mock_resp_not_found
284288
285289 with self ._caplog .at_level (logging .ERROR ):
@@ -288,7 +292,7 @@ def test_get_mapping_not_found(self):
288292 expected_msg = "Marketplace Mapping not found with ID = \" mapping-id\" "
289293 assert expected_msg in self ._caplog .text
290294
291- self . assertIsNone ( res )
295+ assert res is None
292296
293297 @mock .patch ("starmap_client.StarmapClient.get_mapping" )
294298 def test_list_destinations (self , mock_get_mapping : mock .MagicMock ) -> None :
@@ -299,7 +303,7 @@ def test_list_destinations(self, mock_get_mapping: mock.MagicMock) -> None:
299303 res = self .svc_v2 .list_destinations (mapping_id = "mapping-id" )
300304
301305 mock_get_mapping .assert_called_once_with ("mapping-id" )
302- self . assertEqual ( res , m .destinations )
306+ assert res == m .destinations
303307
304308 @mock .patch ("starmap_client.StarmapClient.get_mapping" )
305309 def test_list_destinations_not_found (self , mock_get_mapping : mock .MagicMock ) -> None :
@@ -308,9 +312,9 @@ def test_list_destinations_not_found(self, mock_get_mapping: mock.MagicMock) ->
308312
309313 mock_get_mapping .assert_called_once_with ("mapping-id" )
310314
311- self . assertEqual ( res , [])
315+ assert res == []
312316
313- def test_get_destination (self ):
317+ def test_get_destination (self ) -> None :
314318 fpath = "tests/data/destination/valid_dest1.json"
315319 self .mock_resp_success .json .return_value = load_json (fpath )
316320 self .mock_session_v2 .get .return_value = self .mock_resp_success
@@ -320,9 +324,9 @@ def test_get_destination(self):
320324 self .mock_session_v2 .get .assert_called_once_with ("/destination/destination-id" )
321325 self .mock_resp_success .raise_for_status .assert_called_once ()
322326 # Note: JSON need to be loaded twice as `from_json` pops its original data
323- self . assertEqual ( res , Destination .from_json (load_json (fpath ) ))
327+ assert res == Destination .from_json (load_json (fpath ))
324328
325- def test_get_destination_not_found (self ):
329+ def test_get_destination_not_found (self ) -> None :
326330 self .mock_session_v2 .get .return_value = self .mock_resp_not_found
327331
328332 with self ._caplog .at_level (logging .ERROR ):
@@ -331,15 +335,15 @@ def test_get_destination_not_found(self):
331335 expected_msg = "Destination not found with ID = \" destination-id\" "
332336 assert expected_msg in self ._caplog .text
333337
334- self . assertIsNone ( res )
338+ assert res is None
335339
336- def test_client_requires_url_or_session (self ):
340+ def test_client_requires_url_or_session (self ) -> None :
337341 error = "Cannot initialize the client without defining either an \" url\" or \" session\" ."
338342 with pytest .raises (ValueError , match = error ):
339343 StarmapClient ()
340344
341345
342- def test_offline_client ():
346+ def test_offline_client () -> None :
343347 """Ensure the cient can be used offline with a local provider."""
344348 fpath = "tests/data/query_v2/query_response_container/valid_qrc2.json"
345349 qrc = QueryResponseContainer .from_json (load_json (fpath ))
0 commit comments