diff --git a/api/share/utils.py b/api/share/utils.py index db4f24ce3e0..9ef07646d2a 100644 --- a/api/share/utils.py +++ b/api/share/utils.py @@ -29,6 +29,10 @@ def shtrove_ingest_url(): return f'{settings.SHARE_URL}api/v3/ingest' +def sharev2_push_url(): + return f'{settings.SHARE_URL}api/v2/normalizeddata/' + + def is_qa_resource(resource): """ QA puts tags and special titles on their project to stop them from appearing in the search results. This function @@ -350,7 +354,7 @@ def send_share_json(resource, data): access_token = settings.SHARE_API_TOKEN return requests.post( - f'{settings.SHARE_URL}api/v2/normalizeddata/', + sharev2_push_url(), json=data, headers={ 'Authorization': f'Bearer {access_token}', diff --git a/api_tests/share/_utils.py b/api_tests/share/_utils.py index 56b0e1f4482..9595aaf1b81 100644 --- a/api_tests/share/_utils.py +++ b/api_tests/share/_utils.py @@ -11,7 +11,7 @@ postcommit_queue, ) from website import settings as website_settings -from api.share.utils import shtrove_ingest_url +from api.share.utils import shtrove_ingest_url, sharev2_push_url @contextlib.contextmanager @@ -27,6 +27,8 @@ def mock_share_responses(): _ingest_url = shtrove_ingest_url() _rsps.add(responses.POST, _ingest_url, status=200) _rsps.add(responses.DELETE, _ingest_url, status=200) + # for legacy sharev2 support: + _rsps.add(responses.POST, sharev2_push_url(), status=200) yield _rsps @@ -41,11 +43,15 @@ def mock_update_share(): def expect_ingest_request(mock_share_responses, osfguid, *, token=None, delete=False, count=1): mock_share_responses._calls.reset() yield - assert len(mock_share_responses.calls) == count, ( - f'expected {count} call(s), got {len(mock_share_responses.calls)}: {list(mock_share_responses.calls)}' + _double_count = count * 2 # pushing to share two ways + assert len(mock_share_responses.calls) == _double_count, ( + f'expected {_double_count} call(s), got {len(mock_share_responses.calls)}: {list(mock_share_responses.calls)}' ) for _call in mock_share_responses.calls: - assert_ingest_request(_call.request, osfguid, token=token, delete=delete) + if _call.request.url.startswith(shtrove_ingest_url()): + assert_ingest_request(_call.request, osfguid, token=token, delete=delete) + else: + assert _call.request.url.startswith(sharev2_push_url()) def assert_ingest_request(request, expected_osfguid, *, token=None, delete=False): diff --git a/api_tests/share/test_share_node.py b/api_tests/share/test_share_node.py index e470fcb8a65..755a6c041f5 100644 --- a/api_tests/share/test_share_node.py +++ b/api_tests/share/test_share_node.py @@ -20,7 +20,7 @@ from website.project.tasks import on_node_updated from framework.auth.core import Auth -from api.share.utils import shtrove_ingest_url +from api.share.utils import shtrove_ingest_url, sharev2_push_url from ._utils import expect_ingest_request @@ -188,17 +188,20 @@ def test_call_async_update_on_500_retry(self, mock_share_responses, node, user): """This is meant to simulate a temporary outage, so the retry mechanism should kick in and complete it.""" mock_share_responses.replace(responses.POST, shtrove_ingest_url(), status=500) mock_share_responses.add(responses.POST, shtrove_ingest_url(), status=200) + mock_share_responses.replace(responses.POST, sharev2_push_url(), status=500) + mock_share_responses.add(responses.POST, sharev2_push_url(), status=200) with expect_ingest_request(mock_share_responses, node._id, count=2): on_node_updated(node._id, user._id, False, {'is_public'}) def test_call_async_update_on_500_failure(self, mock_share_responses, node, user): """This is meant to simulate a total outage, so the retry mechanism should try X number of times and quit.""" - mock_share_responses.assert_all_requests_are_fired = False # allows it to retry indefinitely mock_share_responses.replace(responses.POST, shtrove_ingest_url(), status=500) + mock_share_responses.replace(responses.POST, sharev2_push_url(), status=500) with expect_ingest_request(mock_share_responses, node._id, count=5): # tries five times on_node_updated(node._id, user._id, False, {'is_public'}) def test_no_call_async_update_on_400_failure(self, mock_share_responses, node, user): mock_share_responses.replace(responses.POST, shtrove_ingest_url(), status=400) + mock_share_responses.replace(responses.POST, sharev2_push_url(), status=400) with expect_ingest_request(mock_share_responses, node._id): on_node_updated(node._id, user._id, False, {'is_public'}) diff --git a/api_tests/share/test_share_preprint.py b/api_tests/share/test_share_preprint.py index 3d1753c384e..1fa353dd46d 100644 --- a/api_tests/share/test_share_preprint.py +++ b/api_tests/share/test_share_preprint.py @@ -4,7 +4,7 @@ import pytest import responses -from api.share.utils import shtrove_ingest_url +from api.share.utils import shtrove_ingest_url, sharev2_push_url from framework.auth.core import Auth from osf.models.spam import SpamStatus from osf.utils.permissions import READ, WRITE, ADMIN @@ -123,12 +123,14 @@ def test_preprint_contributor_changes_updates_preprints_share(self, mock_share_r def test_call_async_update_on_500_failure(self, mock_share_responses, preprint, auth): mock_share_responses.replace(responses.POST, shtrove_ingest_url(), status=500) + mock_share_responses.replace(responses.POST, sharev2_push_url(), status=500) preprint.set_published(True, auth=auth, save=True) with expect_preprint_ingest_request(mock_share_responses, preprint, count=5): preprint.update_search() def test_no_call_async_update_on_400_failure(self, mock_share_responses, preprint, auth): mock_share_responses.replace(responses.POST, shtrove_ingest_url(), status=400) + mock_share_responses.replace(responses.POST, sharev2_push_url(), status=400) preprint.set_published(True, auth=auth, save=True) with expect_preprint_ingest_request(mock_share_responses, preprint, count=1): preprint.update_search()