from unittest import mock import pytest from owsclient import OwsClient from pytest_mock import MockerFixture from src.ows_video import get_video_assets_for_products def test_get_video_assets_for_products(mocker: MockerFixture) -> None: mock_ows_client = mocker.patch( "src.ows_clients.ows_client", side_effect=["get"], ) product_ids = {1, 2, 345} asset_types = {"VIDEO_MASTER", "H264_HD"} get_video_assets_for_products(mock_ows_client, product_ids, asset_types) product_ids_string = ",".join(list(map(str, product_ids))) asset_types_string = ",".join(list(asset_types)) assert mock_ows_client.get.call_count == 1 assert mock_ows_client.mock_calls == [ mock.call.get( "ows-video", f"/assets-bulk?product_ids={product_ids_string}&asset_types={asset_types_string}", ), ] @mock.patch("src.ows_clients.ows_client") def test_get_assets_for_products_exception(mock_ows_client: OwsClient) -> None: with mock.patch("src.ows_clients.ows_client.get") as mock_get: product_ids = {123, 567, 8910} asset_types = {"test", "testy"} mock_get.side_effect = Exception("Request failed") with pytest.raises(Exception) as exc: get_video_assets_for_products(mock_ows_client, product_ids, asset_types) assert str(exc.value) == "Request failed"