From 6a9a7700a222bc9b72ce3f5c4227287f738bc33d Mon Sep 17 00:00:00 2001 From: Hazal Date: Tue, 23 Apr 2024 14:32:04 +0100 Subject: [PATCH] Support multiple related content on same type (#145) * upgraded pytest * Support multiple related content in same type * converted func to iterable * changed as iterable 'iter_elife_manuscript_part_of_section_complement_for_each_record' * sorted complement output * updated complement type as not optional --- .../docmap_by_manuscript_id/80984.json | 362 ++++++++++ .../docmap_by_manuscript_id/86628.json | 6 +- .../docmap_by_manuscript_id/86873.json | 6 +- .../docmap_by_manuscript_id/87193.json | 6 +- .../docmap_by_manuscript_id/88266.json | 643 ++++++++++++++++++ .../docmap_by_manuscript_id/89891.json | 6 +- .../docmaps/v2/codecs/elife_manuscript.py | 109 +-- data_hub_api/docmaps/v2/docmap_typing.py | 4 +- requirements.dev.txt | 3 +- .../docmaps/docmap_manuscript_test.py | 4 +- .../v2/codecs/elife_manuscript_test.py | 174 ++--- tests/unit_tests/docmaps/v2/test_data.py | 53 +- 12 files changed, 1227 insertions(+), 149 deletions(-) create mode 100644 data/docmaps/regression_test/docmap_by_manuscript_id/80984.json create mode 100644 data/docmaps/regression_test/docmap_by_manuscript_id/88266.json diff --git a/data/docmaps/regression_test/docmap_by_manuscript_id/80984.json b/data/docmaps/regression_test/docmap_by_manuscript_id/80984.json new file mode 100644 index 00000000..65757137 --- /dev/null +++ b/data/docmaps/regression_test/docmap_by_manuscript_id/80984.json @@ -0,0 +1,362 @@ +{ + "@context": "https://w3id.org/docmaps/context.jsonld", + "type": "docmap", + "id": "https://data-hub-api.elifesciences.org/enhanced-preprints/docmaps/v2/by-publisher/elife/get-by-manuscript-id?manuscript_id=80984", + "created": "2022-07-01T05:41:56+00:00", + "updated": "2022-07-01T05:41:56+00:00", + "publisher": { + "account": { + "id": "https://sciety.org/groups/elife", + "service": "https://sciety.org" + }, + "homepage": "https://elifesciences.org/", + "id": "https://elifesciences.org/", + "logo": "https://sciety.org/static/groups/elife--b560187e-f2fb-4ff9-a861-a204f3fc0fb0.png", + "name": "eLife" + }, + "first-step": "_:b0", + "steps": { + "_:b0": { + "actions": [ + { + "participants": [], + "outputs": [ + { + "type": "preprint", + "identifier": "80984", + "doi": "10.7554/eLife.80984.1", + "versionIdentifier": "1", + "license": "http://creativecommons.org/licenses/by/4.0/" + } + ] + } + ], + "assertions": [ + { + "item": { + "type": "preprint", + "doi": "10.1101/2022.06.30.498369", + "versionIdentifier": "1" + }, + "status": "under-review", + "happened": "2022-07-01T05:45:17+00:00" + }, + { + "item": { + "type": "preprint", + "doi": "10.7554/eLife.80984.1", + "versionIdentifier": "1" + }, + "status": "draft" + } + ], + "inputs": [ + { + "type": "preprint", + "doi": "10.1101/2022.06.30.498369", + "url": "https://www.biorxiv.org/content/10.1101/2022.06.30.498369v1", + "versionIdentifier": "1", + "published": "2022-07-02", + "content": [ + { + "type": "computer-file", + "url": "s3://transfers-elife/biorxiv_Current_Content/July_2022/03_Jul_22_Batch_1301/48c60452-6c66-1014-adf9-c7b61873ecd3.meca" + } + ] + } + ], + "next-step": "_:b1" + }, + "_:b1": { + "actions": [ + { + "participants": [ + { + "actor": { + "name": "anonymous", + "type": "person" + }, + "role": "peer-reviewer" + } + ], + "outputs": [ + { + "type": "review-article", + "published": "2022-09-20T09:40:32.116638+00:00", + "doi": "10.7554/eLife.80984.1.sa0", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.80984.1.sa0", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/RQwETDjIEe2ne9s7CnzPmA" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2022.06.30.498369#hypothesis:RQwETDjIEe2ne9s7CnzPmA" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:RQwETDjIEe2ne9s7CnzPmA/content" + } + ] + } + ] + }, + { + "participants": [ + { + "actor": { + "name": "anonymous", + "type": "person" + }, + "role": "peer-reviewer" + } + ], + "outputs": [ + { + "type": "review-article", + "published": "2022-09-20T09:40:33.119469+00:00", + "doi": "10.7554/eLife.80984.1.sa1", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.80984.1.sa1", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/RaRhYDjIEe2YJx-YyylD6A" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2022.06.30.498369#hypothesis:RaRhYDjIEe2YJx-YyylD6A" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:RaRhYDjIEe2YJx-YyylD6A/content" + } + ] + } + ] + }, + { + "participants": [ + { + "actor": { + "name": "anonymous", + "type": "person" + }, + "role": "peer-reviewer" + } + ], + "outputs": [ + { + "type": "review-article", + "published": "2022-09-20T09:40:34.220543+00:00", + "doi": "10.7554/eLife.80984.1.sa2", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.80984.1.sa2", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/RksWLDjIEe2x-GujLxJUMg" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2022.06.30.498369#hypothesis:RksWLDjIEe2x-GujLxJUMg" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:RksWLDjIEe2x-GujLxJUMg/content" + } + ] + } + ] + }, + { + "participants": [ + { + "actor": { + "type": "person", + "name": "Pil Joon Seo", + "firstName": "Pil Joon", + "surname": "Seo", + "_relatesToOrganization": "Seoul National University, Korea, the Republic of", + "affiliation": { + "type": "organization", + "name": "Seoul National University", + "location": "Seoul, Korea, the Republic of" + } + }, + "role": "editor" + }, + { + "actor": { + "type": "person", + "name": "Jürgen Kleine-Vehn", + "firstName": "Jürgen", + "surname": "Kleine-Vehn", + "_relatesToOrganization": "University of Freiburg, Germany", + "affiliation": { + "type": "organization", + "name": "University of Freiburg", + "location": "Freiburg, Germany" + } + }, + "role": "senior-editor" + } + ], + "outputs": [ + { + "type": "evaluation-summary", + "published": "2022-09-20T09:40:35.261952+00:00", + "doi": "10.7554/eLife.80984.1.sa3", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.80984.1.sa3", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/Ruti5DjIEe2VBOuQDx9FSg" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2022.06.30.498369#hypothesis:Ruti5DjIEe2VBOuQDx9FSg" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:Ruti5DjIEe2VBOuQDx9FSg/content" + } + ] + } + ] + }, + { + "participants": [], + "outputs": [ + { + "type": "reply", + "published": "2022-11-16T11:20:07.785631+00:00", + "doi": "10.7554/eLife.80984.1.sa4", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.80984.1.sa4", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/oHTjYmWgEe2w1FdG0TDCSA" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2022.06.30.498369#hypothesis:oHTjYmWgEe2w1FdG0TDCSA" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:oHTjYmWgEe2w1FdG0TDCSA/content" + } + ] + } + ] + } + ], + "assertions": [ + { + "item": { + "type": "preprint", + "doi": "10.1101/2022.06.30.498369", + "versionIdentifier": "1" + }, + "status": "peer-reviewed" + } + ], + "inputs": [ + { + "type": "preprint", + "doi": "10.1101/2022.06.30.498369", + "url": "https://www.biorxiv.org/content/10.1101/2022.06.30.498369v1", + "versionIdentifier": "1" + } + ], + "next-step": "_:b2", + "previous-step": "_:b0" + }, + "_:b2": { + "actions": [ + { + "participants": [], + "outputs": [ + { + "type": "preprint", + "identifier": "80984", + "doi": "10.7554/eLife.80984.1", + "versionIdentifier": "1", + "license": "http://creativecommons.org/licenses/by/4.0/", + "published": "2022-10-20T14:00:00+00:00", + "partOf": { + "type": "manuscript", + "doi": "10.7554/eLife.80984", + "identifier": "80984", + "subjectDisciplines": [ + "Developmental Biology", + "Plant Biology" + ], + "published": "2022-10-20T14:00:00+00:00", + "volumeIdentifier": "11", + "electronicArticleIdentifier": "RP80984", + "complement": [ + { + "type": "Insight", + "url": "https://elifesciences.org/articles/86284", + "title": "Floral Maturation: How the sunflower gets its rings", + "description": "Pil Joon Seo, Young-Joon Park" + }, + { + "type": "Podcast", + "url": "https://elifesciences.org/podcast/episode85", + "title": "Episode 85: February 2023", + "description": "In this episode, we hear about a possible link between mitochondrial DNA and personality, why humans are mostly right-handed, circadian clocks and sunflowers, hairless mammals, and how some herbivores deal with plant toxins." + } + ] + } + } + ] + } + ], + "assertions": [ + { + "item": { + "type": "preprint", + "doi": "10.7554/eLife.80984.1", + "versionIdentifier": "1" + }, + "status": "manuscript-published" + } + ], + "inputs": [ + { + "type": "preprint", + "doi": "10.1101/2022.06.30.498369", + "url": "https://www.biorxiv.org/content/10.1101/2022.06.30.498369v1", + "versionIdentifier": "1" + }, + { + "type": "review-article", + "doi": "10.7554/eLife.80984.1.sa0" + }, + { + "type": "review-article", + "doi": "10.7554/eLife.80984.1.sa1" + }, + { + "type": "review-article", + "doi": "10.7554/eLife.80984.1.sa2" + }, + { + "type": "evaluation-summary", + "doi": "10.7554/eLife.80984.1.sa3" + }, + { + "type": "reply", + "doi": "10.7554/eLife.80984.1.sa4" + } + ], + "previous-step": "_:b1" + } + } +} \ No newline at end of file diff --git a/data/docmaps/regression_test/docmap_by_manuscript_id/86628.json b/data/docmaps/regression_test/docmap_by_manuscript_id/86628.json index eb4ee1ee..e711359b 100644 --- a/data/docmaps/regression_test/docmap_by_manuscript_id/86628.json +++ b/data/docmaps/regression_test/docmap_by_manuscript_id/86628.json @@ -204,7 +204,8 @@ ], "published": "2023-04-11T14:00:00+00:00", "volumeIdentifier": "12", - "electronicArticleIdentifier": "RP86628" + "electronicArticleIdentifier": "RP86628", + "complement": [] } } ] @@ -454,7 +455,8 @@ ], "published": "2023-04-11T14:00:00+00:00", "volumeIdentifier": "12", - "electronicArticleIdentifier": "RP86628" + "electronicArticleIdentifier": "RP86628", + "complement": [] } } ] diff --git a/data/docmaps/regression_test/docmap_by_manuscript_id/86873.json b/data/docmaps/regression_test/docmap_by_manuscript_id/86873.json index a949ac84..d28d9dab 100644 --- a/data/docmaps/regression_test/docmap_by_manuscript_id/86873.json +++ b/data/docmaps/regression_test/docmap_by_manuscript_id/86873.json @@ -265,7 +265,8 @@ ], "published": "2023-07-13T14:00:00+00:00", "volumeIdentifier": "12", - "electronicArticleIdentifier": "RP86873" + "electronicArticleIdentifier": "RP86873", + "complement": [] } } ] @@ -532,7 +533,8 @@ ], "published": "2023-07-13T14:00:00+00:00", "volumeIdentifier": "12", - "electronicArticleIdentifier": "RP86873" + "electronicArticleIdentifier": "RP86873", + "complement": [] } } ] diff --git a/data/docmaps/regression_test/docmap_by_manuscript_id/87193.json b/data/docmaps/regression_test/docmap_by_manuscript_id/87193.json index 09453988..06d27adf 100644 --- a/data/docmaps/regression_test/docmap_by_manuscript_id/87193.json +++ b/data/docmaps/regression_test/docmap_by_manuscript_id/87193.json @@ -298,7 +298,8 @@ ], "published": "2023-07-13T14:00:00+00:00", "volumeIdentifier": "12", - "electronicArticleIdentifier": "RP87193" + "electronicArticleIdentifier": "RP87193", + "complement": [] } } ] @@ -628,7 +629,8 @@ ], "published": "2023-07-13T14:00:00+00:00", "volumeIdentifier": "12", - "electronicArticleIdentifier": "RP87193" + "electronicArticleIdentifier": "RP87193", + "complement": [] } } ] diff --git a/data/docmaps/regression_test/docmap_by_manuscript_id/88266.json b/data/docmaps/regression_test/docmap_by_manuscript_id/88266.json new file mode 100644 index 00000000..83d059ea --- /dev/null +++ b/data/docmaps/regression_test/docmap_by_manuscript_id/88266.json @@ -0,0 +1,643 @@ +{ + "@context": "https://w3id.org/docmaps/context.jsonld", + "type": "docmap", + "id": "https://data-hub-api.elifesciences.org/enhanced-preprints/docmaps/v2/by-publisher/elife/get-by-manuscript-id?manuscript_id=88266", + "created": "2023-05-02T13:55:54+00:00", + "updated": "2023-05-02T13:55:54+00:00", + "publisher": { + "account": { + "id": "https://sciety.org/groups/elife", + "service": "https://sciety.org" + }, + "homepage": "https://elifesciences.org/", + "id": "https://elifesciences.org/", + "logo": "https://sciety.org/static/groups/elife--b560187e-f2fb-4ff9-a861-a204f3fc0fb0.png", + "name": "eLife" + }, + "first-step": "_:b0", + "steps": { + "_:b0": { + "actions": [ + { + "participants": [], + "outputs": [ + { + "type": "preprint", + "identifier": "88266", + "doi": "10.7554/eLife.88266.1", + "versionIdentifier": "1", + "license": "http://creativecommons.org/licenses/by/4.0/" + } + ] + } + ], + "assertions": [ + { + "item": { + "type": "preprint", + "doi": "10.1101/2023.06.08.544148", + "versionIdentifier": "1" + }, + "status": "under-review", + "happened": "2023-05-25T08:56:33+00:00" + }, + { + "item": { + "type": "preprint", + "doi": "10.7554/eLife.88266.1", + "versionIdentifier": "1" + }, + "status": "draft" + } + ], + "inputs": [ + { + "type": "preprint", + "doi": "10.1101/2023.06.08.544148", + "url": "https://www.biorxiv.org/content/10.1101/2023.06.08.544148v1", + "versionIdentifier": "1", + "published": "2023-06-11", + "content": [ + { + "type": "computer-file", + "url": "s3://transfers-elife/biorxiv_Current_Content/June_2023/13_Jun_23_Batch_1641/30b983d1-6d04-1014-8954-d3d2452327b2.meca" + } + ] + } + ], + "next-step": "_:b1" + }, + "_:b1": { + "actions": [ + { + "participants": [ + { + "actor": { + "name": "anonymous", + "type": "person" + }, + "role": "peer-reviewer" + } + ], + "outputs": [ + { + "type": "review-article", + "published": "2023-08-07T08:43:20.118486+00:00", + "doi": "10.7554/eLife.88266.1.sa0", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.88266.1.sa0", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/dgUvCjT-Ee6gD8eV0Jqaeg" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2023.06.08.544148#hypothesis:dgUvCjT-Ee6gD8eV0Jqaeg" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:dgUvCjT-Ee6gD8eV0Jqaeg/content" + } + ] + } + ] + }, + { + "participants": [ + { + "actor": { + "name": "anonymous", + "type": "person" + }, + "role": "peer-reviewer" + } + ], + "outputs": [ + { + "type": "review-article", + "published": "2023-08-07T08:43:20.856744+00:00", + "doi": "10.7554/eLife.88266.1.sa1", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.88266.1.sa1", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/dnQfoDT-Ee6ZsdcZ_JrzEg" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2023.06.08.544148#hypothesis:dnQfoDT-Ee6ZsdcZ_JrzEg" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:dnQfoDT-Ee6ZsdcZ_JrzEg/content" + } + ] + } + ] + }, + { + "participants": [ + { + "actor": { + "type": "person", + "name": "Arya Mani", + "firstName": "Arya", + "surname": "Mani", + "_relatesToOrganization": "Yale University School of Medicine, United States of America", + "affiliation": { + "type": "organization", + "name": "Yale University School of Medicine", + "location": "New Haven, United States of America" + } + }, + "role": "editor" + }, + { + "actor": { + "type": "person", + "name": "David James", + "firstName": "David", + "_middleName": "E", + "surname": "James", + "_relatesToOrganization": "University of Sydney, Australia", + "affiliation": { + "type": "organization", + "name": "University of Sydney", + "location": "Sydney, Australia" + } + }, + "role": "senior-editor" + } + ], + "outputs": [ + { + "type": "evaluation-summary", + "published": "2023-08-07T08:43:21.849863+00:00", + "doi": "10.7554/eLife.88266.1.sa2", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.88266.1.sa2", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/dwtBtDT-Ee6k-WcTF3IfQA" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2023.06.08.544148#hypothesis:dwtBtDT-Ee6k-WcTF3IfQA" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:dwtBtDT-Ee6k-WcTF3IfQA/content" + } + ] + } + ] + } + ], + "assertions": [ + { + "item": { + "type": "preprint", + "doi": "10.1101/2023.06.08.544148", + "versionIdentifier": "1" + }, + "status": "peer-reviewed" + } + ], + "inputs": [ + { + "type": "preprint", + "doi": "10.1101/2023.06.08.544148", + "url": "https://www.biorxiv.org/content/10.1101/2023.06.08.544148v1", + "versionIdentifier": "1" + } + ], + "next-step": "_:b2", + "previous-step": "_:b0" + }, + "_:b2": { + "actions": [ + { + "participants": [], + "outputs": [ + { + "type": "preprint", + "identifier": "88266", + "doi": "10.7554/eLife.88266.1", + "versionIdentifier": "1", + "license": "http://creativecommons.org/licenses/by/4.0/", + "published": "2023-08-10T14:00:00+00:00", + "partOf": { + "type": "manuscript", + "doi": "10.7554/eLife.88266", + "identifier": "88266", + "subjectDisciplines": [ + "Computational and Systems Biology" + ], + "published": "2023-08-10T14:00:00+00:00", + "volumeIdentifier": "12", + "electronicArticleIdentifier": "RP88266", + "complement": [ + { + "type": "Insight", + "url": "https://elifesciences.org/articles/94382", + "title": "Genetics: From mouse to human", + "description": "Arya Mani" + }, + { + "type": "Collection", + "url": "https://elifesciences.org/collections/560cc395/meta-research-a-collection-of-articles", + "title": "Special Issue: Systems Genetics", + "description": "Edited by David James et al", + "thumbnail": "https://iiif.elifesciences.org/journal-cms/collection%2F2023-07%2Fsystems-genetics-illustration-1.png/full/full/0/default.jpg" + } + ] + } + } + ] + } + ], + "assertions": [ + { + "item": { + "type": "preprint", + "doi": "10.7554/eLife.88266.1", + "versionIdentifier": "1" + }, + "status": "manuscript-published" + } + ], + "inputs": [ + { + "type": "preprint", + "doi": "10.1101/2023.06.08.544148", + "url": "https://www.biorxiv.org/content/10.1101/2023.06.08.544148v1", + "versionIdentifier": "1" + }, + { + "type": "review-article", + "doi": "10.7554/eLife.88266.1.sa0" + }, + { + "type": "review-article", + "doi": "10.7554/eLife.88266.1.sa1" + }, + { + "type": "evaluation-summary", + "doi": "10.7554/eLife.88266.1.sa2" + } + ], + "next-step": "_:b3", + "previous-step": "_:b1" + }, + "_:b3": { + "actions": [ + { + "participants": [], + "outputs": [ + { + "type": "preprint", + "identifier": "88266", + "doi": "10.7554/eLife.88266.2", + "versionIdentifier": "2", + "license": "http://creativecommons.org/licenses/by/4.0/" + } + ] + } + ], + "assertions": [ + { + "item": { + "type": "preprint", + "doi": "10.1101/2023.06.08.544148", + "versionIdentifier": "2" + }, + "status": "under-review", + "happened": "2023-09-21T09:20:02+00:00" + }, + { + "item": { + "type": "preprint", + "doi": "10.7554/eLife.88266.2", + "versionIdentifier": "2" + }, + "status": "draft" + } + ], + "inputs": [ + { + "type": "preprint", + "doi": "10.1101/2023.06.08.544148", + "url": "https://www.biorxiv.org/content/10.1101/2023.06.08.544148v2", + "versionIdentifier": "2", + "published": "2023-09-20", + "content": [ + { + "type": "computer-file", + "url": "s3://transfers-elife/biorxiv_Current_Content/September_2023/22_Sep_23_Batch_1742/c008402b-714e-1014-b1da-9faabbc11cb1.meca" + } + ] + } + ], + "next-step": "_:b4", + "previous-step": "_:b2" + }, + "_:b4": { + "actions": [ + { + "participants": [ + { + "actor": { + "name": "anonymous", + "type": "person" + }, + "role": "peer-reviewer" + } + ], + "outputs": [ + { + "type": "review-article", + "published": "2023-10-31T09:39:25.063183+00:00", + "doi": "10.7554/eLife.88266.2.sa0", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.88266.2.sa0", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/YMv4pnfREe6v8yfbe85gBQ" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2023.06.08.544148#hypothesis:YMv4pnfREe6v8yfbe85gBQ" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:YMv4pnfREe6v8yfbe85gBQ/content" + } + ] + } + ] + }, + { + "participants": [ + { + "actor": { + "name": "anonymous", + "type": "person" + }, + "role": "peer-reviewer" + } + ], + "outputs": [ + { + "type": "review-article", + "published": "2023-10-31T09:39:25.840466+00:00", + "doi": "10.7554/eLife.88266.2.sa1", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.88266.2.sa1", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/YUC5DHfREe6H7_fr-6o-sQ" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2023.06.08.544148#hypothesis:YUC5DHfREe6H7_fr-6o-sQ" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:YUC5DHfREe6H7_fr-6o-sQ/content" + } + ] + } + ] + }, + { + "participants": [ + { + "actor": { + "type": "person", + "name": "Arya Mani", + "firstName": "Arya", + "surname": "Mani", + "_relatesToOrganization": "Yale University School of Medicine, United States of America", + "affiliation": { + "type": "organization", + "name": "Yale University School of Medicine", + "location": "New Haven, United States of America" + } + }, + "role": "editor" + }, + { + "actor": { + "type": "person", + "name": "David James", + "firstName": "David", + "_middleName": "E", + "surname": "James", + "_relatesToOrganization": "University of Sydney, Australia", + "affiliation": { + "type": "organization", + "name": "University of Sydney", + "location": "Sydney, Australia" + } + }, + "role": "senior-editor" + } + ], + "outputs": [ + { + "type": "evaluation-summary", + "published": "2023-10-31T09:39:26.547305+00:00", + "doi": "10.7554/eLife.88266.2.sa2", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.88266.2.sa2", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/YayuvnfREe696cNNeJg8Vg" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2023.06.08.544148#hypothesis:YayuvnfREe696cNNeJg8Vg" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:YayuvnfREe696cNNeJg8Vg/content" + } + ] + } + ] + }, + { + "participants": [], + "outputs": [ + { + "type": "reply", + "published": "2023-10-31T10:23:21.729390+00:00", + "doi": "10.7554/eLife.88266.2.sa3", + "license": "http://creativecommons.org/licenses/by/4.0/", + "url": "https://doi.org/10.7554/eLife.88266.2.sa3", + "content": [ + { + "type": "web-page", + "url": "https://hypothes.is/a/hHXMkHfXEe6tVVva9HcV0g" + }, + { + "type": "web-page", + "url": "https://sciety.org/articles/activity/10.1101/2023.06.08.544148#hypothesis:hHXMkHfXEe6tVVva9HcV0g" + }, + { + "type": "web-page", + "url": "https://sciety.org/evaluations/hypothesis:hHXMkHfXEe6tVVva9HcV0g/content" + } + ] + } + ] + } + ], + "assertions": [ + { + "item": { + "type": "preprint", + "doi": "10.1101/2023.06.08.544148", + "versionIdentifier": "2" + }, + "status": "revised" + } + ], + "inputs": [ + { + "type": "preprint", + "doi": "10.1101/2023.06.08.544148", + "url": "https://www.biorxiv.org/content/10.1101/2023.06.08.544148v2", + "versionIdentifier": "2" + } + ], + "next-step": "_:b5", + "previous-step": "_:b3" + }, + "_:b5": { + "actions": [ + { + "participants": [], + "outputs": [ + { + "type": "preprint", + "identifier": "88266", + "doi": "10.7554/eLife.88266.2", + "versionIdentifier": "2", + "license": "http://creativecommons.org/licenses/by/4.0/", + "published": "2023-11-02T14:00:00+00:00", + "partOf": { + "type": "manuscript", + "doi": "10.7554/eLife.88266", + "identifier": "88266", + "subjectDisciplines": [ + "Computational and Systems Biology" + ], + "published": "2023-08-10T14:00:00+00:00", + "volumeIdentifier": "12", + "electronicArticleIdentifier": "RP88266", + "complement": [ + { + "type": "Insight", + "url": "https://elifesciences.org/articles/94382", + "title": "Genetics: From mouse to human", + "description": "Arya Mani" + }, + { + "type": "Collection", + "url": "https://elifesciences.org/collections/560cc395/meta-research-a-collection-of-articles", + "title": "Special Issue: Systems Genetics", + "description": "Edited by David James et al", + "thumbnail": "https://iiif.elifesciences.org/journal-cms/collection%2F2023-07%2Fsystems-genetics-illustration-1.png/full/full/0/default.jpg" + } + ] + } + } + ] + } + ], + "assertions": [ + { + "item": { + "type": "preprint", + "doi": "10.7554/eLife.88266.2", + "versionIdentifier": "2" + }, + "status": "manuscript-published" + } + ], + "inputs": [ + { + "type": "preprint", + "doi": "10.1101/2023.06.08.544148", + "url": "https://www.biorxiv.org/content/10.1101/2023.06.08.544148v2", + "versionIdentifier": "2" + }, + { + "type": "review-article", + "doi": "10.7554/eLife.88266.2.sa0" + }, + { + "type": "review-article", + "doi": "10.7554/eLife.88266.2.sa1" + }, + { + "type": "evaluation-summary", + "doi": "10.7554/eLife.88266.2.sa2" + }, + { + "type": "reply", + "doi": "10.7554/eLife.88266.2.sa3" + } + ], + "next-step": "_:b6", + "previous-step": "_:b4" + }, + "_:b6": { + "actions": [ + { + "participants": [], + "outputs": [ + { + "type": "version-of-record", + "doi": "10.7554/eLife.88266.3", + "published": "2023-12-07", + "url": "https://doi.org/10.7554/eLife.88266.3", + "content": [ + { + "type": "web-page", + "url": "https://elifesciences.org/articles/88266" + } + ] + } + ] + } + ], + "assertions": [ + { + "item": { + "type": "version-of-record", + "doi": "10.7554/eLife.88266.3", + "versionIdentifier": "3" + }, + "status": "vor-published" + } + ], + "inputs": [ + { + "type": "preprint", + "doi": "10.7554/eLife.88266.2", + "identifier": "88266", + "versionIdentifier": "2" + } + ], + "previous-step": "_:b5" + } + } +} \ No newline at end of file diff --git a/data/docmaps/regression_test/docmap_by_manuscript_id/89891.json b/data/docmaps/regression_test/docmap_by_manuscript_id/89891.json index 447ad010..bdb7653b 100644 --- a/data/docmaps/regression_test/docmap_by_manuscript_id/89891.json +++ b/data/docmaps/regression_test/docmap_by_manuscript_id/89891.json @@ -298,7 +298,8 @@ ], "published": "2023-08-08T14:00:00+00:00", "volumeIdentifier": "12", - "electronicArticleIdentifier": "RP89891" + "electronicArticleIdentifier": "RP89891", + "complement": [] } } ] @@ -628,7 +629,8 @@ ], "published": "2023-08-08T14:00:00+00:00", "volumeIdentifier": "12", - "electronicArticleIdentifier": "RP89891" + "electronicArticleIdentifier": "RP89891", + "complement": [] } } ] diff --git a/data_hub_api/docmaps/v2/codecs/elife_manuscript.py b/data_hub_api/docmaps/v2/codecs/elife_manuscript.py index 2fa37aa3..785d241a 100644 --- a/data_hub_api/docmaps/v2/codecs/elife_manuscript.py +++ b/data_hub_api/docmaps/v2/codecs/elife_manuscript.py @@ -1,4 +1,4 @@ -from typing import Optional, Sequence +from typing import Iterable, Optional, Sequence from data_hub_api.config import ( DOI_ROOT_URL, ELECTRONIC_ARTICLE_IDENTIFIER_PREFIX, @@ -20,7 +20,6 @@ DocmapPublishedElifeManuscriptOutput, DocmapPublishedElifeManuscriptPartOf ) -from data_hub_api.utils.json import remove_key_with_none_value_only def get_elife_manuscript_version_doi( @@ -100,49 +99,58 @@ def get_elife_manuscript_subject_disciplines( return None -def get_elife_manuscript_part_of_section_complement( - related_content: Optional[ApiRelatedContentInput] -) -> Optional[Sequence[DocmapPartOfComplement]]: - related_article_dict: Optional[dict] = None - collection_dict: Optional[dict] = None - podcast_dict: Optional[dict] = None - if related_content: - if related_content['manuscript_id']: - related_article_dict = { - 'type': related_content['manuscript_type'], - 'url': 'https://elifesciences.org/articles/' + related_content['manuscript_id'], - 'title': related_content['manuscript_title'], - 'description': related_content['manuscript_authors_csv'] - } - if related_content['collection_id']: - assert related_content['collection_curator_name'] - collection_dict = { - 'type': 'Collection', - 'url': ('https://elifesciences.org/collections/' - + related_content['collection_id'] - + '/meta-research-a-collection-of-articles'), - 'title': related_content['collection_title'], - 'description': ( - 'Edited by ' + related_content['collection_curator_name'] + ' et al' - if related_content['is_collection_curator_et_al'] - else 'Edited by ' + related_content['collection_curator_name'] - ), - '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, podcast_dict] - ) # type: ignore - return None +def iter_elife_manuscript_part_of_section_complement_for_one_record( + related_content: ApiRelatedContentInput +) -> Iterable[DocmapPartOfComplement]: + if related_content['manuscript_id']: + assert related_content['manuscript_type'] + yield { + 'type': related_content['manuscript_type'], + 'url': 'https://elifesciences.org/articles/' + related_content['manuscript_id'], + 'title': related_content['manuscript_title'], + 'description': related_content['manuscript_authors_csv'] + } + if related_content['collection_id']: + assert related_content['collection_curator_name'] + yield { + 'type': 'Collection', + 'url': ('https://elifesciences.org/collections/' + + related_content['collection_id'] + + '/meta-research-a-collection-of-articles'), + 'title': related_content['collection_title'], + 'description': ( + 'Edited by ' + related_content['collection_curator_name'] + ' et al' + if related_content['is_collection_curator_et_al'] + else 'Edited by ' + related_content['collection_curator_name'] + ), + 'thumbnail': related_content['collection_thumbnail_url'] + } + if related_content['podcast_id']: + yield { + 'type': 'Podcast', + 'url': ( + 'https://elifesciences.org/podcast/episode' + + str(related_content['podcast_id']) + ), + 'title': related_content['podcast_title'], + 'description': related_content['podcast_desc'] + } + + +def iter_elife_manuscript_part_of_section_complement_for_each_record( + related_content_array: Optional[Sequence[ApiRelatedContentInput]] +) -> Iterable[DocmapPartOfComplement]: + if related_content_array: + for related_content in related_content_array: + yield from iter_elife_manuscript_part_of_section_complement_for_one_record( + related_content + ) + + +def get_sorted_elife_manuscript_part_of_section_complement( + complement_iterable: Iterable[DocmapPartOfComplement] +) -> Sequence[DocmapPartOfComplement]: + return sorted(complement_iterable, key=lambda complement: complement['url']) def get_elife_manuscript_part_of_section( @@ -150,11 +158,6 @@ def get_elife_manuscript_part_of_section( ) -> DocmapPublishedElifeManuscriptPartOf: first_manuscript_version = query_result_item['manuscript_versions'][0] assert first_manuscript_version['rp_publication_timestamp'] - related_content = ( - query_result_item['related_content'][0] - if query_result_item['related_content'] - else None - ) return { 'type': 'manuscript', 'doi': query_result_item['elife_doi'], @@ -167,7 +170,11 @@ def get_elife_manuscript_part_of_section( 'electronicArticleIdentifier': get_elife_manuscript_electronic_article_identifier( query_result_item ), - 'complement': get_elife_manuscript_part_of_section_complement(related_content) + 'complement': get_sorted_elife_manuscript_part_of_section_complement( + iter_elife_manuscript_part_of_section_complement_for_each_record( + query_result_item['related_content'] + ) + ) } diff --git a/data_hub_api/docmaps/v2/docmap_typing.py b/data_hub_api/docmaps/v2/docmap_typing.py index 3be63b7c..32940915 100644 --- a/data_hub_api/docmaps/v2/docmap_typing.py +++ b/data_hub_api/docmaps/v2/docmap_typing.py @@ -48,8 +48,8 @@ DocmapPartOfComplement = TypedDict( 'DocmapPartOfComplement', { - 'type': Optional[str], - 'url': Optional[str], + 'type': str, + 'url': str, 'title': Optional[str], 'description': Optional[str], 'thumbnail': Optional[str] diff --git a/requirements.dev.txt b/requirements.dev.txt index 56d86380..de6ed367 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,7 +1,6 @@ flake8==6.0.0 pylint==2.15.8 -pytest==7.2.0 +pytest==8.1.1 pytest-watch==4.2.0 mypy==0.991 httpx==0.23.1 - diff --git a/tests/regression_tests/docmaps/docmap_manuscript_test.py b/tests/regression_tests/docmaps/docmap_manuscript_test.py index 77aa058a..71b2d87a 100644 --- a/tests/regression_tests/docmaps/docmap_manuscript_test.py +++ b/tests/regression_tests/docmaps/docmap_manuscript_test.py @@ -19,7 +19,9 @@ # and it is also inside a collection: '88984', '91729', # have related article - '86824' # have related podcast + '86824', # have related podcast + '80984', # have both related article and podcast + '88266' # have both related article and collection ] diff --git a/tests/unit_tests/docmaps/v2/codecs/elife_manuscript_test.py b/tests/unit_tests/docmaps/v2/codecs/elife_manuscript_test.py index 0e618dd7..dd2e510d 100644 --- a/tests/unit_tests/docmaps/v2/codecs/elife_manuscript_test.py +++ b/tests/unit_tests/docmaps/v2/codecs/elife_manuscript_test.py @@ -1,4 +1,5 @@ from datetime import datetime + from data_hub_api.config import ( DOI_ROOT_URL, ELECTRONIC_ARTICLE_IDENTIFIER_PREFIX, @@ -13,7 +14,9 @@ get_docmap_elife_manuscript_output_for_vor, get_elife_manuscript_electronic_article_identifier, get_elife_manuscript_part_of_section, - get_elife_manuscript_part_of_section_complement, + get_sorted_elife_manuscript_part_of_section_complement, + iter_elife_manuscript_part_of_section_complement_for_each_record, + iter_elife_manuscript_part_of_section_complement_for_one_record, get_elife_manuscript_subject_disciplines, get_elife_manuscript_version_doi, get_elife_manuscript_volume @@ -21,16 +24,19 @@ from tests.unit_tests.docmaps.v2.test_data import ( COLLECTIONS_DICT_1, - COLLECTIONS_DICT_WITH_NO_VALUE_1, DOCMAPS_QUERY_RESULT_ITEM_1, 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, + RELATED_ARTICLE_CONTENT_INPUT_DICT_1, + RELATED_ARTICLE_DOCMAP_OUTPUT_1, + RELATED_COLLECTION_CONTENT_INPUT_DICT_1, + RELATED_COLLECTION_DOCMAP_OUTPUT_1, + RELATED_CONTENT_DICT_WITH_NO_VALUE_1, + RELATED_CONTENT_DICT_WITH_ALL_VALUE_1, + RELATED_PODACST_DOCMAP_OUTPUT_1, + RELATED_PODCAST_CONTENT_INPUT_DICT_1, RP_PUBLICATION_TIMESTAMP_1, MANUSCRIPT_VERSION_1, SUBJECT_AREA_NAME_1, @@ -143,100 +149,104 @@ def test_should_return_none_when_subject_areas_is_none(self): assert not result -class TestGetElifeManuscriptPartOfSectionComplement: +class TestIterElifeManuscriptPartOfSectionComplementForOneRecord: def test_should_have_complement_none_if_related_content_is_not_available(self): - result_without_related_content = get_elife_manuscript_part_of_section_complement( - RELATED_CONTENT_WITH_NO_VALUE_1 + result_without_related_content = list( + iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_CONTENT_DICT_WITH_NO_VALUE_1 + ) ) assert not result_without_related_content def test_should_populate_complement_if_related_content_for_all_value_is_available(self): - result_with_related_content = get_elife_manuscript_part_of_section_complement( - RELATED_CONTENT_WITH_ALL_VALUE_1 + result_with_related_content = list( + iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_CONTENT_DICT_WITH_ALL_VALUE_1 + ) ) - assert result_with_related_content == [{ - 'type': 'manuscript_type_1', - 'url': 'https://elifesciences.org/articles/manuscript_id_1', - 'title': 'manuscript_title_1', - 'description': 'manuscript_authors_csv_1' - }, { - 'type': 'Collection', - 'url': ( - 'https://elifesciences.org/collections/' - + 'collection_id_1' - + '/meta-research-a-collection-of-articles' - ), - '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' - }] + assert result_with_related_content == [ + RELATED_ARTICLE_DOCMAP_OUTPUT_1, + RELATED_COLLECTION_DOCMAP_OUTPUT_1, + RELATED_PODACST_DOCMAP_OUTPUT_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, - **PODCAST_DICT_WITH_NO_VALUE_1} + result_with_related_content = list( + iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_ARTICLE_CONTENT_INPUT_DICT_1 + ) ) - assert result_with_related_content == [{ - 'type': 'manuscript_type_1', - 'url': 'https://elifesciences.org/articles/manuscript_id_1', - 'title': 'manuscript_title_1', - 'description': 'manuscript_authors_csv_1' - }] + assert result_with_related_content == [RELATED_ARTICLE_DOCMAP_OUTPUT_1] 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, - **PODCAST_DICT_WITH_NO_VALUE_1, - **COLLECTIONS_DICT_1} + result_with_related_content = list( + iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_COLLECTION_CONTENT_INPUT_DICT_1 + ) ) - assert result_with_related_content == [{ - 'type': 'Collection', - 'url': ( - 'https://elifesciences.org/collections/' - + 'collection_id_1' - + '/meta-research-a-collection-of-articles' - ), - 'title': 'collection_title_1', - 'description': 'Edited by collection_curator_name_1 et al', - 'thumbnail': 'collection_thumbnail_url_1' - }] + assert result_with_related_content == [RELATED_COLLECTION_DOCMAP_OUTPUT_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} + result_with_related_content = list( + iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_PODCAST_CONTENT_INPUT_DICT_1 + ) ) - assert result_with_related_content == [{ - 'type': 'Podcast', - 'url': 'https://elifesciences.org/podcast/episode111', - 'title': 'podcast_title_1', - 'description': 'podcast_desc_1' - }] + assert result_with_related_content == [RELATED_PODACST_DOCMAP_OUTPUT_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} + result_with_related_content = list( + iter_elife_manuscript_part_of_section_complement_for_one_record( + {**RELATED_CONTENT_DICT_WITH_NO_VALUE_1, + **PODCAST_DICT_WITH_NO_VALUE_1, + **COLLECTIONS_DICT_1, + 'is_collection_curator_et_al': False} + ) ) assert result_with_related_content[0]['description'] == ( 'Edited by collection_curator_name_1' ) - def test_should_return_none_if_the_related_content_is_none(self): - result = get_elife_manuscript_part_of_section_complement(None) - assert not result + +class TestGetElifeManuscriptPartOfSectionComplementForEachRecord: + def test_should_return_related_content_for_values_of_all_types_in_same_row(self): + actual_result = list(iter_elife_manuscript_part_of_section_complement_for_each_record( + [RELATED_CONTENT_DICT_WITH_ALL_VALUE_1] + )) + assert actual_result == list( + iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_CONTENT_DICT_WITH_ALL_VALUE_1 + ) + ) + + def test_should_return_related_content_for_values_of_all_types_in_separate_rows(self): + actual_result = list(iter_elife_manuscript_part_of_section_complement_for_each_record([ + RELATED_ARTICLE_CONTENT_INPUT_DICT_1, + RELATED_COLLECTION_CONTENT_INPUT_DICT_1, + RELATED_PODCAST_CONTENT_INPUT_DICT_1 + ])) + assert actual_result == ( + list(iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_ARTICLE_CONTENT_INPUT_DICT_1 + )) + + list(iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_COLLECTION_CONTENT_INPUT_DICT_1 + )) + + list(iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_PODCAST_CONTENT_INPUT_DICT_1 + )) + ) -class TestGetElifeManuscriptPartOfSection: +class TestGetSortedElifeManuscriptPartOfSectionComplement: + def test_should_sort_itearble_by_url(self): + result = get_sorted_elife_manuscript_part_of_section_complement( + [{'url': 'url_3', 'title': 'title_3'}, {'url': 'url_2'}, {'url': 'url_1'}] + ) + assert result == [{'url': 'url_1'}, {'url': 'url_2'}, {'url': 'url_3', 'title': 'title_3'}] + + +class TestIterElifeManuscriptPartOfSection: def test_should_populate_elife_manuscript_part_of_section(self): result = get_elife_manuscript_part_of_section( query_result_item=DOCMAPS_QUERY_RESULT_ITEM_1 @@ -253,9 +263,9 @@ def test_should_populate_elife_manuscript_part_of_section(self): 'electronicArticleIdentifier': get_elife_manuscript_electronic_article_identifier( DOCMAPS_QUERY_RESULT_ITEM_1 ), - 'complement': get_elife_manuscript_part_of_section_complement( - RELATED_CONTENT_WITH_NO_VALUE_1 - ) + 'complement': list(iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_CONTENT_DICT_WITH_NO_VALUE_1 + )) } def test_should_populate_volume_id_caculated_by_first_publication_year_for_each_version(self): @@ -289,8 +299,10 @@ def test_should_populate_complement_if_related_content_is_available(self): result_with_related_content = get_elife_manuscript_part_of_section( query_result_item=DOCMAPS_QUERY_RESULT_ITEM_2 ) - assert result_with_related_content['complement'] == ( - get_elife_manuscript_part_of_section_complement(RELATED_CONTENT_WITH_ALL_VALUE_1) + assert result_with_related_content['complement'] == list( + iter_elife_manuscript_part_of_section_complement_for_one_record( + RELATED_CONTENT_DICT_WITH_ALL_VALUE_1 + ) ) diff --git a/tests/unit_tests/docmaps/v2/test_data.py b/tests/unit_tests/docmaps/v2/test_data.py index 3643a761..91ae3a26 100644 --- a/tests/unit_tests/docmaps/v2/test_data.py +++ b/tests/unit_tests/docmaps/v2/test_data.py @@ -7,6 +7,7 @@ ApiManuscriptVersionInput, ApiRelatedContentInput ) +from data_hub_api.docmaps.v2.docmap_typing import DocmapPartOfComplement MANUSCRIPT_ID_1 = 'manuscript_id_1' @@ -155,18 +156,62 @@ 'podcast_desc': 'podcast_desc_1' } -RELATED_CONTENT_WITH_NO_VALUE_1: ApiRelatedContentInput = { +RELATED_CONTENT_DICT_WITH_NO_VALUE_1: ApiRelatedContentInput = { **RELATED_ARTICLE_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_CONTENT_DICT_WITH_ALL_VALUE_1: ApiRelatedContentInput = { **RELATED_ARTICLE_DICT_1, # type: ignore **COLLECTIONS_DICT_1, # type: ignore **PODCAST_DICT_1 # type: ignore } +RELATED_ARTICLE_CONTENT_INPUT_DICT_1: ApiRelatedContentInput = { + **RELATED_ARTICLE_DICT_1, # type: ignore + **COLLECTIONS_DICT_WITH_NO_VALUE_1, # type: ignore + **PODCAST_DICT_WITH_NO_VALUE_1 # type: ignore +} + +RELATED_COLLECTION_CONTENT_INPUT_DICT_1: ApiRelatedContentInput = { + **RELATED_ARTICLE_DICT_WITH_NO_VALUE_1, # type: ignore + **COLLECTIONS_DICT_1, # type: ignore + **PODCAST_DICT_WITH_NO_VALUE_1 # type: ignore +} + +RELATED_PODCAST_CONTENT_INPUT_DICT_1: ApiRelatedContentInput = { + **RELATED_ARTICLE_DICT_WITH_NO_VALUE_1, # type: ignore + **COLLECTIONS_DICT_WITH_NO_VALUE_1, # type: ignore + **PODCAST_DICT_1 # type: ignore +} + +RELATED_ARTICLE_DOCMAP_OUTPUT_1: DocmapPartOfComplement = { + 'type': 'manuscript_type_1', + 'url': 'https://elifesciences.org/articles/manuscript_id_1', + 'title': 'manuscript_title_1', + 'description': 'manuscript_authors_csv_1' +} + +RELATED_COLLECTION_DOCMAP_OUTPUT_1: DocmapPartOfComplement = { + 'type': 'Collection', + 'url': ( + 'https://elifesciences.org/collections/' + + 'collection_id_1' + + '/meta-research-a-collection-of-articles' + ), + 'title': 'collection_title_1', + 'description': 'Edited by collection_curator_name_1 et al', + 'thumbnail': 'collection_thumbnail_url_1' +} + +RELATED_PODACST_DOCMAP_OUTPUT_1: DocmapPartOfComplement = { + 'type': 'Podcast', + 'url': 'https://elifesciences.org/podcast/episode111', + 'title': 'podcast_title_1', + 'description': 'podcast_desc_1' +} + PUBLISHER_DICT_1 = {"id": "publisher_1"} PUBLISHER_DICT_STR_1 = f'{PUBLISHER_DICT_1}' @@ -177,7 +222,7 @@ 'license': LICENSE_1, 'is_reviewed_preprint_type': True, 'manuscript_versions': [MANUSCRIPT_VERSION_1], - 'related_content': [RELATED_CONTENT_WITH_NO_VALUE_1] + 'related_content': [RELATED_CONTENT_DICT_WITH_NO_VALUE_1] } DOCMAPS_QUERY_RESULT_ITEM_2: ApiInput = { @@ -187,7 +232,7 @@ 'license': LICENSE_1, 'is_reviewed_preprint_type': True, 'manuscript_versions': [MANUSCRIPT_VERSION_1, MANUSCRIPT_VERSION_2], - 'related_content': [RELATED_CONTENT_WITH_ALL_VALUE_1] + 'related_content': [RELATED_CONTENT_DICT_WITH_ALL_VALUE_1] } HYPOTHESIS_ID_1 = 'hypothesis_1'