Пример #1
0
 def test_infinite_regulate(self):
     reg = Regulator()
     reg._default_steps.graph_steps = (InfiniteGraphStep(),)
     graph = MutableGraph()
     graph.add_node(None, 'agent', {'name': 'Agent Agent'})
     with pytest.raises(InfiniteRegulationError):
         reg.regulate(graph)
Пример #2
0
 def test_infinite_regulate(self):
     reg = Regulator()
     reg._default_steps.graph_steps = (InfiniteGraphStep(), )
     graph = MutableGraph()
     graph.add_node(None, 'agent', {'name': 'Agent Agent'})
     with pytest.raises(InfiniteRegulationError):
         reg.regulate(graph)
Пример #3
0
 def test_calls_run(self, mock_steps, num_nodes):
     graph = MutableGraph()
     for i in range(num_nodes):
         graph.add_node(i, 'creativework')
     Regulator(regulator_config={'not': 'empty'}).regulate(graph)
     assert all(s.run.call_count == 1 for st in mock_steps.values()
                for s in st)
Пример #4
0
 def test_calls_steps(self, steps, num_nodes):
     graph = MutableGraph()
     for i in range(num_nodes):
         graph.add_node(i, 'creativework')
     Regulator().regulate(graph)
     assert all(m.should_regulate.call_count == num_nodes for m in steps['node'])
     assert all(m.regulate_node.call_count == num_nodes for m in steps['node'])
     assert all(m.regulate_graph.call_count == 1 for m in steps['graph'])
     assert all(m.validate_graph.call_count == 1 for m in steps['validation'])
Пример #5
0
    def test_blocks(self, schemes, authorities, expected_identifiers):
        identifiers = [
            # (uri, scheme, authority)
            ('http://osf.io/mst3k/', 'http', 'osf.io'),
            ('mailto:[email protected]', 'mailto', 'example.com'),
            ('2049-3630', 'urn', 'issn'),
            ('0000-0002-1825-0097', 'http', 'orcid.org'),
        ]

        step = NormalizeIRIs(blocked_schemes=schemes,
                             blocked_authorities=authorities)
        graph = MutableGraph()

        for uri, scheme, authority in identifiers:
            node = graph.add_node('id_{}'.format(authority), 'workidentifier',
                                  {'uri': uri})
            assert node['scheme'] is None
            assert node['host'] is None

            step.regulate_node(node)

            if scheme not in schemes and authority not in authorities:
                assert node['scheme'] == scheme
                assert node['host'] == authority

        assert len(graph.filter_type('workidentifier')) == expected_identifiers
Пример #6
0
 def test_normalize_agentidentifier(self, input, output):
     graph = MutableGraph()
     node = graph.add_node('1', 'agentidentifier', uri=input)
     NormalizeIRIs().regulate_node(node)
     if output:
         assert node['uri'] == output
     else:
         assert len(graph) == 0
 def test_normalize_agentidentifier(self, input, output):
     graph = MutableGraph()
     node = graph.add_node('1', 'agentidentifier', {'uri': input})
     NormalizeIRIs().regulate_node(node)
     if output:
         assert node['uri'] == output
     else:
         assert len(graph) == 0
Пример #8
0
 def test_normalize_workidentifier(self, input, output):
     graph = MutableGraph()
     node = graph.add_node('1', 'workidentifier', uri=input)
     step = NormalizeIRIs(blocked_schemes=['mailto'], blocked_authorities=['issn', 'orcid.org'])
     step.regulate_node(node)
     if output:
         assert node['uri'] == output
     else:
         assert len(graph) == 0
 def test_normalize_workidentifier(self, input, output):
     graph = MutableGraph()
     node = graph.add_node('1', 'workidentifier', {'uri': input})
     step = NormalizeIRIs(blocked_schemes=['mailto'], blocked_authorities=['issn', 'orcid.org'])
     step.regulate_node(node)
     if output:
         assert node['uri'] == output
     else:
         assert len(graph) == 0
Пример #10
0
    def test_legacy_pipeline(self, legacy, monkeypatch):
        mock_apply_changes = mock.Mock(return_value=[])
        monkeypatch.setattr(
            'share.tasks.jobs.IngestJobConsumer._apply_changes',
            mock_apply_changes)
        monkeypatch.setattr('django.conf.settings.SHARE_LEGACY_PIPELINE',
                            legacy)

        g = MutableGraph()
        g.add_node('_:id', 'creativework', title='This is a title')

        job = factories.IngestJobFactory(
            raw__datum=json.dumps({'@graph': g.to_jsonld(in_edges=False)}))

        ingest.apply(kwargs={'job_id': job.id}, throw=True)

        if legacy:
            assert NormalizedData.objects.count() == 1
            assert mock_apply_changes.call_count == 1
        else:
            assert NormalizedData.objects.count() == 0
            assert not mock_apply_changes.called
Пример #11
0
 def graph(self):
     g = MutableGraph()
     g.add_node(1, 'creativework', title='A work!', extra={
         'foo': 'flooby',
         'bah': 'hab',
     })
     g.add_node(2, 'creativework', title='Another work!', extra={
         'extra': 'extra',
         'bah': 'hab',
     })
     g.add_node(3, 'creativework', title='No extra :(')
     return g
 def graph(self):
     g = MutableGraph()
     g.add_node(1, 'creativework', {
         'title': 'A work!',
         'extra': {
             'foo': 'flooby',
             'bah': 'hab',
         },
     })
     g.add_node(2, 'creativework', {
         'title': 'Another work!',
         'extra': {
             'extra': 'extra',
             'bah': 'hab',
         },
     })
     g.add_node(3, 'creativework', {'title': 'No extra :('})
     return g
    def test_blocks(self, schemes, authorities, expected_identifiers):
        identifiers = [
            # (uri, scheme, authority)
            ('http://osf.io/mst3k/', 'http', 'osf.io'),
            ('mailto:[email protected]', 'mailto', 'example.com'),
            ('2049-3630', 'urn', 'issn'),
            ('0000-0002-1825-0097', 'http', 'orcid.org'),
        ]

        step = NormalizeIRIs(blocked_schemes=schemes, blocked_authorities=authorities)
        graph = MutableGraph()

        for uri, scheme, authority in identifiers:
            node = graph.add_node('id_{}'.format(authority), 'workidentifier', {'uri': uri})
            assert node['scheme'] is None
            assert node['host'] is None

            step.regulate_node(node)

            if scheme not in schemes and authority not in authorities:
                assert node['scheme'] == scheme
                assert node['host'] == authority

        assert len(graph.filter_type('workidentifier')) == expected_identifiers
Пример #14
0
 def test_calls_run(self, mock_steps, num_nodes):
     graph = MutableGraph()
     for i in range(num_nodes):
         graph.add_node(i, 'creativework')
     Regulator(regulator_config={'not': 'empty'}).regulate(graph)
     assert all(s.run.call_count == 1 for st in mock_steps.values() for s in st)