From 6beecc57545a6c56914c644f3a982d0cf59dfec5 Mon Sep 17 00:00:00 2001 From: Saksham Arora Date: Mon, 8 Apr 2024 10:57:07 +0200 Subject: [PATCH] tests: importer: Add test for importing audiobook for existing document --- tests/importer/data/existing_documents.json | 23 +++++++++++++ tests/importer/data/existing_eitems.json | 20 +++++++++++ tests/importer/test_importer.py | 37 +++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/tests/importer/data/existing_documents.json b/tests/importer/data/existing_documents.json index f2ed40518..f00b70241 100644 --- a/tests/importer/data/existing_documents.json +++ b/tests/importer/data/existing_documents.json @@ -154,5 +154,28 @@ "abstract": "This is a document volume v.1 part of a MULTIPART MONOGRAPH", "document_type": "BOOK", "publication_year": "1950" + }, + { + "$schema": "https://127.0.0.1:5000/schemas/documents/document-v1.0.0.json", + "created_by": { "type": "user", "value": "1" }, + "pid": "docid-9", + "abstract": "Make anxiety work for you. Work is stressful: We race to meet deadlines. We extend ourselves to return favors for colleagues. We set ambitious goals for ourselves and our teams. We measure ourselves against metrics, our competitors, and sometimes, our colleagues. Some of us even go beyond tangible metrics to internalize stress and fear of missing the mark-ruminating over presentations that didn't go according to plan, imagining worst-case scenarios, or standing frozen, paralyzed by perfectionism. But hypervigilance, worry, and catastrophizing don't have to hold you back at work. When channeled thoughtfully, anxiety can motivate us to be more resourceful, productive, and creative. It can break down barriers and create new bonds with our colleagues. Managing Your Anxiety will help you distinguish stress from anxiety, learn what anxiety looks like for you, understand it, and respond to it with self-compassion at work. With the latest psychological research and practical advice from leading experts, you'll learn how to recognize how your anxiety manifests itself; manage it in small, day-to-day moments and in more challenging times; experiment and find a mindfulness practice that works for you; and build a support infrastructure to help you manage your anxiety over the long term.", + "authors": [ + { "full_name": "Marvel, Steve", "roles": ["AUTHOR"], "type": "PERSON" }, + { "full_name": "Schnaubelt, Teri", "roles": ["AUTHOR"], "type": "PERSON" } + ], + "document_type": "BOOK", + "edition": "1st", + "alternative_identifiers": [ + { "scheme": "SAFARI", "value": "on1417409648" } + ], + "imprint": { + "place": "Place of publication not identified", + "publisher": "Ascent Audio" + }, + "languages": ["ENG"], + "publication_year": "2024", + "title": "Managing your anxiety", + "note": "ADD AUDIOBOOK TO DOC WITH AN EXISTING E-ITEM" } ] diff --git a/tests/importer/data/existing_eitems.json b/tests/importer/data/existing_eitems.json index e07b75837..d99943521 100644 --- a/tests/importer/data/existing_eitems.json +++ b/tests/importer/data/existing_eitems.json @@ -146,5 +146,25 @@ "login_required": false } ] + }, + { + "pid": "eitemid-9", + "created_by": {"type": "user", "value": "1"}, + "document_pid": "docid-9", + "internal_notes": "An internal note", + "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 + } + ] } ] diff --git a/tests/importer/test_importer.py b/tests/importer/test_importer.py index 9070de048..28a54ec88 100644 --- a/tests/importer/test_importer.py +++ b/tests/importer/test_importer.py @@ -42,6 +42,43 @@ def test_modify_documents(importer_test_data): assert updated_eitem["description"] == "Modified description" +def test_import_audiobook_with_existing_ebook(importer_test_data): + document_cls = current_app_ils.document_record_cls + eitem_cls = current_app_ils.eitem_record_cls + eitem_search_cls = current_app_ils.eitem_search_cls + + # Import an audiobook for a document with an existing ebook + json_data = load_json_from_datadir( + "documents_with_audiobook.json", relpath="importer" + ) + importer = Importer(json_data[0], "safari") + + report = importer.import_record() + assert report["action"] == "update" + + 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"] + ) + results = search.execute() + assert results.hits.total.value == 2 + + created_eitem_pid = results.hits[1].pid + eitem = eitem_cls.get_record_by_pid(created_eitem_pid) + + assert eitem["document_pid"] == updated_document["pid"] + + assert "_eitem" not in updated_document + assert "agency_code" not in updated_document + assert "identifiers" in updated_document + + for isbn in updated_document["identifiers"]: + assert isbn["material"] == "AUDIOBOOK" + + assert eitem["created_by"] == {"type": "import", "value": "safari"} + + def test_import_documents(app, db): document_cls = current_app_ils.document_record_cls eitem_search_cls = current_app_ils.eitem_search_cls