Skip to content

Commit 35372ad

Browse files
committed
feat: add asset scanning unit tests for _asset_scan_status param and api_version header
1 parent f5be3cb commit 35372ad

1 file changed

Lines changed: 78 additions & 1 deletion

File tree

tests/unit/assets/test_assets_unit.py

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,81 @@ def test_delete_folder(self):
253253
response = self.client.stack(api_key).assets().delete_folder(folder_uid)
254254
self.assertEqual(response.request.url, f"{self.client.endpoint}assets/folders/{folder_uid}")
255255
self.assertEqual(response.request.method, "DELETE")
256-
self.assertEqual(response.request.headers["Content-Type"], "application/json")
256+
self.assertEqual(response.request.headers["Content-Type"], "application/json")
257+
258+
# Asset scanning tests — _asset_scan_status param and api_version header
259+
260+
def test_fetch_includes_scan_status_param(self):
261+
asset = self.client.stack(api_key).assets(asset_uid)
262+
asset.add_param("_asset_scan_status", True)
263+
response = asset.fetch()
264+
self.assertIn("_asset_scan_status=True", response.request.url)
265+
self.assertEqual(response.request.method, "GET")
266+
267+
def test_find_includes_scan_status_param(self):
268+
asset = self.client.stack(api_key).assets()
269+
asset.add_param("_asset_scan_status", True)
270+
response = asset.find()
271+
self.assertIn("_asset_scan_status=True", response.request.url)
272+
self.assertEqual(response.request.method, "GET")
273+
274+
def test_upload_includes_scan_status_param(self):
275+
file_path = "tests/resources/mock_assets/chaat.jpeg"
276+
asset = self.client.stack(api_key).assets()
277+
asset.add_param("_asset_scan_status", True)
278+
response = asset.upload(file_path)
279+
self.assertIn("_asset_scan_status=True", response.request.url)
280+
self.assertEqual(response.request.method, "POST")
281+
282+
def test_fetch_without_scan_status_param_field_absent(self):
283+
response = self.client.stack(api_key).assets(asset_uid).fetch()
284+
self.assertNotIn("_asset_scan_status", response.request.url)
285+
self.assertEqual(response.request.method, "GET")
286+
287+
def test_find_without_scan_status_param_field_absent(self):
288+
response = self.client.stack(api_key).assets().find()
289+
self.assertNotIn("_asset_scan_status", response.request.url)
290+
self.assertEqual(response.request.method, "GET")
291+
292+
def test_upload_without_scan_status_param_field_absent(self):
293+
file_path = "tests/resources/mock_assets/chaat.jpeg"
294+
response = self.client.stack(api_key).assets().upload(file_path)
295+
self.assertNotIn("_asset_scan_status", response.request.url)
296+
self.assertEqual(response.request.method, "POST")
297+
298+
def test_scan_status_param_coexists_with_other_params(self):
299+
asset = self.client.stack(api_key).assets(asset_uid)
300+
asset.add_param("locale", "en-us")
301+
asset.add_param("_asset_scan_status", True)
302+
response = asset.fetch()
303+
self.assertIn("locale=en-us", response.request.url)
304+
self.assertIn("_asset_scan_status=True", response.request.url)
305+
self.assertEqual(response.request.method, "GET")
306+
307+
def test_publish_includes_api_version_header(self):
308+
data = {
309+
"asset": {
310+
"locales": ["en-us"],
311+
"environments": ["development"]
312+
},
313+
"version": 1,
314+
"scheduled_at": "2019-02-08T18:30:00.000Z"
315+
}
316+
asset = self.client.stack(api_key).assets(asset_uid)
317+
asset.add_header("api_version", "3.2")
318+
response = asset.publish(data)
319+
self.assertEqual(response.request.headers.get("api_version"), "3.2")
320+
self.assertEqual(response.request.method, "POST")
321+
322+
def test_api_version_header_scoped_to_publish(self):
323+
data = {
324+
"asset": {
325+
"locales": ["en-us"],
326+
"environments": ["development"]
327+
},
328+
"version": 1,
329+
"scheduled_at": "2019-02-08T18:30:00.000Z"
330+
}
331+
response = self.client.stack(api_key).assets(asset_uid).publish(data)
332+
self.assertIsNone(response.request.headers.get("api_version"))
333+
self.assertEqual(response.request.method, "POST")

0 commit comments

Comments
 (0)