Skip to content

Commit

Permalink
Electronic books genre removal (#41)
Browse files Browse the repository at this point in the history
* removes adding "Electronic books" & "Electronic audiobooks" genre terms

* version bump to 0.4.0
  • Loading branch information
klinga authored Apr 10, 2023
1 parent 1d3d444 commit 94f50a0
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 57 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
[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
2 changes: 1 addition & 1 deletion nightshift/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.3.0"
__version__ = "0.4.0"
__title__ = "NightShift"
37 changes: 1 addition & 36 deletions nightshift/marc/marc_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "NightShift"
version = "0.3.0"
version = "0.4.0"
description = "Copy cataloging bot"
authors = ["Tomasz Kalata <klingaroo@gmail.com>"]
license = "MIT"
Expand Down
45 changes: 34 additions & 11 deletions tests/unit/test_marc_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_add_command_tag(
None,
[],
[],
["Added 'Electronic books' genre to 655 tag."],
[],
id="ebook: No previous tags",
),
pytest.param(
Expand All @@ -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",
),
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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",
[
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_nightshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def test_version():
assert __version__ == "0.3.0"
assert __version__ == "0.4.0"


def test_title():
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_worldcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 94f50a0

Please sign in to comment.