Skip to content

Commit

Permalink
tests: importer: Add test for importing audiobook for existing document
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 authored and kpsherva committed May 13, 2024
1 parent ff5bf8e commit 6beecc5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/importer/data/existing_documents.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
20 changes: 20 additions & 0 deletions tests/importer/data/existing_eitems.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
37 changes: 37 additions & 0 deletions tests/importer/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6beecc5

Please sign in to comment.