mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-21 07:36:42 +00:00
Adds test for book add description view
This commit is contained in:
parent
ac52142146
commit
d0114d2e83
2 changed files with 15 additions and 6 deletions
bookwyrm
|
@ -299,3 +299,15 @@ 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
|
||||
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue