From 10ed419dd91493b978c50ebdf499a9d3511398da Mon Sep 17 00:00:00 2001 From: PascalEgn Date: Mon, 9 Dec 2024 13:39:30 +0100 Subject: [PATCH] data: add creation_date to the Data builder --- inspire_schemas/builders/data.py | 10 ++++++++++ tests/integration/test_builders.py | 5 ++++- tests/unit/test_data_builder.py | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/inspire_schemas/builders/data.py b/inspire_schemas/builders/data.py index 6aa1b84e..7e1f9c0d 100644 --- a/inspire_schemas/builders/data.py +++ b/inspire_schemas/builders/data.py @@ -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 @@ -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. diff --git a/tests/integration/test_builders.py b/tests/integration/test_builders.py index fb6213a8..09adccf4 100644 --- a/tests/integration/test_builders.py +++ b/tests/integration/test_builders.py @@ -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'], @@ -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']) diff --git a/tests/unit/test_data_builder.py b/tests/unit/test_data_builder.py index 1c3bd8a3..fb39cb7f 100644 --- a/tests/unit/test_data_builder.py +++ b/tests/unit/test_data_builder.py @@ -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()