Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Aug 24, 2023
1 parent 70c2bc1 commit df477be
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"credit_requirements": "This image is published under <a href=\"https://creativecommons.org/licenses/by/4.0/deed.en\" target=\"_blank\">CC BY 4.0 licence</a>.<br />Free for commercial use. Attribution required.<br />Please, credit: &copy; Justtakeitfree Free Photos (CC BY 4.0)<br />An active hyperlink to the page should be provided.",
"credit_text": "&copy; 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 <a href=\"https://creativecommons.org/licenses/by/4.0/deed.en\" target=\"_blank\">CC BY 4.0 licence</a>.<br />Free for commercial use. Attribution required.<br />Please, credit: &copy; Justtakeitfree Free Photos (CC BY 4.0)<br />An active hyperlink to the page should be provided.",
"credit_text": "&copy; 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"]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = {
Expand All @@ -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/",
Expand All @@ -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

0 comments on commit df477be

Please sign in to comment.