From d4c31b454d2b18ebfb1bd16bb4327c9a310fa191 Mon Sep 17 00:00:00 2001 From: ammirate Date: Fri, 8 Sep 2017 12:44:00 +0200 Subject: [PATCH] tests: comply to schema v41.0.1 --- inspire_json_merger/merger_config.py | 6 ++ tests/unit/test_merger_arxiv2arxiv.py | 96 ++++++++++++++++++++++++--- 2 files changed, 93 insertions(+), 9 deletions(-) diff --git a/inspire_json_merger/merger_config.py b/inspire_json_merger/merger_config.py index 1114fdb..b7ede87 100644 --- a/inspire_json_merger/merger_config.py +++ b/inspire_json_merger/merger_config.py @@ -129,6 +129,8 @@ class ArxivToArxivOperations(MergerConfigurationOperations): 'public_notes': UnifierOps.KEEP_ONLY_UPDATE_ENTITIES, 'publication_info': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_HEAD_FIRST, 'publication_type': UnifierOps.KEEP_ONLY_UPDATE_ENTITIES, + 'record_affiliations': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_HEAD_FIRST, + 'related_records': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_HEAD_FIRST, 'references': UnifierOps.KEEP_UPDATE_ENTITIES_CONFLICT_ON_HEAD_DELETE, 'references.raw_refs': UnifierOps.KEEP_ONLY_UPDATE_ENTITIES, 'references.reference.authors': UnifierOps.KEEP_UPDATE_ENTITIES_CONFLICT_ON_HEAD_DELETE, @@ -235,6 +237,8 @@ class PublisherToArxivOperations(MergerConfigurationOperations): 'public_notes': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_UPDATE_FIRST, 'publication_info': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_HEAD_FIRST, 'publication_type': UnifierOps.KEEP_UPDATE_ENTITIES_CONFLICT_ON_HEAD_DELETE, + 'record_affiliations': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_HEAD_FIRST, + 'related_records': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_HEAD_FIRST, 'references': UnifierOps.KEEP_UPDATE_ENTITIES_CONFLICT_ON_HEAD_DELETE, 'references.raw_refs': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_UPDATE_FIRST, 'references.reference.authors': UnifierOps.KEEP_UPDATE_ENTITIES_CONFLICT_ON_HEAD_DELETE, @@ -358,6 +362,8 @@ class PublisherToPublisherOperations(MergerConfigurationOperations): 'public_notes': UnifierOps.KEEP_ONLY_UPDATE_ENTITIES, 'publication_info': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_HEAD_FIRST, 'publication_type': UnifierOps.KEEP_ONLY_UPDATE_ENTITIES, + 'record_affiliations': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_HEAD_FIRST, + 'related_records': UnifierOps.KEEP_UPDATE_AND_HEAD_ENTITIES_HEAD_FIRST, 'references': UnifierOps.KEEP_UPDATE_ENTITIES_CONFLICT_ON_HEAD_DELETE, 'references.raw_refs': UnifierOps.KEEP_ONLY_UPDATE_ENTITIES, 'references.reference.authors': UnifierOps.KEEP_UPDATE_ENTITIES_CONFLICT_ON_HEAD_DELETE, diff --git a/tests/unit/test_merger_arxiv2arxiv.py b/tests/unit/test_merger_arxiv2arxiv.py index 236376c..c067e56 100644 --- a/tests/unit/test_merger_arxiv2arxiv.py +++ b/tests/unit/test_merger_arxiv2arxiv.py @@ -30,7 +30,6 @@ import decorator import pytest - from inspire_schemas.api import load_schema, validate from inspire_json_merger.inspire_json_merger import inspire_json_merge @@ -3643,34 +3642,113 @@ def test_merging_references_field_reference_urls(): validate_subschema(merged) -@pytest.mark.xfail @cover('self') def test_self_field(): - pytest.fail("Not tested yet.") + root = {} + head = { + "self": { + "$ref": "http://labs.inspirehep.net/api/literature/1622230" + } + } + conflict_val = "http://labs.inspirehep.net/api/literature/9874654321" + update = { + "self": { + "$ref": conflict_val + } + } + + expected_merged = head + root, head, update, expected_merged = add_arxiv_source(root, head, update, expected_merged) + merged, conflict = inspire_json_merge(root, head, update) + + merged = add_arxiv_source(merged) + assert merged == expected_merged + assert conflict == [[u'SET_FIELD', [u'self', u'$ref'], conflict_val]] + validate_subschema(merged) @pytest.mark.xfail @cover('documents') def test_documents_field(): - pytest.fail("Not tested yet.") + pytest.fail("Not tested. Merger doesn't have to handle this field.") @pytest.mark.xfail @cover('figures') def test_figures_field(): - pytest.fail("Not tested yet.") + pytest.fail("Not tested. Merger doesn't have to handle this field.") -@pytest.mark.xfail @cover('record_affiliations') def test_record_affiliations_field(): - pytest.fail("Not tested yet.") + root = {} + head = { + 'record_affiliations': [ + { + "curated_relation": True, + "record": {"$ref": "http://labs.inspirehep.net/api/literature/9874654321"}, + "value": "parent", + }, + ] + } + update = { + 'record_affiliations': [ + { + "curated_relation": False, + "record": {"$ref": "http://labs.inspirehep.net/api/literature/9874654321"}, + "value": "precedessor", + }, + ] + } + expected_merged = { + 'record_affiliations': [ + head['record_affiliations'][0], + update['record_affiliations'][0] + ] + } + root, head, update, expected_merged = add_arxiv_source(root, head, update, expected_merged) + merged, conflict = inspire_json_merge(root, head, update) + + merged = add_arxiv_source(merged) + assert merged == expected_merged + assert conflict is None + validate_subschema(merged) -@pytest.mark.xfail @cover('related_records') def test_related_records_field(): - pytest.fail("Not tested yet.") + root = {} + head = { + 'related_records': [ + { + "curated_relation": True, + "record": {"$ref": "http://labs.inspirehep.net/api/literature/9874654321"}, + "relation": "parent", + }, + ] + } + update = { + 'related_records': [ + { + "curated_relation": False, + "record": {"$ref": "http://labs.inspirehep.net/api/literature/9874654321"}, + "relation": "predecessor", + }, + ] + } + expected_merged = { + 'related_records': [ + head['related_records'][0], + update['related_records'][0] + ] + } + root, head, update, expected_merged = add_arxiv_source(root, head, update, expected_merged) + merged, conflict = inspire_json_merge(root, head, update) + + merged = add_arxiv_source(merged) + assert merged == expected_merged + assert conflict is None + validate_subschema(merged) def test_schema_keys_coverage():