Skip to content

Commit

Permalink
importer: Populate eitem_type in EItem object
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 authored and kpsherva committed May 13, 2024
1 parent 3cbdd4b commit 25197d5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions cds_ils/importer/eitems/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def _build_eitem_json(self, eitem_json, document_pid, urls=None, description=Non
eitem_json.update(
dict(
document_pid=document_pid,
eitem_type=self.eitem_json.get("_type", "E-BOOK").upper(),
open_access=self.open_access,
identifiers=dois,
urls=self.eitem_json.get("urls", []),
Expand Down
9 changes: 9 additions & 0 deletions tests/importer/data/existing_eitems.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"pid": "eitemid-1",
"created_by": {"type": "script", "value": "test"},
"document_pid": "docid-2",
"eitem_type": "E-BOOK",
"internal_notes": "An internal note",
"description": "Description of the electronic item",
"open_access": true
Expand All @@ -11,6 +12,7 @@
"pid": "eitemid-2",
"created_by": {"type": "script", "value": "test"},
"document_pid": "docid-2",
"eitem_type": "E-BOOK",
"internal_notes": "An internal note",
"description": "Description of the electronic item",
"open_access": false,
Expand All @@ -31,6 +33,7 @@
"pid": "eitemid-3",
"created_by": {"type": "import", "value": "springer"},
"document_pid": "docid-3",
"eitem_type": "E-BOOK",
"internal_notes": "EITEM TO MODIFY",
"description": "Description of the electronic item",
"open_access": false,
Expand All @@ -51,6 +54,7 @@
"pid": "eitemid-4",
"created_by": {"type": "import", "value": "ebl"},
"document_pid": "docid-1",
"eitem_type": "E-BOOK",
"internal_notes": "An internal note",
"description": "Description of the electronic item",
"open_access": false,
Expand All @@ -71,6 +75,7 @@
"pid": "eitemid-6",
"created_by": {"type": "import", "value": "ebl"},
"document_pid": "docid-6",
"eitem_type": "E-BOOK",
"internal_notes": "An internal note",
"description": "Description of the electronic item",
"open_access": false,
Expand All @@ -91,6 +96,7 @@
"pid": "eitemid-6A",
"created_by": {"type": "import", "value": "safari"},
"document_pid": "docid-6A",
"eitem_type": "E-BOOK",
"internal_notes": "An internal note",
"description": "Description of the electronic item",
"open_access": false,
Expand All @@ -111,6 +117,7 @@
"pid": "eitemid-7",
"created_by": {"type": "import", "value": "springer"},
"document_pid": "docid-7",
"eitem_type": "E-BOOK",
"internal_notes": "An internal note",
"description": "Description of the electronic item",
"open_access": false,
Expand All @@ -131,6 +138,7 @@
"pid": "eitemid-8",
"created_by": {"type": "user", "value": "1"},
"document_pid": "docid-8",
"eitem_type": "E-BOOK",
"internal_notes": "An internal note",
"description": "Description of the electronic item",
"open_access": false,
Expand All @@ -151,6 +159,7 @@
"pid": "eitemid-9",
"created_by": {"type": "user", "value": "1"},
"document_pid": "docid-9",
"eitem_type": "AUDIOBOOK",
"internal_notes": "An internal note",
"description": "Description of the electronic item",
"open_access": false,
Expand Down
2 changes: 2 additions & 0 deletions tests/importer/data/modify_document_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{"scheme": "ISBN", "value": "0987654321"}],
"_eitem": {
"pid": "eitmid-1",
"eitem_type": "E-BOOK",
"created_by": {"type": "script", "value": "springer"},
"internal_notes": "Modified",
"description": "Modified description",
Expand Down Expand Up @@ -47,6 +48,7 @@
"identifiers": [{ "scheme": "ISBN", "value": "0123456789" }],
"_eitem": {
"pid": "eitmid-1",
"eitem_type": "E-BOOK",
"created_by": {"type": "script", "value": "springer"},
"document_pid": "docid-1",
"internal_notes": "Modified",
Expand Down
9 changes: 9 additions & 0 deletions tests/importer/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_import_audiobook_with_existing_ebook(importer_test_data):
eitem = eitem_cls.get_record_by_pid(created_eitem_pid)

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

assert "_eitem" not in updated_document
assert "agency_code" not in updated_document
Expand Down Expand Up @@ -100,10 +101,14 @@ def test_import_documents(app, db):
eitem = eitem_cls.get_record_by_pid(eitem_pid)

assert eitem["document_pid"] == document["pid"]
assert eitem["eitem_type"] == "E-BOOK"

assert "_eitem" not in document
assert "agency_code" not in document

for urls in eitem["urls"]:
urls["description"] == "e-book"

assert eitem["created_by"] == {"type": "import", "value": "springer"}
assert document["created_by"] == {"type": "import", "value": "springer"}

Expand Down Expand Up @@ -211,11 +216,15 @@ def test_import_audiobook(app, db):
eitem = eitem_cls.get_record_by_pid(eitem_pid)

assert eitem["document_pid"] == created_document["pid"]
assert eitem["eitem_type"] == "AUDIOBOOK"

assert "_eitem" not in created_document
assert "agency_code" not in created_document
assert "identifiers" in created_document

for urls in eitem["urls"]:
urls["description"] == "audiobook"

for isbn in created_document["identifiers"]:
assert isbn["material"] == "AUDIOBOOK"

Expand Down

0 comments on commit 25197d5

Please sign in to comment.