예제 #1
0
    def test_reaccept(self, input, Graph):
        initial_cg = ChangeGraph(Graph(*initial))
        initial_cg.process()
        ChangeSet.objects.from_graph(initial_cg, NormalizedDataFactory().id).accept()

        Graph.reseed()  # Force new values to be generated

        first_cg = ChangeGraph(Graph(*input))
        first_cg.process()
        first_cs = ChangeSet.objects.from_graph(first_cg, NormalizedDataFactory().id)
        assert first_cs is not None
        first_cs.accept()

        second_cg = ChangeGraph(Graph(*input))
        second_cg.process()
        second_cs = ChangeSet.objects.from_graph(second_cg, NormalizedDataFactory().id)
        assert second_cs is None
예제 #2
0
    def test_disambiguate(self, input, model, delta, Graph):
        initial_cg = ChangeGraph(Graph(*initial))
        initial_cg.process(disambiguate=False)
        ChangeSet.objects.from_graph(initial_cg,
                                     NormalizedDataFactory().id).accept()

        Graph.reseed()
        # Nasty hack to avoid progres' fuzzy counting
        before = model.objects.exclude(change=None).count()

        cg = ChangeGraph(Graph(*input))
        cg.process()
        cs = ChangeSet.objects.from_graph(cg, NormalizedDataFactory().id)
        if cs is not None:
            cs.accept()

        assert (model.objects.exclude(change=None).count() - before) == delta
예제 #3
0
    def test_canonical(self, Graph, first_canonical, second_canonical, change):
        first_source = factories.SourceFactory(canonical=first_canonical)
        second_source = factories.SourceFactory(canonical=second_canonical)

        first_graph = ChangeGraph(Graph(
            Preprint(
                id=1,
                title='The first title',
                identifiers=[WorkIdentifier(1)],
            )),
                                  namespace=first_source.user.username)

        second_graph = ChangeGraph(Graph(
            Article(
                id=1,
                title='The Second Title',
                identifiers=[WorkIdentifier(1)],
            )),
                                   namespace=second_source.user.username)

        first_graph.process()
        (cw, _) = ChangeSet.objects.from_graph(
            first_graph,
            NormalizedDataFactory(source=first_source.user).id).accept()

        assert cw.type == 'share.preprint'
        assert cw.title == 'The first title'

        second_graph.process()
        ChangeSet.objects.from_graph(
            second_graph,
            NormalizedDataFactory(source=second_source.user).id).accept()

        cw = models.AbstractCreativeWork.objects.get(id=cw.id)

        assert second_graph.nodes[0].change == change
        assert cw.type == change.get('type', 'share.preprint')
        assert cw.title == change.get('title', 'The first title')
예제 #4
0
    def test_split_brain(self, Graph):
        initial_cg = ChangeGraph(Graph(*initial))
        initial_cg.process()
        ChangeSet.objects.from_graph(initial_cg,
                                     NormalizedDataFactory().id).accept()

        # Multiple matches found for a thing should break
        cg = ChangeGraph(
            Graph(Preprint(identifiers=[WorkIdentifier(1),
                                        WorkIdentifier(2)])))
        with pytest.raises(NotImplementedError) as e:
            cg.process()
        assert e.value.args[
            0] == "Multiple <class 'share.models.creative.Preprint'>s found"
예제 #5
0
    def test_get_data(self, generator, model, route, controlled_values, client, Graph):
        initial_cg = ChangeGraph(Graph(*initial))
        initial_cg.process(disambiguate=False)
        ChangeSet.objects.from_graph(initial_cg, NormalizedDataFactory().id).accept()

        cg = ChangeGraph(Graph(*generator))
        cg.process()

        for obj in cg.serialize():
            if obj['@type'] == model:
                expected_id = obj['@id']
                expected = obj
        response = client.get('/api/v2/{}/{}/'.format(route, expected_id))

        actual = json.loads(response.content.decode(encoding='UTF-8'))

        assert response.status_code == 200
        assert actual['data']['id'] == expected_id
        assert actual['data']['attributes']['type'] == expected['@type']
        for value in controlled_values:
            assert actual['data']['attributes'][value] == expected[camelCase_to_underscore(value)]
예제 #6
0
    def test_no_timetraveling_many(self, Graph):
        oldest_graph = ChangeGraph(
            Graph(
                Publication(
                    id=1,
                    sparse=True,
                    is_deleted=True,
                    title='The first title',
                    description='The first description',
                    identifiers=[WorkIdentifier(1)],
                    date_updated='2016-02-03T18:07:50.000000',
                )))

        oldest_graph.process()
        ChangeSet.objects.from_graph(oldest_graph,
                                     NormalizedDataFactory().id).accept()

        newer_graph = ChangeGraph(
            Graph(
                Publication(
                    id=1,
                    sparse=True,
                    is_deleted=False,
                    identifiers=[WorkIdentifier(1)],
                    date_updated='2017-02-03T18:07:50.000000',
                )))

        newer_graph.process()
        ChangeSet.objects.from_graph(newer_graph,
                                     NormalizedDataFactory().id).accept()

        newest_graph = ChangeGraph(
            Graph(
                Publication(
                    id=1,
                    sparse=True,
                    title='The final title',
                    identifiers=[WorkIdentifier(1)],
                    date_updated='2017-02-03T18:07:53.385000',
                )))

        newest_graph.process()
        ChangeSet.objects.from_graph(newest_graph,
                                     NormalizedDataFactory().id).accept()

        older_graph = ChangeGraph(
            Graph(
                Publication(
                    id=1,
                    sparse=True,
                    is_deleted=True,
                    title='The second title',
                    description='The final description',
                    identifiers=[WorkIdentifier(1)],
                    date_updated='2017-01-01T18:00:00.000000',
                )))

        older_graph.process()
        assert older_graph.nodes[0].change == {
            'description': 'The final description'
        }