From 8c4cafed79a65354a0bfe4952074f17e87d9cead Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 16 Sep 2021 12:52:10 -0700 Subject: [PATCH] Fixes formatting isbn endpoint results --- bookwyrm/book_search.py | 6 +++--- bookwyrm/tests/connectors/test_abstract_connector.py | 10 ++++------ bookwyrm/tests/views/test_isbn.py | 2 +- bookwyrm/views/isbn.py | 4 +++- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bookwyrm/book_search.py b/bookwyrm/book_search.py index c4d03caf..91a4e67a 100644 --- a/bookwyrm/book_search.py +++ b/bookwyrm/book_search.py @@ -114,7 +114,7 @@ def search_title_author(query, min_confidence, *filters, return_first=False): editions_of_work = results.values("parent_work__id").values_list("parent_work__id") # filter out multiple editions of the same work - results = [] + list_results = [] for work_id in set(editions_of_work): editions = results.filter(parent_work=work_id) default = editions.order_by("-edition_rank").first() @@ -126,8 +126,8 @@ def search_title_author(query, min_confidence, *filters, return_first=False): result = editions.first() if return_first: return result - results.append(result) - return results + list_results.append(result) + return list_results @dataclass diff --git a/bookwyrm/tests/connectors/test_abstract_connector.py b/bookwyrm/tests/connectors/test_abstract_connector.py index 129b3f0c..a453f613 100644 --- a/bookwyrm/tests/connectors/test_abstract_connector.py +++ b/bookwyrm/tests/connectors/test_abstract_connector.py @@ -119,12 +119,10 @@ class AbstractConnector(TestCase): @responses.activate def test_get_or_create_author(self): """load an author""" - self.connector.author_mappings = ( # pylint: disable=attribute-defined-outside-init - [ # pylint: disable=attribute-defined-outside-init - Mapping("id"), - Mapping("name"), - ] - ) + self.connector.author_mappings = [ # pylint: disable=attribute-defined-outside-init # pylint: disable=attribute-defined-outside-init + Mapping("id"), + Mapping("name"), + ] responses.add( responses.GET, diff --git a/bookwyrm/tests/views/test_isbn.py b/bookwyrm/tests/views/test_isbn.py index a6a45174..05a10956 100644 --- a/bookwyrm/tests/views/test_isbn.py +++ b/bookwyrm/tests/views/test_isbn.py @@ -35,7 +35,7 @@ class IsbnViews(TestCase): parent_work=self.work, ) models.Connector.objects.create( - identifier="self", connector_file="self_connector", local=True + identifier="self", connector_file="self_connector" ) models.SiteSettings.objects.create() diff --git a/bookwyrm/views/isbn.py b/bookwyrm/views/isbn.py index 173a3adb..e5343488 100644 --- a/bookwyrm/views/isbn.py +++ b/bookwyrm/views/isbn.py @@ -17,7 +17,9 @@ class Isbn(View): book_results = book_search.isbn_search(isbn) if is_api_request(request): - return JsonResponse([r.json() for r in book_results], safe=False) + return JsonResponse( + [book_search.format_search_result(r) for r in book_results], safe=False + ) paginated = Paginator(book_results, PAGE_LENGTH).get_page( request.GET.get("page")