Skip to content

Commit

Permalink
Merge pull request #24 from ammirate/comply_schema_41
Browse files Browse the repository at this point in the history
tests: comply to schema v41.0.1
  • Loading branch information
ammirate authored Sep 8, 2017
2 parents 9fe89cc + d4c31b4 commit e4d98c4
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 9 deletions.
6 changes: 6 additions & 0 deletions inspire_json_merger/merger_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
96 changes: 87 additions & 9 deletions tests/unit/test_merger_arxiv2arxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down

1 comment on commit e4d98c4

@ammirate
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.