Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
Remove _get_meta_data function
Browse files Browse the repository at this point in the history
  • Loading branch information
AetherUnbound committed Oct 21, 2022
1 parent 28b3a78 commit d823ec2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
64 changes: 30 additions & 34 deletions openverse_catalog/dags/providers/provider_api_scripts/phylopic.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,39 +184,6 @@ def _get_creator_details(result: dict) -> tuple[str | None, str | None, str | No

return creator, credit_line, pub_date

@staticmethod
def _get_meta_data(result: dict) -> dict | None:
meta_data = {}
uid = result.get("uid")
license_url = result.get("licenseURL")

img_url, width, height = PhylopicDataIngester._get_image_info(result, uid)

if img_url is None:
return None

meta_data["taxa"], title = PhylopicDataIngester._get_taxa_details(result)

foreign_url = PhylopicDataIngester._image_url(uid)

(
creator,
meta_data["credit_line"],
meta_data["pub_date"],
) = PhylopicDataIngester._get_creator_details(result)

return {
"foreign_identifier": uid,
"foreign_landing_url": foreign_url,
"image_url": img_url,
"license_info": get_license_info(license_url=license_url),
"width": width,
"height": height,
"creator": creator,
"title": title,
"meta_data": meta_data,
}

def get_record_data(self, data: dict) -> dict | list[dict] | None:
uid = data.get("uid")
if not uid:
Expand Down Expand Up @@ -244,7 +211,36 @@ def get_record_data(self, data: dict) -> dict | list[dict] | None:
if not result:
return None

return self._get_meta_data(result)
meta_data = {}
uid = result.get("uid")
license_url = result.get("licenseURL")

img_url, width, height = self._get_image_info(result, uid)

if img_url is None:
return None

meta_data["taxa"], title = self._get_taxa_details(result)

foreign_url = self._image_url(uid)

(
creator,
meta_data["credit_line"],
meta_data["pub_date"],
) = self._get_creator_details(result)

return {
"foreign_identifier": uid,
"foreign_landing_url": foreign_url,
"image_url": img_url,
"license_info": get_license_info(license_url=license_url),
"width": width,
"height": height,
"creator": creator,
"title": title,
"meta_data": meta_data,
}


def main(date_start: str = None, process_days: int = None):
Expand Down
13 changes: 7 additions & 6 deletions tests/dags/providers/provider_api_scripts/test_phylopic.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ def test_get_batch_data():
assert actual_img_ids == expect_img_ids


def test_get_meta_data_with_no_img_url():
r = get_json("no_image_url_example.json")
meta_data = pp._get_meta_data(r["result"])
assert meta_data is None


def test_get_creator_details(image_data):
result = image_data["result"]
actual_creator_details = pp._get_creator_details(result)
Expand Down Expand Up @@ -178,6 +172,13 @@ def test_get_record_data_no_data():
assert actual is None


def test_get_record_data_with_no_img_url():
r = get_json("no_image_url_example.json")
with patch.object(pp, "get_response_json", return_value=r):
actual = pp.get_record_data({"uid": r["result"]["uid"]})
assert actual is None


def test_get_image_info(image_data):
result = image_data["result"]
actual_img_info = pp._get_image_info(result, "e9df48fe-68ea-419e-b9df-441e0b208335")
Expand Down

0 comments on commit d823ec2

Please sign in to comment.