Merge pull request #1256 from bookwyrm-social/test-coverage
Adds misc tests to improve coverage
This commit is contained in:
commit
6fa430efec
|
@ -171,3 +171,15 @@ class Inventaire(TestCase):
|
||||||
}
|
}
|
||||||
self.assertEqual(get_language_code(options), "there")
|
self.assertEqual(get_language_code(options), "there")
|
||||||
self.assertIsNone(get_language_code({}))
|
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")
|
||||||
|
|
|
@ -299,3 +299,16 @@ 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
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue