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

Add book section serialization to bibtex #1921

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions invenio_rdm_records/resources/serializers/bibtex/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
54 changes: 53 additions & 1 deletion tests/resources/serializers/test_bibtex_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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.
Expand Down
Loading