Skip to content

Commit

Permalink
EKIRJASTO-132 Add testcase for empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
natlibfi-kaisa committed Nov 21, 2024
1 parent 8acdb74 commit f412bde
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
70 changes: 70 additions & 0 deletions tests/core/files/opds2/feed.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,76 @@
"width": 800
}
]
},
{
"metadata": {
"@type": "http://schema.org/Book",
"title": "Test Book with author empty string",
"author": {
"name": ""
},
"description": "Test Book description with author empty string",
"identifier": "urn:isbn:978-0-06-112008-4",
"language": [
"eng"
],
"publisher": {
"name": "Test Publisher"
},
"published": "2014-09-28T00:00:00Z",
"modified": "2015-09-29T17:00:00Z",
"subject": [
{
"scheme": "http://schema.org/audience",
"code": "juvenile-fiction",
"name": "Juvenile Fiction",
"links": []
}
]
},
"links": [
{
"type": "application/opds-publication+json",
"rel": "http://opds-spec.org/acquisition/borrow",
"href": "http://example.org/huckleberry-finn",
"properties": {
"availability": {
"state": "available"
},
"indirectAcquisition": [
{
"type": "application/vnd.adobe.adept+xml",
"child": [
{
"type": "application/epub+zip"
}
]
},
{
"type": "application/vnd.readium.lcp.license.v1.0+json",
"child": [
{
"type": "application/epub+zip"
}
]
}
]
}
},
{
"rel": "http://opds-spec.org/acquisition/sample",
"type": "application/epub+zip",
"href": "https://example.com/medias/e5/318061475b11cf8c8e3752da2a1cf68384d8bf.epub"
}
],
"images": [
{
"href": "http://example.org/cover.jpg",
"type": "image/jpeg",
"height": 1400,
"width": 800
}
]
}
]
}
15 changes: 11 additions & 4 deletions tests/core/test_opds2_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class TestOPDS2Importer(OPDS2Test):
"urn:librarysimplified.org/terms/id/ProQuest%20Doc%20ID/181639"
)
BOOK_WITHOUT_AUTHOR_IDENTIFIER = "urn:isbn:9789523565593"
BOOK_AUTHOR_EMPTY_STRING_IDENTIFIER = "urn:isbn:978-0-06-112008-4"

@pytest.mark.parametrize(
"name,manifest_type",
Expand Down Expand Up @@ -164,7 +165,7 @@ def test_opds2_importer_correctly_imports_valid_opds2_feed(

# 1. Make sure that editions contain all required metadata
assert isinstance(imported_editions, list)
assert 4 == len(imported_editions)
assert 5 == len(imported_editions)

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

# 2. Make sure that license pools have correct configuration
assert isinstance(pools, list)
assert 4 == len(pools)
assert 5 == len(pools)

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

# 3. Make sure that work objects contain all the required metadata
assert isinstance(works, list)
assert 4 == len(works)
assert 5 == len(works)

# 3.1. Work (Moby-Dick)
moby_dick_work = self._get_work_by_identifier(
Expand All @@ -390,7 +391,7 @@ def test_opds2_importer_correctly_imports_valid_opds2_feed(
== huckleberry_finn_work.summary_text
)

# 4.1 Author name is null
# 4.1 Author name is null or empty string
edition_author_null = self._get_edition_by_identifier(
imported_editions, self.BOOK_WITHOUT_AUTHOR_IDENTIFIER
)
Expand All @@ -408,6 +409,12 @@ def test_opds2_importer_correctly_imports_valid_opds2_feed(
assert isinstance(book_without_author, Work)
assert "[Unknown]" == book_without_author.author

edition_author_empty_string = self._get_edition_by_identifier(
imported_editions, self.BOOK_AUTHOR_EMPTY_STRING_IDENTIFIER
)
assert isinstance(edition_author_empty_string, Edition)
assert "[Unknown]" == edition_author_empty_string.author

@pytest.mark.parametrize(
"this_identifier_type,ignore_identifier_type,identifier",
[
Expand Down

0 comments on commit f412bde

Please sign in to comment.