Skip to content

Commit

Permalink
Add podcast to DocMaps complement section (#143)
Browse files Browse the repository at this point in the history
* updated typings with podcast data

* updated test data and tests with podcast data

* added podcast added to DocMaps

* linting

* fixed old missed regression text for thumnail url change

* fixed the type issue for podcast id and edited test data regardingly

* added regression test for an rp with podcast

* linting

* updated podcast_id typing to int

* removed unnecessary condition
  • Loading branch information
HazalCiplak authored Apr 18, 2024
1 parent ed41a0b commit c4a7273
Show file tree
Hide file tree
Showing 8 changed files with 755 additions and 23 deletions.
677 changes: 677 additions & 0 deletions data/docmaps/regression_test/docmap_by_manuscript_id/86824.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions data/docmaps/regression_test/docmap_by_manuscript_id/88984.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@
"electronicArticleIdentifier": "RP88984",
"complement": [
{
"type": "Collection",
"url":"https://elifesciences.org/collections/8d233d47/meta-research-a-collection-of-articles",
"title": "Meta-Research: A Collection of Articles",
"description": "Edited by Peter A Rodgers",
"thumbnail": "https://iiif.elifesciences.org/journal-cms/collection%2F2018-07%2Fmetadata_-_1_1.jpg"
"type": "Collection",
"url":"https://elifesciences.org/collections/8d233d47/meta-research-a-collection-of-articles",
"title": "Meta-Research: A Collection of Articles",
"description": "Edited by Peter A Rodgers",
"thumbnail": "https://iiif.elifesciences.org/journal-cms/collection%2F2018-07%2Fmetadata_-_1_1.jpg/full/full/0/default.jpg"
}
]
}
Expand Down Expand Up @@ -608,11 +608,11 @@
"electronicArticleIdentifier": "RP88984",
"complement": [
{
"type": "Collection",
"url":"https://elifesciences.org/collections/8d233d47/meta-research-a-collection-of-articles",
"title": "Meta-Research: A Collection of Articles",
"description": "Edited by Peter A Rodgers",
"thumbnail": "https://iiif.elifesciences.org/journal-cms/collection%2F2018-07%2Fmetadata_-_1_1.jpg"
"type": "Collection",
"url":"https://elifesciences.org/collections/8d233d47/meta-research-a-collection-of-articles",
"title": "Meta-Research: A Collection of Articles",
"description": "Edited by Peter A Rodgers",
"thumbnail": "https://iiif.elifesciences.org/journal-cms/collection%2F2018-07%2Fmetadata_-_1_1.jpg/full/full/0/default.jpg"
}
]
}
Expand Down Expand Up @@ -946,11 +946,11 @@
"electronicArticleIdentifier": "RP88984",
"complement": [
{
"type": "Collection",
"url":"https://elifesciences.org/collections/8d233d47/meta-research-a-collection-of-articles",
"title": "Meta-Research: A Collection of Articles",
"description": "Edited by Peter A Rodgers",
"thumbnail": "https://iiif.elifesciences.org/journal-cms/collection%2F2018-07%2Fmetadata_-_1_1.jpg"
"type": "Collection",
"url":"https://elifesciences.org/collections/8d233d47/meta-research-a-collection-of-articles",
"title": "Meta-Research: A Collection of Articles",
"description": "Edited by Peter A Rodgers",
"thumbnail": "https://iiif.elifesciences.org/journal-cms/collection%2F2018-07%2Fmetadata_-_1_1.jpg/full/full/0/default.jpg"
}
]
}
Expand Down
3 changes: 3 additions & 0 deletions data_hub_api/docmaps/v2/api_input_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
'collection_curator_name': Optional[str],
'is_collection_curator_et_al': Optional[bool],
'collection_thumbnail_url': Optional[str],
'podcast_id': Optional[int],
'podcast_title': Optional[str],
'podcast_desc': Optional[str],
}
)

Expand Down
15 changes: 13 additions & 2 deletions data_hub_api/docmaps/v2/codecs/elife_manuscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def get_elife_manuscript_part_of_section_complement(
) -> Optional[Sequence[DocmapPartOfComplement]]:
related_article_dict: Optional[dict] = None
collection_dict: Optional[dict] = None
if related_content and any(related_content.values()):
podcast_dict: Optional[dict] = None
if related_content:
if related_content['manuscript_id']:
related_article_dict = {
'type': related_content['manuscript_type'],
Expand All @@ -128,8 +129,18 @@ def get_elife_manuscript_part_of_section_complement(
),
'thumbnail': related_content['collection_thumbnail_url']
}
if related_content['podcast_id']:
podcast_dict = {
'type': 'Podcast',
'url': (
'https://elifesciences.org/podcast/episode'
+ str(related_content['podcast_id'])
),
'title': related_content['podcast_title'],
'description': related_content['podcast_desc']
}
return remove_key_with_none_value_only(
[related_article_dict, collection_dict]
[related_article_dict, collection_dict, podcast_dict]
) # type: ignore
return None

Expand Down
3 changes: 2 additions & 1 deletion data_hub_api/docmaps/v2/docmap_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
'title': Optional[str],
'description': Optional[str],
'thumbnail': Optional[str]
}
},
total=False
)

