from unittest.mock import MagicMock import pytest from fastapi.testclient import TestClient from pytest_mock import MockerFixture from syrupy.assertion import SnapshotAssertion from delivery_metadata.clients.ows_assets import get_product_assets @pytest.mark.asyncio async def test_get_product_assets( mocker: MockerFixture, test_client: TestClient, snapshot: SnapshotAssertion ) -> None: product_id = 12345 response_mock = MagicMock() response_mock.json = mocker.Mock( return_value=[ { "tuid": 123, "product_id": product_id, "asset_type": "WAV", "s3_bucket": "test-bucket", "s3_key": "test-key", "duration": 334213412, "updated_timestamp": "2023-04-23 16:37:52", "updated_timestamp_us_east": "2023-04-23 12:37:52", }, { "tuid": 0, "product_id": product_id, "asset_type": "TIF", "s3_bucket": "test-bucket", "s3_key": "test-key", "duration": None, "updated_timestamp": "2023-04-23 16:37:52", "updated_timestamp_us_east": "2023-04-23 12:37:52", }, { "tuid": 123, "product_id": product_id, "asset_type": "atmos", "s3_bucket": "test-bucket", "s3_key": "test-key", "duration": 334213423, "updated_timestamp": "2023-04-23 16:37:52", "updated_timestamp_us_east": "2023-04-23 12:37:52", }, ] ) get_mock = mocker.patch.object( test_client.app.state.ows_connector, # type: ignore[attr-defined] "get", return_value=response_mock, autospec=True, ) result = await get_product_assets(product_id) get_mock.assert_called_once_with( service_name="ows-assets", path=f"/product/{product_id}/assets", ) response_mock.raise_for_status.assert_called_once() assert result == snapshot