Merge pull request #1256 from bookwyrm-social/test-coverage

Adds misc tests to improve coverage
This commit is contained in:
Mouse Reeve 2021-08-05 20:52:35 -06:00 committed by GitHub
commit 6fa430efec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 6 deletions

View file

@ -171,3 +171,15 @@ class Inventaire(TestCase):
}
self.assertEqual(get_language_code(options), "there")
self.assertIsNone(get_language_code({}))
@responses.activate
def test_get_description(self):
"""extract a wikipedia excerpt"""
responses.add(
responses.GET,
"https://inventaire.io/api/data?action=wp-extract&lang=en&title=test_path",
json={"extract": "hi hi"},
)
extract = self.connector.get_description({"enwiki": "test_path"})
self.assertEqual(extract, "hi hi")

View file

@ -299,3 +299,16 @@ class BookViews(TestCase):
self.book.refresh_from_db()
self.assertTrue(self.book.cover)
def test_add_description(self):
"""add a book description"""
self.local_user.groups.add(self.group)
request = self.factory.post("", {"description": "new description hi"})
request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
views.add_description(request, self.book.id)
self.book.refresh_from_db()
self.assertEqual(self.book.description, "new description hi")
self.assertEqual(self.book.last_edited_by, self.local_user)

View file

@ -339,18 +339,15 @@ def set_cover_from_url(url):
@permission_required("bookwyrm.edit_book", raise_exception=True)
def add_description(request, book_id):
"""upload a new cover"""
if not request.method == "POST":
return redirect("/")
book = get_object_or_404(models.Edition, id=book_id)
description = request.POST.get("description")
book.description = description
book.last_edited_by = request.user
book.save()
book.save(update_fields=["description", "last_edited_by"])
return redirect("/book/%s" % book.id)
return redirect("book", book.id)
@require_POST
@ -360,7 +357,7 @@ def resolve_book(request):
connector = connector_manager.get_or_create_connector(remote_id)
book = connector.get_or_create_book(remote_id)
return redirect("/book/%d" % book.id)
return redirect("book", book.id)
@login_required