diff --git a/invenio_rdm_records/resources/serializers/bibtex/schema.py b/invenio_rdm_records/resources/serializers/bibtex/schema.py index e80f2aa28..88eb1406c 100644 --- a/invenio_rdm_records/resources/serializers/bibtex/schema.py +++ b/invenio_rdm_records/resources/serializers/bibtex/schema.py @@ -52,6 +52,10 @@ class BibTexSchema(BaseSerializerSchema, CommonFieldsMixin): BibTexFormatter.book, BibTexFormatter.booklet, ], + "publication-section": [ + BibTexFormatter.in_collection, + BibTexFormatter.in_book, + ], "publication-article": [BibTexFormatter.article], "publication-preprint": [BibTexFormatter.unpublished], "publication-thesis": [BibTexFormatter.thesis], diff --git a/tests/resources/serializers/test_bibtex_serializer.py b/tests/resources/serializers/test_bibtex_serializer.py index 5d2d54610..ac6e76f05 100644 --- a/tests/resources/serializers/test_bibtex_serializer.py +++ b/tests/resources/serializers/test_bibtex_serializer.py @@ -86,7 +86,6 @@ def test_bibtex_serializer_full_record(running_app, updated_full_record): [ ("publication"), ("publication-annotationcollection"), - ("publication-section"), ("publication-conferenceproceeding"), ("publication-datamanagementplan"), ("publication-journal"), @@ -195,6 +194,59 @@ def test_serialize_publication_conferencepaper(running_app, updated_minimal_reco ] ) +def test_serialize_publication_booksection(running_app, updated_minimal_record): + """Test bibtex formatter for a section of a book. + + It serializes into `incollection` based on + + - incollection + - inbook + """ + updated_minimal_record["metadata"]["resource_type"][ + "id" + ] = "publication-section" + + # Force serialization into 'inproceedings' + updated_minimal_record.update( + {"custom_fields": {"imprint:imprint": {"title": "book title"}}} + ) + serializer = BibtexSerializer() + serialized_record = serializer.serialize_object(updated_minimal_record) + + expected_data = "\n".join( + [ + "@incollection{brown_2023_abcde-fghij,", + " author = {Name and", + " Troy Inc.},", + " title = {A Romans story},", + " booktitle = {book title},", + " year = 2023,", + " publisher = {Acme Inc},", + " month = mar,", + "}", + ] + ) + + assert serialized_record == expected_data + + # Force serialization into 'inbook' + del updated_minimal_record["custom_fields"]["imprint:imprint"] + serialized_record = serializer.serialize_object(updated_minimal_record) + + expected_data = "\n".join( + [ + "@inbook{brown_2023_abcde-fghij,", + " author = {Name and", + " Troy Inc.},", + " title = {A Romans story},", + " year = 2023,", + " publisher = {Acme Inc},", + " month = mar,", + "}", + ] + ) + + assert serialized_record == expected_data def test_serialize_publication_book(running_app, updated_minimal_record): """Test bibtex formatter for books.