Skip to content

Commit

Permalink
update reindex-to-share admin test
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Aug 11, 2023
1 parent 1b831a8 commit 90d9bba
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions admin_tests/nodes/test_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import datetime as dt
import pytest
import json
import mock
import pytz
import datetime
import responses

from osf.models import AdminLogEntry, NodeLog, AbstractNode
from admin.nodes.views import (
Expand All @@ -22,8 +20,7 @@
RemoveStuckRegistrationsView
)
from admin_tests.utilities import setup_log_view, setup_view
from api.share.utils import shtrove_ingest_url
from api_tests.share._utils import assert_ingest_request
from api_tests.share._utils import mock_update_share
from website import settings
from nose import tools as nt
from django.utils import timezone
Expand Down Expand Up @@ -267,28 +264,19 @@ def test_reindex_node_share(self):
count = AdminLogEntry.objects.count()
view = NodeReindexShare()
view = setup_log_view(view, self.request, guid=self.node._id)
with mock.patch('api.share.utils.settings.SHARE_ENABLED', True):
with mock.patch('api.share.utils.settings.SHARE_API_TOKEN', 'mock-api-token'):
with responses.RequestsMock(assert_all_requests_are_fired=True) as rsps:
rsps.add(responses.POST, shtrove_ingest_url())
view.post(self.request)
assert_ingest_request(rsps.calls[-1].request, self.node._id, token='mock-api-token')
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
with mock_update_share() as _shmock:
view.post(self.request)
assert _shmock.called_once_with(self.node._id)
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)

def test_reindex_registration_share(self):
count = AdminLogEntry.objects.count()
view = NodeReindexShare()
view = setup_log_view(view, self.request, guid=self.registration._id)
with mock.patch('api.share.utils.settings.SHARE_ENABLED', True):
with mock.patch('api.share.utils.settings.SHARE_API_TOKEN', 'mock-api-token'):
with responses.RequestsMock(assert_all_requests_are_fired=True) as rsps:
rsps.add(responses.POST, 'https://share.osf.io/api/v2/normalizeddata/')
view.post(self.request)
data = json.loads(rsps.calls[-1].request.body.decode())

assert any(graph for graph in data['data']['attributes']['data']['@graph']
if graph['@type'] == self.registration.provider.share_publish_type.lower())
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
with mock_update_share() as _shmock:
view.post(self.request)
assert _shmock.called_once_with(self.registration._id)
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)

@mock.patch('website.search.search.update_node')
def test_reindex_node_elastic(self, mock_update_node):
Expand Down

0 comments on commit 90d9bba

Please sign in to comment.