Skip to content

Commit

Permalink
importer: Fix Audiobook updating test
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 authored and kpsherva committed May 28, 2024
1 parent 80da1e7 commit 657dd39
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cds_ils/importer/documents/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _update_field_alternative_identifiers(self, matched_document):
@staticmethod
def _normalize_title(title):
"""Return a normalized title."""
t = " ".join(title.lower().split())
t = " ".join((title or "").lower().split())
return t.strip()

def update_document(self, matched_document):
Expand Down
2 changes: 2 additions & 0 deletions cds_ils/importer/eitems/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def _apply_url_login(self, eitem):
def eitems_search(self, matched_document):
"""Search items for given document."""
document_pid = matched_document["pid"]
print(self.eitem_json.get("_type", "E-BOOK").upper())

# get eitems for current provider
search = get_eitems_for_document_by_provider(
Expand All @@ -236,6 +237,7 @@ def import_eitem_action(self, search):
"""Determine import action."""
# If found more than 0 then update for the same type & provider, if eitem with same type & provider isn't found then do create
hits_count = search.count()
print(hits_count)
if hits_count == 1:
self.action = "update"
elif hits_count == 0:
Expand Down
2 changes: 1 addition & 1 deletion cds_ils/importer/series/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _update_field_identifiers(self, matched_series, json_series):
@staticmethod
def _normalize_title(title):
"""Return a normalized title."""
t = " ".join(title.lower().split())
t = " ".join((title or "").lower().split())
# remove `series` or `ser` at the end of the title
# `International Series of Numerical Mathematics series`
# or `International series of Numerical mathematics ser`
Expand Down
18 changes: 5 additions & 13 deletions tests/importer/data/documents_with_audiobook.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,24 @@
}
]
},
"abstract": "This is an abstract that you understand.",
"abstract": "Check if existing audiobook gets updated if providers are same",
"agency_code": "OCoLC",
"alternative_identifiers": [
{ "scheme": "SAFARI", "value": "on1417409123" }
],
"authors": [
{
"full_name": "Bros, Warner",
"roles": ["AUTHOR"],
"type": "ORGANISATION"
}
],
"authors": [{ "full_name": "Doe, John" }],
"document_type": "BOOK",
"edition": "1st",
"identifiers": [
{ "material": "AUDIOBOOK", "scheme": "ISBN", "value": "9781663731913" },
{ "material": "AUDIOBOOK", "scheme": "ISBN", "value": "1663731918" }
{ "material": "AUDIOBOOK", "scheme": "ISBN", "value": "9999999999" }
],
"imprint": {
"place": "Place of publication not known",
"publisher": "Descent Audio"
},
"keywords": [
{ "source": "SAFARI", "value": "Abstracts" },
{ "source": "SAFARI", "value": "Books" },
{ "source": "SAFARI", "value": "Self-care, Health" }
{ "source": "SAFARI", "value": "Books" }
],
"languages": ["ENG"],
"provider_recid": "on1417409123",
Expand All @@ -87,6 +79,6 @@
{ "scheme": "LOC", "value": "GF575.B6" },
{ "scheme": "DEWEY", "value": "222.4/6" }
],
"title": "Understanding abstracts"
"title": "New Book: Test Audiobook Updating"
}
]
15 changes: 15 additions & 0 deletions tests/importer/data/existing_documents.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,20 @@
"publication_year": "2024",
"identifiers": [{ "scheme": "ISBN", "value": "9876543210" }],
"title": "Understanding abstracts"
},
{
"$schema": "https://127.0.0.1:5000/schemas/documents/document-v1.0.0.json",
"created_by": { "type": "script", "value": "test" },
"pid": "docid-11",
"title": "New Book: Test Audiobook Updating",
"authors": [{ "full_name": "Frank Bidart" }],
"abstract": "This is an abstract",
"edition": "3",
"identifiers": [
{ "material": "AUDIOBOOK", "scheme": "ISBN", "value": "9999999999" }
],
"keywords": [{ "source": "X", "value": "Patata" }],
"document_type": "BOOK",
"publication_year": "1950"
}
]
21 changes: 21 additions & 0 deletions tests/importer/data/existing_eitems.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,26 @@
"login_required": false
}
]
},
{
"pid": "eitemid-11",
"created_by": {"type": "import", "value": "safari"},
"document_pid": "docid-11",
"eitem_type": "AUDIOBOOK",
"internal_notes": "AUDIOBOOK TO MODIFY",
"description": "Description of the electronic item",
"open_access": false,
"urls": [
{
"description": "Protected URL",
"value": "http://protected-cds-ils.ch/",
"login_required": true
},
{
"description": "Another open URL",
"value": "http://cds-ils.ch/",
"login_required": false
}
]
}
]
10 changes: 6 additions & 4 deletions tests/importer/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ def test_import_update_existing_audiobook(importer_test_data):

updated_document = document_cls.get_record_by_pid(report["document_json"]["pid"])
time.sleep(1)
search = eitem_search_cls().search_by_document_pid(
document_pid=updated_document["pid"]
search = (
eitem_search_cls()
.search_by_document_pid(document_pid=updated_document["pid"])
.filter("term", eitem_type="AUDIOBOOK")
)
results = search.execute()
assert results.hits.total.value == 1

created_eitem_pid = results.hits[0].pid
eitem = eitem_cls.get_record_by_pid(created_eitem_pid)
updated_eitem_pid = results.hits[0].pid
eitem = eitem_cls.get_record_by_pid(updated_eitem_pid)

assert eitem["document_pid"] == updated_document["pid"]
assert eitem["eitem_type"] == "AUDIOBOOK"
Expand Down

0 comments on commit 657dd39

Please sign in to comment.