1- from unittest .mock import ANY , call , patch , MagicMock
1+ from unittest .mock import patch , MagicMock
22from typing import Iterable , Sequence
33
44import pytest
55
66from fastapi .testclient import TestClient
77
88from data_hub_api import main as main_module
9- from data_hub_api .config import ADDITIONAL_MANUSCRIPT_IDS
109from data_hub_api .main import create_app
1110
1211
1615
1716@pytest .fixture (name = 'enhanced_preprints_docmaps_provider_class_mock' , autouse = True )
1817def _enhanced_preprints_docmaps_provider_class_mock () -> Iterable [MagicMock ]:
19- with patch .object (main_module , 'DocmapsProviderV1 ' ) as mock :
18+ with patch .object (main_module , 'DocmapsProvider ' ) as mock :
2019 yield mock
2120
2221
@@ -36,13 +35,6 @@ def _enhanced_preprints_docmaps_provider_mock(
3635 return docmaps_provider_mock_list [0 ]
3736
3837
39- @pytest .fixture (name = 'public_reviews_docmaps_provider_mock' )
40- def _public_reviews_docmaps_provider_mock (
41- docmaps_provider_mock_list : Sequence [MagicMock ]
42- ) -> MagicMock :
43- return docmaps_provider_mock_list [1 ]
44-
45-
4638def test_read_main ():
4739 client = TestClient (create_app ())
4840 response = client .get ("/" )
@@ -57,7 +49,7 @@ def test_should_return_json_with_docmaps_list_from_enhanced_preprint_provider(
5749 docmaps_index = [{'docmaps' : [{'id' : 'docmap_1' }, {'id' : 'docmap_2' }]}]
5850 enhanced_preprints_docmaps_provider_mock .get_docmaps_index .return_value = docmaps_index
5951 client = TestClient (create_app ())
60- response = client .get ('/enhanced-preprints/docmaps/v1 /index' )
52+ response = client .get ('/enhanced-preprints/docmaps/v2 /index' )
6153 assert response .json () == docmaps_index
6254
6355 def test_should_return_not_available_message_for_invalid_manuscript_id_by_elife (
@@ -67,7 +59,7 @@ def test_should_return_not_available_message_for_invalid_manuscript_id_by_elife(
6759 enhanced_preprints_docmaps_provider_mock .get_docmaps_by_manuscript_id .return_value = []
6860 client = TestClient (create_app ())
6961 response = client .get (
70- '/enhanced-preprints/docmaps/v1 /by-publisher/elife/get-by-manuscript-id' ,
62+ '/enhanced-preprints/docmaps/v2 /by-publisher/elife/get-by-manuscript-id' ,
7163 params = {'manuscript_id' : MANUSCRIPT_ID }
7264 )
7365 assert response .status_code == 404
@@ -85,43 +77,11 @@ def test_should_docmap_from_epp_provider_for_individual_by_publisher_manuscript_
8577 )
8678 client = TestClient (create_app ())
8779 response = client .get (
88- '/enhanced-preprints/docmaps/v1 /by-publisher/elife/get-by-manuscript-id' ,
80+ '/enhanced-preprints/docmaps/v2 /by-publisher/elife/get-by-manuscript-id' ,
8981 params = {'manuscript_id' : MANUSCRIPT_ID }
9082 )
9183 enhanced_preprints_docmaps_provider_mock .get_docmaps_by_manuscript_id .assert_called_with (
9284 MANUSCRIPT_ID
9385 )
9486 assert response .status_code == 200
9587 assert response .json () == article_docmap_list [0 ]
96-
97- def test_should_return_json_with_docmaps_list_from_public_review_provider (
98- self ,
99- public_reviews_docmaps_provider_mock : MagicMock
100- ):
101- docmaps_index = [{'docmaps' : [{'id' : 'docmap_1' }, {'id' : 'docmap_2' }]}]
102- public_reviews_docmaps_provider_mock .get_docmaps_index .return_value = docmaps_index
103- client = TestClient (create_app ())
104- response = client .get ('/public-reviews/docmaps/v1/index' )
105- assert response .json () == docmaps_index
106-
107- def test_should_pass_correct_parameters_to_provider_class (
108- self ,
109- enhanced_preprints_docmaps_provider_class_mock : MagicMock
110- ):
111- create_app ()
112- enhanced_preprints_docmaps_provider_class_mock .assert_has_calls (
113- [
114- call (
115- only_include_reviewed_preprint_type = True ,
116- only_include_evaluated_preprints = False ,
117- additionally_include_manuscript_ids = ADDITIONAL_MANUSCRIPT_IDS ,
118- query_results_cache = ANY
119- ),
120- call (
121- only_include_reviewed_preprint_type = False ,
122- only_include_evaluated_preprints = True ,
123- query_results_cache = ANY
124- )
125- ],
126- any_order = False
127- )
0 commit comments