Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion json_merger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
32 changes: 32 additions & 0 deletions json_merger/merger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- 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):
"""Merge update upon src."""
return src
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@

from __future__ import absolute_import, print_function

import json
import os

import pytest
from flask import Flask

from json_merger import JsonMerger


@pytest.fixture()
def app():
Expand All @@ -38,4 +43,28 @@ def app():
app.config.update(
TESTING=True
)
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/')
1 change: 1 addition & 0 deletions tests/fixtures/author_delete/description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deleting an author should preserve affiliations for the other.
29 changes: 29 additions & 0 deletions tests/fixtures/author_delete/expected.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
38 changes: 38 additions & 0 deletions tests/fixtures/author_delete/src.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
9 changes: 9 additions & 0 deletions tests/fixtures/author_delete/update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"authors": [
{
"curated_relation": false,
"full_name": "Ooguri, Hirosi",
"inspire_id": "INSPIRE-00113241"
}
]
}
1 change: 1 addition & 0 deletions tests/fixtures/author_delete_and_typo/description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deleting an author and editing another should preserve affiliations for the second.
29 changes: 29 additions & 0 deletions tests/fixtures/author_delete_and_typo/expected.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
38 changes: 38 additions & 0 deletions tests/fixtures/author_delete_and_typo/src.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
9 changes: 9 additions & 0 deletions tests/fixtures/author_delete_and_typo/update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"authors": [
{
"curated_relation": false,
"full_name": "Ooguri, Hirosi, Update",
"inspire_id": "INSPIRE-00113241"
}
]
}
1 change: 1 addition & 0 deletions tests/fixtures/author_prepend/description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prepending a new author should preserve affiliations for all the others.
41 changes: 41 additions & 0 deletions tests/fixtures/author_prepend/expected.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
38 changes: 38 additions & 0 deletions tests/fixtures/author_prepend/src.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
16 changes: 16 additions & 0 deletions tests/fixtures/author_prepend/update.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
1 change: 1 addition & 0 deletions tests/fixtures/author_prepend_and_typo/description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update typo in author plus adding a new record should preserve affiliations.
Loading