Skip to content

Commit

Permalink
Merge pull request #473 from PascalEgn/add_creation_date_to_builder
Browse files Browse the repository at this point in the history
data: add creation_date to the Data builder
  • Loading branch information
PascalEgn authored Dec 9, 2024
2 parents 19daa19 + 10ed419 commit 85292b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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

0 comments on commit 85292b1

Please sign in to comment.