DocmapPublishedElifeManuscriptPartOf = TypedDict(
Expand Down
3 changes: 2 additions & 1 deletion tests/regression_tests/docmaps/docmap_manuscript_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# for 88984 hypothesis annotation links to v10 but we decided to use v11 for production process
# and it is also inside a collection:
'88984',
'91729' # have related article
'91729', # have related article
'86824' # have related podcast
]


Expand Down
29 changes: 27 additions & 2 deletions tests/unit_tests/docmaps/v2/codecs/elife_manuscript_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
DOCMAPS_QUERY_RESULT_ITEM_2,
DOCMAPS_QUERY_RESULT_ITEM_WITH_VOR_VERSION,
MANUSCRIPT_VOR_VERSION_1,
PODCAST_DICT_1,
PODCAST_DICT_WITH_NO_VALUE_1,
RELATED_ARTICLE_DICT_1,
RELATED_CONTENT_WITH_NO_VALUE_1,
RELATED_CONTENT_WITH_ALL_VALUE_1,
Expand Down Expand Up @@ -167,11 +169,18 @@ def test_should_populate_complement_if_related_content_for_all_value_is_availabl
'title': 'collection_title_1',
'description': 'Edited by collection_curator_name_1 et al',
'thumbnail': 'collection_thumbnail_url_1'
}, {
'type': 'Podcast',
'url': 'https://elifesciences.org/podcast/episode111',
'title': 'podcast_title_1',
'description': 'podcast_desc_1'
}]

def test_should_populate_complement_if_only_related_article_data_available(self):
result_with_related_content = get_elife_manuscript_part_of_section_complement(
{**RELATED_ARTICLE_DICT_1, **COLLECTIONS_DICT_WITH_NO_VALUE_1}
{**RELATED_ARTICLE_DICT_1,
**COLLECTIONS_DICT_WITH_NO_VALUE_1,
**PODCAST_DICT_WITH_NO_VALUE_1}
)
assert result_with_related_content == [{
'type': 'manuscript_type_1',
Expand All @@ -182,7 +191,9 @@ def test_should_populate_complement_if_only_related_article_data_available(self)

def test_should_populate_complement_if_only_collections_data_available(self):
result_with_related_content = get_elife_manuscript_part_of_section_complement(
{**RELATED_CONTENT_WITH_NO_VALUE_1, **COLLECTIONS_DICT_1}
{**RELATED_CONTENT_WITH_NO_VALUE_1,
**PODCAST_DICT_WITH_NO_VALUE_1,
**COLLECTIONS_DICT_1}
)
assert result_with_related_content == [{
'type': 'Collection',
Expand All @@ -196,9 +207,23 @@ def test_should_populate_complement_if_only_collections_data_available(self):
'thumbnail': 'collection_thumbnail_url_1'
}]

def test_should_populate_complement_if_only_podcast_data_available(self):
result_with_related_content = get_elife_manuscript_part_of_section_complement(
{**RELATED_CONTENT_WITH_NO_VALUE_1,
**COLLECTIONS_DICT_WITH_NO_VALUE_1,
**PODCAST_DICT_1}
)
assert result_with_related_content == [{
'type': 'Podcast',
'url': 'https://elifesciences.org/podcast/episode111',
'title': 'podcast_title_1',
'description': 'podcast_desc_1'
}]

def test_should_populate_complement_collection_description_without_et_al_when_false(self):
result_with_related_content = get_elife_manuscript_part_of_section_complement(
{**RELATED_CONTENT_WITH_NO_VALUE_1,
**PODCAST_DICT_WITH_NO_VALUE_1,
**COLLECTIONS_DICT_1,
'is_collection_curator_et_al': False}
)
Expand Down
18 changes: 16 additions & 2 deletions tests/unit_tests/docmaps/v2/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,28 @@
'is_collection_curator_et_al': True
}

PODCAST_DICT_WITH_NO_VALUE_1: dict = {
'podcast_id': None,
'podcast_title': None,
'podcast_desc': None
}

PODCAST_DICT_1: dict = {
'podcast_id': 111,
'podcast_title': 'podcast_title_1',
'podcast_desc': 'podcast_desc_1'
}

RELATED_CONTENT_WITH_NO_VALUE_1: ApiRelatedContentInput = {
**RELATED_ARTICLE_DICT_WITH_NO_VALUE_1, # type: ignore
**COLLECTIONS_DICT_WITH_NO_VALUE_1 # type: ignore
**COLLECTIONS_DICT_WITH_NO_VALUE_1, # type: ignore
**PODCAST_DICT_WITH_NO_VALUE_1 # type: ignore
}

RELATED_CONTENT_WITH_ALL_VALUE_1: ApiRelatedContentInput = {
**RELATED_ARTICLE_DICT_1, # type: ignore
**COLLECTIONS_DICT_1 # type: ignore
**COLLECTIONS_DICT_1, # type: ignore
**PODCAST_DICT_1 # type: ignore
}

PUBLISHER_DICT_1 = {"id": "publisher_1"}
Expand Down

0 comments on commit c4a7273

Please sign in to comment.