Adds test for book add description view

This commit is contained in:
Mouse Reeve 2021-08-05 18:05:57 -07:00
parent ac52142146
commit d0114d2e83
2 changed files with 15 additions and 6 deletions

View file

@ -299,3 +299,15 @@ class BookViews(TestCase):
self.book.refresh_from_db() self.book.refresh_from_db()
self.assertTrue(self.book.cover) 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
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) @permission_required("bookwyrm.edit_book", raise_exception=True)
def add_description(request, book_id): def add_description(request, book_id):
"""upload a new cover""" """upload a new cover"""
if not request.method == "POST":
return redirect("/")
book = get_object_or_404(models.Edition, id=book_id) book = get_object_or_404(models.Edition, id=book_id)
description = request.POST.get("description") description = request.POST.get("description")
book.description = description book.description = description
book.last_edited_by = request.user 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 @require_POST
@ -360,7 +357,7 @@ def resolve_book(request):
connector = connector_manager.get_or_create_connector(remote_id) connector = connector_manager.get_or_create_connector(remote_id)
book = connector.get_or_create_book(remote_id) book = connector.get_or_create_book(remote_id)
return redirect("/book/%d" % book.id) return redirect("book", book.id)
@login_required @login_required