Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hep: add material to FFT for CDS #291

Merged
merged 1 commit into from
Dec 11, 2023
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
5 changes: 4 additions & 1 deletion inspire_dojson/hep/rules/bdFFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ def _get_hidden(value):
return None

def _get_filename_and_extension(value):
return os.path.splitext(value.get('filename', value['key']))
file_name, extension = os.path.splitext(value.get('filename', value['key']))
if file_name == "document" and value.get("material", "publication") != "publication":
file_name = value["material"]
return file_name, extension

file_name, extension = _get_filename_and_extension(value)

Expand Down
63 changes: 63 additions & 0 deletions tests/test_hep_bdFFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,69 @@ def test_documents_to_FFT_uses_filename():
assert expected == result['FFT']


def test_documents_to_FFT_uses_material_as_filename_fallback():
schema = load_schema('hep')
subschema = schema['properties']['documents']

snippet = {
"documents": [
{
"key": "8f09853e5bc12d6d077ba0833e97626e",
"url": "https://inspirehep.net/files/8f09853e5bc12d6d077ba0833e97626e",
"source": "Springer",
"fulltext": True,
"filename": "document",
"material": "addendum",
},
{
"key": "35715635c16bc869b4995e150b140bf8",
"url": "https://inspirehep.net/files/35715635c16bc869b4995e150b140bf8",
"hidden": True,
"source": "arxiv",
"filename": "2103.11769.pdf",
"fulltext": True,
"material": "preprint",
"original_url": "http://export.arxiv.org/pdf/2103.11769",
},
{
"key": "277ff3946ce757cba86a4ab4ebb95287",
"url": "https://inspirehep.net/files/277ff3946ce757cba86a4ab4ebb95287",
"filename": "document",
"fulltext": True,
"material": "publication",
}
],
} # literature/1852846

expected = [
{
"a": "https://inspirehep.net/files/8f09853e5bc12d6d077ba0833e97626e",
"d": "Fulltext",
"n": "addendum",
"t": "Springer",
},
{
"a": "https://inspirehep.net/files/35715635c16bc869b4995e150b140bf8",
"d": "Fulltext",
"n": "2103.11769",
"t": "arXiv",
"f": ".pdf",
},
{
"a": "https://inspirehep.net/files/277ff3946ce757cba86a4ab4ebb95287",
"d": "Fulltext",
"n": "document",
"t": "INSPIRE-PUBLIC",
}
]

assert validate(snippet['documents'], subschema) is None

result = hep2marc.do(snippet)

assert expected == result['FFT']


def test_figures_to_FFT():
schema = load_schema('hep')
subschema = schema['properties']['figures']
Expand Down
Loading