From 919fcfb3f23b43c2b8f6a1782c6e5926c4e7190e Mon Sep 17 00:00:00 2001 From: Mihai Bivol Date: Wed, 30 Mar 2016 13:22:18 +0200 Subject: [PATCH 1/6] tests: initial api tests Signed-off-by: Mihai Bivol --- json_merger/__init__.py | 3 +- json_merger/merger.py | 31 +++++++++++++++++ tests/conftest.py | 3 ++ tests/{test_json_merger.py => test_ext.py} | 1 - tests/test_merger.py | 40 ++++++++++++++++++++++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 json_merger/merger.py rename tests/{test_json_merger.py => test_ext.py} (97%) create mode 100644 tests/test_merger.py diff --git a/json_merger/__init__.py b/json_merger/__init__.py index 68cec09..5833890 100644 --- a/json_merger/__init__.py +++ b/json_merger/__init__.py @@ -27,6 +27,7 @@ from __future__ import absolute_import, print_function from .ext import JsonMerger +from .merger import merge_records from .version import __version__ -__all__ = ('__version__', 'JsonMerger') +__all__ = ('__version__', 'JsonMerger', 'merge_records') diff --git a/json_merger/merger.py b/json_merger/merger.py new file mode 100644 index 0000000..3c36331 --- /dev/null +++ b/json_merger/merger.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# +# This file is part of Inspirehep. +# Copyright (C) 2016 CERN. +# +# Inspirehep is free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# Inspirehep is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Inspirehep; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307, USA. +# +# In applying this license, CERN does not +# waive the privileges and immunities granted to it by virtue of its status +# as an Intergovernmental Organization or submit itself to any jurisdiction. + +"""Invenio module that is able to merge json record objects.""" + +from __future__ import absolute_import, print_function + + +def merge_records(src, update): + return src diff --git a/tests/conftest.py b/tests/conftest.py index a850370..cbf466a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -30,6 +30,8 @@ import pytest from flask import Flask +from json_merger import JsonMerger + @pytest.fixture() def app(): @@ -38,4 +40,5 @@ def app(): app.config.update( TESTING=True ) + JsonMerger(app) return app diff --git a/tests/test_json_merger.py b/tests/test_ext.py similarity index 97% rename from tests/test_json_merger.py rename to tests/test_ext.py index a5e7125..df0afb5 100644 --- a/tests/test_json_merger.py +++ b/tests/test_ext.py @@ -28,7 +28,6 @@ from __future__ import absolute_import, print_function from flask import Flask -from flask_babelex import Babel from json_merger import JsonMerger diff --git a/tests/test_merger.py b/tests/test_merger.py new file mode 100644 index 0000000..afd515e --- /dev/null +++ b/tests/test_merger.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# +# This file is part of Inspirehep. +# Copyright (C) 2016 CERN. +# +# Inspirehep is free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# Inspirehep is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Inspirehep; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307, USA. +# +# In applying this license, CERN does not +# waive the privileges and immunities granted to it by virtue of its status +# as an Intergovernmental Organization or submit itself to any jurisdiction. + + +"""Test Merging Logic""" + +from __future__ import absolute_import, print_function + +from flask import Flask + +from json_merger import merge_records + + +def test_merge_records_empty_update(): + # TODO add a fixture + src = {'some': 'stuff'} + update = {} + + assert merge_records(src, update) == src From cb68ac63bbb635f249ca685e6803a68c5e818411 Mon Sep 17 00:00:00 2001 From: Mihai Bivol Date: Wed, 30 Mar 2016 14:49:42 +0200 Subject: [PATCH 2/6] tests: first failing test * Adds first test for a simple author typo update. Signed-off-by: Mihai Bivol --- tests/conftest.py | 26 +++++++++++++++ tests/fixtures/author_typo/description.txt | 1 + tests/fixtures/author_typo/expected.json | 38 ++++++++++++++++++++++ tests/fixtures/author_typo/src.json | 38 ++++++++++++++++++++++ tests/fixtures/author_typo/update.json | 13 ++++++++ tests/test_merger.py | 9 +++-- 6 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/author_typo/description.txt create mode 100644 tests/fixtures/author_typo/expected.json create mode 100644 tests/fixtures/author_typo/src.json create mode 100644 tests/fixtures/author_typo/update.json diff --git a/tests/conftest.py b/tests/conftest.py index cbf466a..69f58a6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,6 +27,9 @@ from __future__ import absolute_import, print_function +import json +import os + import pytest from flask import Flask @@ -42,3 +45,26 @@ def app(): ) JsonMerger(app) return app + + +@pytest.fixture() +def json_loader(): + class _Loader(object): + def __init__(self, basedir): + self.basedir = basedir + + def _read_file(self, test_name, file_name): + with open(os.path.join(self.basedir, test_name, file_name)) as f: + return f.read() + + def load_single(self, test_name, file_name): + return json.loads(self._read_file(test_name, file_name)) + + def load_test(self, test_name): + src = self.load_single(test_name, 'src.json') + update = self.load_single(test_name, 'update.json') + expected = self.load_single(test_name, 'expected.json') + desc = self._read_file(test_name, 'description.txt') + return src, update, expected, desc + + return _Loader('./tests/fixtures/') diff --git a/tests/fixtures/author_typo/description.txt b/tests/fixtures/author_typo/description.txt new file mode 100644 index 0000000..854ef6a --- /dev/null +++ b/tests/fixtures/author_typo/description.txt @@ -0,0 +1 @@ +Update typo in author name should preserve affiliations. diff --git a/tests/fixtures/author_typo/expected.json b/tests/fixtures/author_typo/expected.json new file mode 100644 index 0000000..443a334 --- /dev/null +++ b/tests/fixtures/author_typo/expected.json @@ -0,0 +1,38 @@ +{ + "authors": [ + { + "affiliations": [ + { + "value": "UC, Santa Barbara" + } + ], + "curated_relation": false, + "full_name": "Horowitz, Gary" + }, + { + "affiliations": [ + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "UC, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "LBL, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "Santa Barbara, KITP" + } + ], + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_typo/src.json b/tests/fixtures/author_typo/src.json new file mode 100644 index 0000000..b44b12a --- /dev/null +++ b/tests/fixtures/author_typo/src.json @@ -0,0 +1,38 @@ +{ + "authors": [ + { + "affiliations": [ + { + "value": "UC, Santa Barbara" + } + ], + "curated_relation": false, + "full_name": "Horowitz, Gary T." + }, + { + "affiliations": [ + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "UC, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "LBL, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "Santa Barbara, KITP" + } + ], + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_typo/update.json b/tests/fixtures/author_typo/update.json new file mode 100644 index 0000000..b2f6433 --- /dev/null +++ b/tests/fixtures/author_typo/update.json @@ -0,0 +1,13 @@ +{ + "authors": [ + { + "curated_relation": false, + "full_name": "Horowitz, Gary" + }, + { + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/test_merger.py b/tests/test_merger.py index afd515e..e440a4e 100644 --- a/tests/test_merger.py +++ b/tests/test_merger.py @@ -27,14 +27,19 @@ from __future__ import absolute_import, print_function -from flask import Flask +import pytest from json_merger import merge_records def test_merge_records_empty_update(): - # TODO add a fixture src = {'some': 'stuff'} update = {} assert merge_records(src, update) == src + + +@pytest.mark.skip +def test_merge_records_author_typo(json_loader): + src, update, expected, desc = json_loader.load_test('author_typo') + assert merge_records(src, update) == expected, desc From 5a6db66f620d5dc212be46fc2c5d598795a3ca36 Mon Sep 17 00:00:00 2001 From: Mihai Bivol Date: Wed, 30 Mar 2016 15:01:41 +0200 Subject: [PATCH 3/6] merger: docstrings Signed-off-by: Mihai Bivol --- json_merger/merger.py | 1 + 1 file changed, 1 insertion(+) diff --git a/json_merger/merger.py b/json_merger/merger.py index 3c36331..1cdeda6 100644 --- a/json_merger/merger.py +++ b/json_merger/merger.py @@ -28,4 +28,5 @@ def merge_records(src, update): + """Merge update upon src.""" return src From 97d2bc591170bdca3cbde1d809dd39fae77df411 Mon Sep 17 00:00:00 2001 From: Mihai Bivol Date: Wed, 30 Mar 2016 15:11:00 +0200 Subject: [PATCH 4/6] global: fix MANIFSET.in Signed-off-by: Mihai Bivol --- MANIFEST.in | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MANIFEST.in b/MANIFEST.in index 071336b..e21365c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -35,3 +35,19 @@ include .dockerignore include .editorconfig include .tx/config recursive-include json_merger *.po *.pot *.mo + +# added by check_manifest.py +include *.rst +include *.sh +include *.txt +include LICENSE +include babel.ini +include pytest.ini +recursive-include docs *.bat +recursive-include docs *.py +recursive-include docs *.rst +recursive-include docs Makefile +recursive-include examples *.py +recursive-include tests *.json +recursive-include tests *.py +recursive-include tests *.txt From 61d3096def30bc9a39fc8cc262fb42223a381dcd Mon Sep 17 00:00:00 2001 From: Mihai Bivol Date: Wed, 30 Mar 2016 15:18:49 +0200 Subject: [PATCH 5/6] tests: xfail instead of skip Signed-off-by: Mihai Bivol --- tests/test_merger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_merger.py b/tests/test_merger.py index e440a4e..3d5e7bf 100644 --- a/tests/test_merger.py +++ b/tests/test_merger.py @@ -39,7 +39,7 @@ def test_merge_records_empty_update(): assert merge_records(src, update) == src -@pytest.mark.skip +@pytest.mark.xfail def test_merge_records_author_typo(json_loader): src, update, expected, desc = json_loader.load_test('author_typo') assert merge_records(src, update) == expected, desc From be5cde6c196e005fbbacde74d4d0c2d009ef895a Mon Sep 17 00:00:00 2001 From: Mihai Bivol Date: Thu, 31 Mar 2016 12:57:38 +0200 Subject: [PATCH 6/6] tests: new acceptance scenarios * Adds new TDD scenarios to test. Signed-off-by: Mihai Bivol --- tests/fixtures/author_delete/description.txt | 1 + tests/fixtures/author_delete/expected.json | 29 +++++++++++++ tests/fixtures/author_delete/src.json | 38 +++++++++++++++++ tests/fixtures/author_delete/update.json | 9 ++++ .../author_delete_and_typo/description.txt | 1 + .../author_delete_and_typo/expected.json | 29 +++++++++++++ .../fixtures/author_delete_and_typo/src.json | 38 +++++++++++++++++ .../author_delete_and_typo/update.json | 9 ++++ tests/fixtures/author_prepend/description.txt | 1 + tests/fixtures/author_prepend/expected.json | 41 +++++++++++++++++++ tests/fixtures/author_prepend/src.json | 38 +++++++++++++++++ tests/fixtures/author_prepend/update.json | 16 ++++++++ .../author_prepend_and_typo/description.txt | 1 + .../author_prepend_and_typo/expected.json | 41 +++++++++++++++++++ .../fixtures/author_prepend_and_typo/src.json | 38 +++++++++++++++++ .../author_prepend_and_typo/update.json | 16 ++++++++ ...st_merger.py => test_merger_acceptance.py} | 19 ++++----- 17 files changed, 355 insertions(+), 10 deletions(-) create mode 100644 tests/fixtures/author_delete/description.txt create mode 100644 tests/fixtures/author_delete/expected.json create mode 100644 tests/fixtures/author_delete/src.json create mode 100644 tests/fixtures/author_delete/update.json create mode 100644 tests/fixtures/author_delete_and_typo/description.txt create mode 100644 tests/fixtures/author_delete_and_typo/expected.json create mode 100644 tests/fixtures/author_delete_and_typo/src.json create mode 100644 tests/fixtures/author_delete_and_typo/update.json create mode 100644 tests/fixtures/author_prepend/description.txt create mode 100644 tests/fixtures/author_prepend/expected.json create mode 100644 tests/fixtures/author_prepend/src.json create mode 100644 tests/fixtures/author_prepend/update.json create mode 100644 tests/fixtures/author_prepend_and_typo/description.txt create mode 100644 tests/fixtures/author_prepend_and_typo/expected.json create mode 100644 tests/fixtures/author_prepend_and_typo/src.json create mode 100644 tests/fixtures/author_prepend_and_typo/update.json rename tests/{test_merger.py => test_merger_acceptance.py} (78%) diff --git a/tests/fixtures/author_delete/description.txt b/tests/fixtures/author_delete/description.txt new file mode 100644 index 0000000..f95c3b1 --- /dev/null +++ b/tests/fixtures/author_delete/description.txt @@ -0,0 +1 @@ +Deleting an author should preserve affiliations for the other. diff --git a/tests/fixtures/author_delete/expected.json b/tests/fixtures/author_delete/expected.json new file mode 100644 index 0000000..ffb873f --- /dev/null +++ b/tests/fixtures/author_delete/expected.json @@ -0,0 +1,29 @@ +{ + "authors": [ + { + "affiliations": [ + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "UC, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "LBL, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "Santa Barbara, KITP" + } + ], + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_delete/src.json b/tests/fixtures/author_delete/src.json new file mode 100644 index 0000000..b44b12a --- /dev/null +++ b/tests/fixtures/author_delete/src.json @@ -0,0 +1,38 @@ +{ + "authors": [ + { + "affiliations": [ + { + "value": "UC, Santa Barbara" + } + ], + "curated_relation": false, + "full_name": "Horowitz, Gary T." + }, + { + "affiliations": [ + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "UC, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "LBL, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "Santa Barbara, KITP" + } + ], + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_delete/update.json b/tests/fixtures/author_delete/update.json new file mode 100644 index 0000000..ed0f0b4 --- /dev/null +++ b/tests/fixtures/author_delete/update.json @@ -0,0 +1,9 @@ +{ + "authors": [ + { + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_delete_and_typo/description.txt b/tests/fixtures/author_delete_and_typo/description.txt new file mode 100644 index 0000000..35d6e5e --- /dev/null +++ b/tests/fixtures/author_delete_and_typo/description.txt @@ -0,0 +1 @@ +Deleting an author and editing another should preserve affiliations for the second. diff --git a/tests/fixtures/author_delete_and_typo/expected.json b/tests/fixtures/author_delete_and_typo/expected.json new file mode 100644 index 0000000..8f82308 --- /dev/null +++ b/tests/fixtures/author_delete_and_typo/expected.json @@ -0,0 +1,29 @@ +{ + "authors": [ + { + "affiliations": [ + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "UC, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "LBL, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "Santa Barbara, KITP" + } + ], + "curated_relation": false, + "full_name": "Ooguri, Hirosi, Update", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_delete_and_typo/src.json b/tests/fixtures/author_delete_and_typo/src.json new file mode 100644 index 0000000..b44b12a --- /dev/null +++ b/tests/fixtures/author_delete_and_typo/src.json @@ -0,0 +1,38 @@ +{ + "authors": [ + { + "affiliations": [ + { + "value": "UC, Santa Barbara" + } + ], + "curated_relation": false, + "full_name": "Horowitz, Gary T." + }, + { + "affiliations": [ + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "UC, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "LBL, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "Santa Barbara, KITP" + } + ], + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_delete_and_typo/update.json b/tests/fixtures/author_delete_and_typo/update.json new file mode 100644 index 0000000..ec06969 --- /dev/null +++ b/tests/fixtures/author_delete_and_typo/update.json @@ -0,0 +1,9 @@ +{ + "authors": [ + { + "curated_relation": false, + "full_name": "Ooguri, Hirosi, Update", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_prepend/description.txt b/tests/fixtures/author_prepend/description.txt new file mode 100644 index 0000000..1db094e --- /dev/null +++ b/tests/fixtures/author_prepend/description.txt @@ -0,0 +1 @@ +Prepending a new author should preserve affiliations for all the others. diff --git a/tests/fixtures/author_prepend/expected.json b/tests/fixtures/author_prepend/expected.json new file mode 100644 index 0000000..dadb74c --- /dev/null +++ b/tests/fixtures/author_prepend/expected.json @@ -0,0 +1,41 @@ +{ + "authors": [ + { + "full_name": "New, Author" + }, + { + "affiliations": [ + { + "value": "UC, Santa Barbara" + } + ], + "curated_relation": false, + "full_name": "Horowitz, Gary T." + }, + { + "affiliations": [ + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "UC, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "LBL, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "Santa Barbara, KITP" + } + ], + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_prepend/src.json b/tests/fixtures/author_prepend/src.json new file mode 100644 index 0000000..b44b12a --- /dev/null +++ b/tests/fixtures/author_prepend/src.json @@ -0,0 +1,38 @@ +{ + "authors": [ + { + "affiliations": [ + { + "value": "UC, Santa Barbara" + } + ], + "curated_relation": false, + "full_name": "Horowitz, Gary T." + }, + { + "affiliations": [ + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "UC, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "LBL, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "Santa Barbara, KITP" + } + ], + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_prepend/update.json b/tests/fixtures/author_prepend/update.json new file mode 100644 index 0000000..f1d3b5b --- /dev/null +++ b/tests/fixtures/author_prepend/update.json @@ -0,0 +1,16 @@ +{ + "authors": [ + { + "full_name": "New, Author" + }, + { + "curated_relation": false, + "full_name": "Horowitz, Gary T." + }, + { + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_prepend_and_typo/description.txt b/tests/fixtures/author_prepend_and_typo/description.txt new file mode 100644 index 0000000..52496a4 --- /dev/null +++ b/tests/fixtures/author_prepend_and_typo/description.txt @@ -0,0 +1 @@ +Update typo in author plus adding a new record should preserve affiliations. diff --git a/tests/fixtures/author_prepend_and_typo/expected.json b/tests/fixtures/author_prepend_and_typo/expected.json new file mode 100644 index 0000000..3bf613d --- /dev/null +++ b/tests/fixtures/author_prepend_and_typo/expected.json @@ -0,0 +1,41 @@ +{ + "authors": [ + { + "full_name": "New, Author" + }, + { + "affiliations": [ + { + "value": "UC, Santa Barbara" + } + ], + "curated_relation": false, + "full_name": "Horowitz, Gary" + }, + { + "affiliations": [ + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "UC, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "LBL, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "Santa Barbara, KITP" + } + ], + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_prepend_and_typo/src.json b/tests/fixtures/author_prepend_and_typo/src.json new file mode 100644 index 0000000..b44b12a --- /dev/null +++ b/tests/fixtures/author_prepend_and_typo/src.json @@ -0,0 +1,38 @@ +{ + "authors": [ + { + "affiliations": [ + { + "value": "UC, Santa Barbara" + } + ], + "curated_relation": false, + "full_name": "Horowitz, Gary T." + }, + { + "affiliations": [ + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "UC, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "LBL, Berkeley" + }, + { + "record": { + "$ref": "http://localhost:5000/api/institutions/903889" + }, + "value": "Santa Barbara, KITP" + } + ], + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/fixtures/author_prepend_and_typo/update.json b/tests/fixtures/author_prepend_and_typo/update.json new file mode 100644 index 0000000..e4106f7 --- /dev/null +++ b/tests/fixtures/author_prepend_and_typo/update.json @@ -0,0 +1,16 @@ +{ + "authors": [ + { + "full_name": "New, Author" + }, + { + "curated_relation": false, + "full_name": "Horowitz, Gary" + }, + { + "curated_relation": false, + "full_name": "Ooguri, Hirosi", + "inspire_id": "INSPIRE-00113241" + } + ] +} diff --git a/tests/test_merger.py b/tests/test_merger_acceptance.py similarity index 78% rename from tests/test_merger.py rename to tests/test_merger_acceptance.py index 3d5e7bf..9b91d18 100644 --- a/tests/test_merger.py +++ b/tests/test_merger_acceptance.py @@ -23,7 +23,7 @@ # as an Intergovernmental Organization or submit itself to any jurisdiction. -"""Test Merging Logic""" +"""Acceptance scenarios for the merger.""" from __future__ import absolute_import, print_function @@ -32,14 +32,13 @@ from json_merger import merge_records -def test_merge_records_empty_update(): - src = {'some': 'stuff'} - update = {} - - assert merge_records(src, update) == src - - @pytest.mark.xfail -def test_merge_records_author_typo(json_loader): - src, update, expected, desc = json_loader.load_test('author_typo') +@pytest.mark.parametrize('scenario', [ + 'author_typo', + 'author_prepend', + 'author_delete', + 'author_prepend_and_typo', + 'author_delete_and_typo']) +def test_expected_outcome(json_loader, scenario): + src, update, expected, desc = json_loader.load_test(scenario) assert merge_records(src, update) == expected, desc