Beispiel #1
0
    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)
Beispiel #2
0
    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,
                             'https://share.osf.io/api/v2/normalizeddata/')
                    view.post(self.request)
                    data = json.loads(rsps.calls[-1].request.body.decode())

                    share_graph = data['data']['attributes']['data']['@graph']
                    identifier_node = next(n for n in share_graph
                                           if n['@type'] == 'workidentifier')
                    assert identifier_node['creative_work'][
                        '@type'] == 'project'
                    nt.assert_equal(AdminLogEntry.objects.count(), count + 1)