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

data: add creation_date to the Data builder #473

Merged
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
10 changes: 10 additions & 0 deletions inspire_schemas/builders/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import warnings

import idutils
from inspire_utils.date import normalize_date
from six import python_2_unicode_compatible, text_type

from inspire_schemas.builders.builder import RecordBuilder
Expand Down Expand Up @@ -92,6 +93,15 @@ def add_abstract(self, abstract, source=None):
),
)

@filter_empty_parameters
def add_creation_date(self, date=None):
"""
Args:
date (str)
"""
if date is not None:
self.record['creation_date'] = normalize_date(date)

@filter_empty_parameters
def add_accelerator_experiments_legacy_name(self, legacy_name):
"""Add legacy name in accelerator experiment.
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ def test_data_builder(data_data):
'control_number': data_data['control_number'],
'deleted': data_data['deleted'],
'deleted_records': data_data['deleted_records'],
'creation_date': data_data['creation_date'],
'legacy_version': data_data['legacy_version'],
'new_record': data_data['new_record'],
'self': data_data['self'],
Expand All @@ -460,6 +459,10 @@ def test_data_builder(data_data):
builder.add_doi(doi['value'], doi['source'], doi['material'])
assert builder.record['dois'] == dois

creation_date = data_data['creation_date']
builder.add_creation_date(creation_date)
assert builder.record['creation_date'] == creation_date

collaborations = data_data['collaborations']
for collaboration in collaborations:
builder.add_collaboration(collaboration['value'])
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_data_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def test_add_title():
]
assert result == expected

def test_add_creation_date():
builder = DataBuilder()
creation_date = "2020-01-01"
builder.add_creation_date(creation_date)
result = builder.record.get("creation_date")
assert result == creation_date

def test_add_doi():
builder = DataBuilder()
Expand Down