Skip to content

Commit

Permalink
Empty author tag fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RishiDiwanTT committed Sep 19, 2023
1 parent e8e42ca commit eb99da5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 2 additions & 3 deletions core/feed/annotator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def contributor(
return None

name = contributor.display_name or contributor.sort_name
name_key = name.lower()
if name_key in state[marc_role]:
name_key = name and name.lower()

Check warning on line 96 in core/feed/annotator/base.py

View check run for this annotation

Codecov / codecov/patch

core/feed/annotator/base.py#L96

Added line #L96 was not covered by tests
if not name_key or name_key in state[marc_role]:
# We've already credited this person with this
# MARC role. Returning a tag would be redundant.
return None
Expand All @@ -108,7 +108,6 @@ def contributor(
# Record the fact that we credited this person with this role,
# so that we don't do it again on a subsequent call.
state[marc_role].add(name_key)

return current_role, entry

@classmethod
Expand Down
4 changes: 3 additions & 1 deletion core/feed/serializer/opds.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ def serialize_work_entry(self, feed_entry: WorkEntryData) -> etree._Element:
entry.append(rating_tag)

for author in feed_entry.authors:
entry.append(self._serialize_author_tag("author", author))
# Author must at a minimum have a name
if author.name:
entry.append(self._serialize_author_tag("author", author))

Check warning on line 226 in core/feed/serializer/opds.py

View check run for this annotation

Codecov / codecov/patch

core/feed/serializer/opds.py#L226

Added line #L226 was not covered by tests
for contributor in feed_entry.contributors:
entry.append(self._serialize_author_tag("contributor", contributor))

Expand Down
21 changes: 21 additions & 0 deletions tests/api/feed/test_annotators.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ def test_appeals(self, annotators_fixture: TestAnnotatorsFixture):
actual = [(x["term"], x["label"], x["ratingValue"]) for x in appeal_tags]
assert set(expect) == set(actual)

def test_authors(self, annotators_fixture: TestAnnotatorsFixture):
db = annotators_fixture.db
edition = db.edition()
[c_orig] = list(edition.contributors)

c1 = edition.add_contributor("c1", Contributor.AUTHOR_ROLE, _sort_name="c1")
# No name contributor
c_none = edition.add_contributor("c2", Contributor.AUTHOR_ROLE)
c_none.display_name = ""
c_none._sort_name = ""

authors = Annotator.authors(edition)
# The default, c1 and c_none
assert len(edition.contributions) == 3
# Only default and c1 are used in the feed, because c_none has no name
assert len(authors["authors"]) == 2
assert set(map(lambda x: x.name, authors["authors"])) == {
c1.sort_name,
c_orig.sort_name,
}

def test_detailed_author(self, annotators_fixture: TestAnnotatorsFixture):
data, db, session = (
annotators_fixture,
Expand Down

0 comments on commit eb99da5

Please sign in to comment.