Skip to content

Commit 7e9c698

Browse files
Merge pull request #118 from NatLibFi/EKIRJASTO-132-Fix-import-fail-with-empty-string
Ekirjasto 132 fix import fail with empty string
2 parents c4b095c + 715547d commit 7e9c698

3 files changed

Lines changed: 84 additions & 8 deletions

File tree

core/opds2_import.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,8 @@ def _extract_contributors(
438438
roles=contributor.roles if contributor.roles else default_role,
439439
)
440440
# If the feed is missing contributor name information, record the information to our metadata
441-
if (
442-
contributor_metadata.sort_name is None
443-
and contributor_metadata.display_name is None
441+
if not (
442+
contributor_metadata.sort_name or contributor_metadata.display_name
444443
):
445444
contributor_metadata.sort_name = Edition.UNKNOWN_AUTHOR
446445
contributor_metadata.display_name = Edition.UNKNOWN_AUTHOR

tests/core/files/opds2/feed.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,76 @@
275275
"width": 800
276276
}
277277
]
278+
},
279+
{
280+
"metadata": {
281+
"@type": "http://schema.org/Book",
282+
"title": "Test Book with author empty string",
283+
"author": {
284+
"name": ""
285+
},
286+
"description": "Test Book description with author empty string",
287+
"identifier": "urn:isbn:978-0-06-112008-4",
288+
"language": [
289+
"eng"
290+
],
291+
"publisher": {
292+
"name": "Test Publisher"
293+
},
294+
"published": "2014-09-28T00:00:00Z",
295+
"modified": "2015-09-29T17:00:00Z",
296+
"subject": [
297+
{
298+
"scheme": "http://schema.org/audience",
299+
"code": "juvenile-fiction",
300+
"name": "Juvenile Fiction",
301+
"links": []
302+
}
303+
]
304+
},
305+
"links": [
306+
{
307+
"type": "application/opds-publication+json",
308+
"rel": "http://opds-spec.org/acquisition/borrow",
309+
"href": "http://example.org/huckleberry-finn",
310+
"properties": {
311+
"availability": {
312+
"state": "available"
313+
},
314+
"indirectAcquisition": [
315+
{
316+
"type": "application/vnd.adobe.adept+xml",
317+
"child": [
318+
{
319+
"type": "application/epub+zip"
320+
}
321+
]
322+
},
323+
{
324+
"type": "application/vnd.readium.lcp.license.v1.0+json",
325+
"child": [
326+
{
327+
"type": "application/epub+zip"
328+
}
329+
]
330+
}
331+
]
332+
}
333+
},
334+
{
335+
"rel": "http://opds-spec.org/acquisition/sample",
336+
"type": "application/epub+zip",
337+
"href": "https://example.com/medias/e5/318061475b11cf8c8e3752da2a1cf68384d8bf.epub"
338+
}
339+
],
340+
"images": [
341+
{
342+
"href": "http://example.org/cover.jpg",
343+
"type": "image/jpeg",
344+
"height": 1400,
345+
"width": 800
346+
}
347+
]
278348
}
279349
]
280350
}

tests/core/test_opds2_import.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class TestOPDS2Importer(OPDS2Test):
123123
"urn:librarysimplified.org/terms/id/ProQuest%20Doc%20ID/181639"
124124
)
125125
BOOK_WITHOUT_AUTHOR_IDENTIFIER = "urn:isbn:9789523565593"
126+
BOOK_AUTHOR_EMPTY_STRING_IDENTIFIER = "urn:isbn:978-0-06-112008-4"
126127

127128
@pytest.mark.parametrize(
128129
"name,manifest_type",
@@ -164,7 +165,7 @@ def test_opds2_importer_correctly_imports_valid_opds2_feed(
164165

165166
# 1. Make sure that editions contain all required metadata
166167
assert isinstance(imported_editions, list)
167-
assert 4 == len(imported_editions)
168+
assert 5 == len(imported_editions)
168169

169170
# 1.1. Edition with open-access links (Moby-Dick)
170171
moby_dick_edition = self._get_edition_by_identifier(
@@ -258,7 +259,7 @@ def test_opds2_importer_correctly_imports_valid_opds2_feed(
258259

259260
# 2. Make sure that license pools have correct configuration
260261
assert isinstance(pools, list)
261-
assert 4 == len(pools)
262+
assert 5 == len(pools)
262263

263264
# 2.1. Edition with open-access links (Moby-Dick)
264265
moby_dick_license_pool = self._get_license_pool_by_identifier(
@@ -365,7 +366,7 @@ def test_opds2_importer_correctly_imports_valid_opds2_feed(
365366

366367
# 3. Make sure that work objects contain all the required metadata
367368
assert isinstance(works, list)
368-
assert 4 == len(works)
369+
assert 5 == len(works)
369370

370371
# 3.1. Work (Moby-Dick)
371372
moby_dick_work = self._get_work_by_identifier(
@@ -390,7 +391,7 @@ def test_opds2_importer_correctly_imports_valid_opds2_feed(
390391
== huckleberry_finn_work.summary_text
391392
)
392393

393-
# 4.1 Author name is null
394+
# 4.1 Author name is null or empty string
394395
edition_author_null = self._get_edition_by_identifier(
395396
imported_editions, self.BOOK_WITHOUT_AUTHOR_IDENTIFIER
396397
)
@@ -408,6 +409,12 @@ def test_opds2_importer_correctly_imports_valid_opds2_feed(
408409
assert isinstance(book_without_author, Work)
409410
assert "[Unknown]" == book_without_author.author
410411

412+
edition_author_empty_string = self._get_edition_by_identifier(
413+
imported_editions, self.BOOK_AUTHOR_EMPTY_STRING_IDENTIFIER
414+
)
415+
assert isinstance(edition_author_empty_string, Edition)
416+
assert "[Unknown]" == edition_author_empty_string.author
417+
411418
@pytest.mark.parametrize(
412419
"this_identifier_type,ignore_identifier_type,identifier",
413420
[
@@ -473,7 +480,7 @@ def test_opds2_importer_skips_publications_with_unsupported_identifier_types(
473480
assert isinstance(imported_editions, list)
474481

475482
if this_identifier_type == IdentifierType.ISBN:
476-
assert 2 == len(imported_editions)
483+
assert 3 == len(imported_editions)
477484
assert (
478485
imported_editions[0].primary_identifier.type
479486
== this_identifier_type.value

0 commit comments

Comments
 (0)