From 94f50a0c749fbdb36daf33d1e4098e6664eb9d23 Mon Sep 17 00:00:00 2001 From: Tomek Date: Mon, 10 Apr 2023 08:45:13 -0400 Subject: [PATCH] Electronic books genre removal (#41) * removes adding "Electronic books" & "Electronic audiobooks" genre terms * version bump to 0.4.0 --- README.md | 9 +++++-- nightshift/__init__.py | 2 +- nightshift/marc/marc_writer.py | 37 +--------------------------- pyproject.toml | 2 +- tests/unit/test_marc_writer.py | 45 +++++++++++++++++++++++++--------- tests/unit/test_nightshift.py | 2 +- tests/unit/test_tasks.py | 4 +-- tests/unit/test_worldcat.py | 6 ++--- 8 files changed, 50 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 8e60f4e..a0862b4 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ More info: [Sierra Scheduler configuration](https://github.com/BookOps-CAT/NightShift/blob/main/docs/sierra.md) | [WorldCat record matching](https://github.com/BookOps-CAT/NightShift/blob/main/docs/matching.md) | [Record manipulation](https://github.com/BookOps-CAT/NightShift/blob/main/docs/manipulating.md) | [Sierra loading instructions](https://github.com/BookOps-CAT/NightShift/blob/main/docs/loading.md) ## Version -> 0.3.0 +> 0.4.0 ## Local Installation & Usage @@ -61,6 +61,10 @@ If a good match in WorldCat has been found, the bot manipulates the downloaded f If for any reason the execution of the routine is interrupted (API error, etc.), the process can be restarted using `run [local, prod]` command again. The bot will pick up exactly where it left. ## Changelog +[0.4.0] - 2023-10-04 +### Changed ++ "Electronic books" and "Electronic audiobooks" local terms no longer added + [0.3.0] - 2023-04-05 ### Security + Main dependency update: @@ -103,4 +107,5 @@ If for any reason the execution of the routine is interrupted (API error, etc.), + [GMGPC terms](https://www.loc.gov/rr/print/tgm2/) in subject headings are no longer accepted [0.2.0]: https://github.com/BookOps-CAT/NightShift/compare/0.1.0...0.2.0 -[0.3.0]: https://github.com/BookOps-CAT/NightShift/compare/0.2.0...0.3.0 \ No newline at end of file +[0.3.0]: https://github.com/BookOps-CAT/NightShift/compare/0.2.0...0.3.0 +[0.4.0]: https://github.com/BookOps-CAT/NightShift/compare/0.3.0...0.4.0 \ No newline at end of file diff --git a/nightshift/__init__.py b/nightshift/__init__.py index 1fbe1e3..6010d11 100644 --- a/nightshift/__init__.py +++ b/nightshift/__init__.py @@ -1,2 +1,2 @@ -__version__ = "0.3.0" +__version__ = "0.4.0" __title__ = "NightShift" diff --git a/nightshift/marc/marc_writer.py b/nightshift/marc/marc_writer.py index 8607963..0b08efd 100644 --- a/nightshift/marc/marc_writer.py +++ b/nightshift/marc/marc_writer.py @@ -254,32 +254,13 @@ def _add_command_tag(self) -> None: def _add_genre_tags(self) -> None: """ Adds genre tags to e-resources. - - Occasionally genre terms may be recorded in 650 tag in Worldcat records - and it is safer to remove all and add 655 from scratch. """ try: resource_cat = self._res_cat[self.resource.resourceCategoryId].name except KeyError: resource_cat = None - if resource_cat == "ebook": - found = False - for field in self.bib.subjects(): - if "electronic books." in field.value().lower(): - found = True - break - if not found: - self.bib.add_field( - Field( - tag="655", - indicators=[" ", "0"], - subfields=["a", "Electronic books."], - ) - ) - logger.debug("Added 'Electronic books' genre to 655 tag.") - - elif resource_cat == "eaudio": + if resource_cat == "eaudio": # 'Audiobooks' term found = False @@ -297,22 +278,6 @@ def _add_genre_tags(self) -> None: ) logger.debug("Added 'Audiobooks' genre to 655 tag.") - # 'Electronic audiobooks' term - found = False - for field in self.bib.subjects(): - if "electronic audiobooks." in field.value().lower(): - found = True - break - if not found: - self.bib.add_field( - Field( - tag="655", - indicators=[" ", "7"], - subfields=["a", "Electronic audiobooks.", "2", "local"], - ) - ) - logger.debug("Added 'Electronic audiobooks' genre to 655 tags.") - elif resource_cat == "evideo": found = False for field in self.bib.subjects(): diff --git a/pyproject.toml b/pyproject.toml index 187fe43..b7a07b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "NightShift" -version = "0.3.0" +version = "0.4.0" description = "Copy cataloging bot" authors = ["Tomasz Kalata "] license = "MIT" diff --git a/tests/unit/test_marc_writer.py b/tests/unit/test_marc_writer.py index f78ec93..6228f5f 100644 --- a/tests/unit/test_marc_writer.py +++ b/tests/unit/test_marc_writer.py @@ -132,7 +132,7 @@ def test_add_command_tag( None, [], [], - ["Added 'Electronic books' genre to 655 tag."], + [], id="ebook: No previous tags", ), pytest.param( @@ -142,7 +142,6 @@ def test_add_command_tag( [], [ "Added 'Audiobooks' genre to 655 tag.", - "Added 'Electronic audiobooks' genre to 655 tags.", ], id="eaudio: No previous tags", ), @@ -188,13 +187,11 @@ def test_add_genre_tags_when_missing( assert log_msg in caplog.text if res_cat_id == 1: - assert len(be.bib.get_fields("655")) == 1 - assert str(be.bib["655"]) == "=655 \\0$aElectronic books." + assert len(be.bib.get_fields("655")) == 0 elif res_cat_id == 2: tags = be.bib.get_fields("655") - assert len(tags) == 2 + assert len(tags) == 1 assert str(tags[0]) == "=655 \\7$aAudiobooks.$2lcgft" - assert str(tags[1]) == "=655 \\7$aElectronic audiobooks.$2local" elif res_cat_id == 3: assert len(be.bib.get_fields("655")) == 1 assert str(be.bib["655"]) == "=655 \\7$aInternet videos.$2lcgft" @@ -267,7 +264,9 @@ def test_add_genre_tags_when_present( be._add_genre_tags() - if res_cat_id == 1: + if ( + res_cat_id == 1 + ): # remove, OCLC no longer allows (Sept. 2022) use of 'electronic books' genre terms - so this should technically not occur any more assert len(be.bib.get_fields("655")) == 1 assert "electronic books." in str(be.bib["655"]).lower() elif res_cat_id == 2: @@ -652,6 +651,32 @@ def test_remove_oclc_prefix(self, stub_resource, stub_res_cat_by_id, arg): be = BibEnhancer(stub_resource, "NYP", stub_res_cat_by_id) assert be._remove_oclc_prefix(arg) == "12345" + def test_remove_unsupported_local_genre_tag_electronic_books( + self, stub_resource, stub_res_cat_by_id + ): + be = BibEnhancer(stub_resource, "NYP", stub_res_cat_by_id) + + # prep - remove any existing tags for tests + for f in be.bib.subjects(): + be.bib.remove_field(f) + + assert len(be.bib.subjects()) == 0 + + be.bib.add_field( + Field( + tag="655", indicators=[" ", "4"], subfields=["a", "Electronic books."] + ) + ) + # must add additional 650 to pass minimium requirments + be.bib.add_field( + Field(tag="650", indicators=[" ", "0"], subfields=["a", "Foo."]) + ) + + assert len(be.bib.subjects()) == 2 + be.manipulate() + assert len(be.bib.subjects()) == 1 + assert str(be.bib.subjects()[0]) == "=650 \\0$aFoo." + @pytest.mark.parametrize( "tag", [ @@ -723,9 +748,8 @@ def test_remove_unsupported_subject_tags_good_terms( be.bib.add_field(tag) be.manipulate() - assert len(be.bib.subjects()) == 2 + assert len(be.bib.subjects()) == 1 assert str(be.bib.subjects()[0]) == str(tag) - assert str(be.bib.subjects()[1]) == "=655 \\0$aElectronic books." @pytest.mark.parametrize( "tag", @@ -789,9 +813,8 @@ def test_remove_unsupported_subject_tags_unwanted_terms( ) be.manipulate() - assert len(be.bib.subjects()) == 2 + assert len(be.bib.subjects()) == 1 assert str(be.bib.subjects()[0]) == "=650 \\0$aSpam." - assert str(be.bib.subjects()[1]) == "=655 \\0$aElectronic books." def test_save2file(self, caplog, stub_resource, stub_res_cat_by_id): be = BibEnhancer(stub_resource, "NYP", stub_res_cat_by_id) diff --git a/tests/unit/test_nightshift.py b/tests/unit/test_nightshift.py index 87fe243..5d6d0f7 100644 --- a/tests/unit/test_nightshift.py +++ b/tests/unit/test_nightshift.py @@ -2,7 +2,7 @@ def test_version(): - assert __version__ == "0.3.0" + assert __version__ == "0.4.0" def test_title(): diff --git a/tests/unit/test_tasks.py b/tests/unit/test_tasks.py index feef73b..73d66c7 100644 --- a/tests/unit/test_tasks.py +++ b/tests/unit/test_tasks.py @@ -433,7 +433,7 @@ def test_manipulate_and_serialize_bibs_default_outfile( assert bib["091"].value() == "eNYPL Book" assert bib["945"].value() == ".b11111111a" assert bib["949"].value() == "*b2=z;bn=ia;" - assert bib["901"].value() == "NightShift/0.3.0" + assert bib["901"].value() == "NightShift/0.4.0" if os.path.exists("temp.mrc"): try: @@ -472,7 +472,7 @@ def test_manipulate_and_serialize_bibs_custom_outfile( assert bib["091"].value() == "eNYPL Book" assert bib["945"].value() == ".b11111111a" assert bib["949"].value() == "*b2=z;bn=ia;" - assert bib["901"].value() == "NightShift/0.3.0" + assert bib["901"].value() == "NightShift/0.4.0" def test_manipulate_and_serialize_bibs_failed( diff --git a/tests/unit/test_worldcat.py b/tests/unit/test_worldcat.py index b9f2b73..0ce84f1 100644 --- a/tests/unit/test_worldcat.py +++ b/tests/unit/test_worldcat.py @@ -58,7 +58,7 @@ def test_get_credentials(self, mock_Worldcat): "scopes": "WorldCatMetadataAPI", "principal_id": "lib_principal_id", "principal_idns": "lib_principal_idns", - "agent": "NightShift/0.3.0", + "agent": "NightShift/0.4.0", } def test_get_access_token(self, mock_Worldcat): @@ -68,11 +68,11 @@ def test_get_access_token(self, mock_Worldcat): "scopes": "WorldCatMetadataAPI", "principal_id": "lib_principal_id", "principal_idns": "lib_principal_idns", - "agent": "NightShift/0.3.0", + "agent": "NightShift/0.4.0", } token = mock_Worldcat._get_access_token(creds) assert isinstance(token, WorldcatAccessToken) - assert token.agent == "NightShift/0.3.0" + assert token.agent == "NightShift/0.4.0" def test_get_access_token_failure( self, caplog, mock_worldcat_creds, mock_failed_post_token_response