diff --git a/catalog/tests/dags/providers/provider_api_scripts/resources/justtakeitfree/single_item.json b/catalog/tests/dags/providers/provider_api_scripts/resources/justtakeitfree/single_item.json index 45fb44ebd8e..acf3294abb4 100644 --- a/catalog/tests/dags/providers/provider_api_scripts/resources/justtakeitfree/single_item.json +++ b/catalog/tests/dags/providers/provider_api_scripts/resources/justtakeitfree/single_item.json @@ -1,10 +1,12 @@ -{ - "credit_requirements": "This image is published under CC BY 4.0 licence.
Free for commercial use. Attribution required.
Please, credit: © Justtakeitfree Free Photos (CC BY 4.0)
An active hyperlink to the page should be provided.", - "credit_text": "© Justtakeitfree Free Photos (CC BY 4.0)", - "full_image_link": "https://justtakeitfree.com/photos/2.jpg", - "license": "(CC BY 4.0)", - "license_link": "https://creativecommons.org/licenses/by/4.0/deed.en", - "page_link": "https://justtakeitfree.com/photo/2/", - "preview_link": "https://justtakeitfree.com/photos/2_800.jpg", - "tags": ["Baturyn fortress", "Baturyn citadel", "cossack fortress"] -} +[ + { + "credit_requirements": "This image is published under CC BY 4.0 licence.
Free for commercial use. Attribution required.
Please, credit: © Justtakeitfree Free Photos (CC BY 4.0)
An active hyperlink to the page should be provided.", + "credit_text": "© Justtakeitfree Free Photos (CC BY 4.0)", + "full_image_link": "https://justtakeitfree.com/photos/2.jpg", + "license": "(CC BY 4.0)", + "license_link": "https://creativecommons.org/licenses/by/4.0/deed.en", + "page_link": "https://justtakeitfree.com/photo/2/", + "preview_link": "https://justtakeitfree.com/photos/2_800.jpg", + "tags": ["Baturyn fortress", "Baturyn citadel", "cossack fortress"] + } +] diff --git a/catalog/tests/dags/providers/provider_api_scripts/test_justtakeitfree.py b/catalog/tests/dags/providers/provider_api_scripts/test_justtakeitfree.py index b084ca836d5..c875c6fe296 100644 --- a/catalog/tests/dags/providers/provider_api_scripts/test_justtakeitfree.py +++ b/catalog/tests/dags/providers/provider_api_scripts/test_justtakeitfree.py @@ -8,23 +8,28 @@ import json from pathlib import Path +from unittest.mock import patch from common.licenses import get_license_info from providers.provider_api_scripts.justtakeitfree import JusttakeitfreeDataIngester -# TODO: API responses used for testing can be added to this directory RESOURCES = Path(__file__).parent / "resources/justtakeitfree" # Set up test class -ingester = JusttakeitfreeDataIngester() +jtif = JusttakeitfreeDataIngester() + + +class FileSizeHeadResponse: + def __init__(self, size): + self.headers = {"Content-Length": size} def test_get_next_query_params_default_response(): - actual_result = ingester.get_next_query_params(None) + actual_result = jtif.get_next_query_params(None) actual_result.pop("key", None) expected_result = { - "page": 0, + "page": 1, } assert actual_result == expected_result @@ -33,7 +38,7 @@ def test_get_next_query_params_updates_parameters(): previous_query_params = { "page": 1, } - actual_result = ingester.get_next_query_params(previous_query_params) + actual_result = jtif.get_next_query_params(previous_query_params) actual_result.pop("key", None) expected_result = { @@ -46,7 +51,10 @@ def test_get_record_data(): with open(RESOURCES / "single_item.json") as f: resource_json = json.load(f) - actual_data = ingester.get_record_data(resource_json) + with patch.object(jtif.delayed_requester, "head") as head_patch: + # Returns None when 404 + head_patch.return_value = FileSizeHeadResponse(100) + actual_data = jtif.get_record_data(resource_json) expected_data = { "foreign_landing_url": "https://justtakeitfree.com/photo/2/", @@ -55,9 +63,10 @@ def test_get_record_data(): "creator": "Justtakeitfree Free Photos", "creator_url": "https://justtakeitfree.com", "license_info": get_license_info( - "https://creativecommons.org/licenses/by/4.0/deed.en" + "https://creativecommons.org/licenses/by/4.0/" ), "raw_tags": ["Baturyn fortress", "Baturyn citadel", "cossack fortress"], + "filesize": 100, } assert actual_data == expected_data