mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 03:51:08 +00:00
Merge pull request #1259 from bookwyrm-social/test-coverage
Test coverage
This commit is contained in:
commit
4d4a7bc20b
12 changed files with 224 additions and 11 deletions
|
@ -175,3 +175,10 @@ class TemplateTags(TestCase):
|
|||
|
||||
result = bookwyrm_tags.related_status(notification)
|
||||
self.assertIsInstance(result, models.Status)
|
||||
|
||||
def test_get_next_shelf(self, *_):
|
||||
"""self progress helper"""
|
||||
self.assertEqual(bookwyrm_tags.get_next_shelf("to-read"), "reading")
|
||||
self.assertEqual(bookwyrm_tags.get_next_shelf("reading"), "read")
|
||||
self.assertEqual(bookwyrm_tags.get_next_shelf("read"), "read")
|
||||
self.assertEqual(bookwyrm_tags.get_next_shelf("blooooga"), "to-read")
|
||||
|
|
|
@ -8,7 +8,7 @@ from django.template.response import TemplateResponse
|
|||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import models, views
|
||||
from bookwyrm import forms, models, views
|
||||
from bookwyrm.settings import DOMAIN
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ class AuthenticationViews(TestCase):
|
|||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@your.domain.here",
|
||||
"mouse@mouse.com",
|
||||
"password",
|
||||
local=True,
|
||||
|
@ -49,6 +49,66 @@ class AuthenticationViews(TestCase):
|
|||
self.assertEqual(result.url, "/")
|
||||
self.assertEqual(result.status_code, 302)
|
||||
|
||||
def test_login_post_localname(self, _):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Login.as_view()
|
||||
form = forms.LoginForm()
|
||||
form.data["localname"] = "mouse@mouse.com"
|
||||
form.data["password"] = "password"
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.anonymous_user
|
||||
|
||||
with patch("bookwyrm.views.authentication.login"):
|
||||
result = view(request)
|
||||
self.assertEqual(result.url, "/")
|
||||
self.assertEqual(result.status_code, 302)
|
||||
|
||||
def test_login_post_username(self, _):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Login.as_view()
|
||||
form = forms.LoginForm()
|
||||
form.data["localname"] = "mouse@your.domain.here"
|
||||
form.data["password"] = "password"
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.anonymous_user
|
||||
|
||||
with patch("bookwyrm.views.authentication.login"):
|
||||
result = view(request)
|
||||
self.assertEqual(result.url, "/")
|
||||
self.assertEqual(result.status_code, 302)
|
||||
|
||||
def test_login_post_email(self, _):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Login.as_view()
|
||||
form = forms.LoginForm()
|
||||
form.data["localname"] = "mouse"
|
||||
form.data["password"] = "password"
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.anonymous_user
|
||||
|
||||
with patch("bookwyrm.views.authentication.login"):
|
||||
result = view(request)
|
||||
self.assertEqual(result.url, "/")
|
||||
self.assertEqual(result.status_code, 302)
|
||||
|
||||
def test_login_post_invalid_credentials(self, _):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Login.as_view()
|
||||
form = forms.LoginForm()
|
||||
form.data["localname"] = "mouse"
|
||||
form.data["password"] = "passsword1"
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.anonymous_user
|
||||
|
||||
with patch("bookwyrm.views.authentication.login"):
|
||||
result = view(request)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(
|
||||
result.context_data["login_form"].non_field_errors,
|
||||
"Username or password are incorrect",
|
||||
)
|
||||
|
||||
def test_register(self, _):
|
||||
"""create a user"""
|
||||
view = views.Register.as_view()
|
||||
|
|
|
@ -12,6 +12,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
|
|||
from django.template.response import TemplateResponse
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
from django.utils import timezone
|
||||
|
||||
from bookwyrm import forms, models, views
|
||||
from bookwyrm.activitypub import ActivitypubResponse
|
||||
|
@ -52,6 +53,11 @@ class BookViews(TestCase):
|
|||
def test_book_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Book.as_view()
|
||||
models.ReadThrough.objects.create(
|
||||
user=self.local_user,
|
||||
book=self.book,
|
||||
start_date=timezone.now(),
|
||||
)
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.views.books.is_api_request") as is_api:
|
||||
|
@ -67,6 +73,79 @@ class BookViews(TestCase):
|
|||
self.assertIsInstance(result, ActivitypubResponse)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_book_page_statuses(self, *_):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Book.as_view()
|
||||
|
||||
review = models.Review.objects.create(
|
||||
user=self.local_user,
|
||||
book=self.book,
|
||||
content="hi",
|
||||
)
|
||||
|
||||
comment = models.Comment.objects.create(
|
||||
user=self.local_user,
|
||||
book=self.book,
|
||||
content="hi",
|
||||
)
|
||||
|
||||
quote = models.Quotation.objects.create(
|
||||
user=self.local_user,
|
||||
book=self.book,
|
||||
content="hi",
|
||||
quote="wow",
|
||||
)
|
||||
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.views.books.is_api_request") as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, self.book.id, user_statuses="review")
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.context_data["statuses"].object_list[0], review)
|
||||
|
||||
with patch("bookwyrm.views.books.is_api_request") as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, self.book.id, user_statuses="comment")
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.context_data["statuses"].object_list[0], comment)
|
||||
|
||||
with patch("bookwyrm.views.books.is_api_request") as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, self.book.id, user_statuses="quotation")
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.context_data["statuses"].object_list[0], quote)
|
||||
|
||||
def test_book_page_invalid_id(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Book.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.views.books.is_api_request") as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, 0)
|
||||
self.assertEqual(result.status_code, 404)
|
||||
|
||||
def test_book_page_work_id(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Book.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.views.books.is_api_request") as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, self.work.id)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.context_data["book"], self.book)
|
||||
|
||||
def test_edit_book_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.EditBook.as_view()
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
""" test for app action functionality """
|
||||
import pathlib
|
||||
from unittest.mock import patch
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.template.response import TemplateResponse
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm import views
|
||||
from bookwyrm import forms, models, views
|
||||
|
||||
|
||||
class ImportViews(TestCase):
|
||||
|
@ -47,6 +48,27 @@ class ImportViews(TestCase):
|
|||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_start_import(self):
|
||||
"""retry failed items"""
|
||||
view = views.Import.as_view()
|
||||
form = forms.ImportForm()
|
||||
form.data["source"] = "LibraryThing"
|
||||
form.data["privacy"] = "public"
|
||||
form.data["include_reviews"] = False
|
||||
csv_file = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv")
|
||||
form.data["csv_file"] = SimpleUploadedFile(
|
||||
csv_file, open(csv_file, "rb").read(), content_type="text/csv"
|
||||
)
|
||||
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
||||
with patch("bookwyrm.importers.Importer.start_import"):
|
||||
view(request)
|
||||
job = models.ImportJob.objects.get()
|
||||
self.assertFalse(job.include_reviews)
|
||||
self.assertEqual(job.privacy, "public")
|
||||
|
||||
def test_retry_import(self):
|
||||
"""retry failed items"""
|
||||
view = views.ImportStatus.as_view()
|
||||
|
|
|
@ -52,6 +52,26 @@ class InviteViews(TestCase):
|
|||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_manage_invites_post(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.ManageInvites.as_view()
|
||||
form = forms.CreateInviteForm()
|
||||
form.data["use_limit"] = 3
|
||||
form.data["expiry"] = ""
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
request.user.is_superuser = True
|
||||
|
||||
result = view(request)
|
||||
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
invite = models.SiteInvite.objects.get()
|
||||
self.assertEqual(invite.use_limit, 3)
|
||||
self.assertIsNone(invite.expiry)
|
||||
|
||||
def test_invite_request(self):
|
||||
"""request to join a server"""
|
||||
form = forms.InviteRequestForm()
|
||||
|
|
|
@ -6,6 +6,7 @@ from django.shortcuts import get_object_or_404, redirect
|
|||
from django.template.response import TemplateResponse
|
||||
from django.utils import timezone
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views import View
|
||||
|
||||
|
@ -54,7 +55,7 @@ class Login(View):
|
|||
return redirect(request.GET.get("next", "/"))
|
||||
|
||||
# login errors
|
||||
login_form.non_field_errors = "Username or password are incorrect"
|
||||
login_form.non_field_errors = _("Username or password are incorrect")
|
||||
register_form = forms.RegisterForm()
|
||||
data = {"login_form": login_form, "register_form": register_form}
|
||||
return TemplateResponse(request, "login.html", data)
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: 0.0.1\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-08-05 01:33+0000\n"
|
||||
"POT-Creation-Date: 2021-08-06 18:34+0000\n"
|
||||
"PO-Revision-Date: 2021-03-02 17:19-0800\n"
|
||||
"Last-Translator: Mouse Reeve <mousereeve@riseup.net>\n"
|
||||
"Language-Team: English <LL@li.org>\n"
|
||||
|
@ -3295,6 +3295,10 @@ msgstr ""
|
|||
msgid "%(title)s: %(subtitle)s"
|
||||
msgstr ""
|
||||
|
||||
#: bookwyrm/views/authentication.py:58
|
||||
msgid "Username or password are incorrect"
|
||||
msgstr ""
|
||||
|
||||
#: bookwyrm/views/import_data.py:67
|
||||
#, fuzzy
|
||||
#| msgid "Email address:"
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: 0.0.1\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-08-05 01:33+0000\n"
|
||||
"POT-Creation-Date: 2021-08-06 18:34+0000\n"
|
||||
"PO-Revision-Date: 2021-02-28 17:19-0800\n"
|
||||
"Last-Translator: Mouse Reeve <mousereeve@riseup.net>\n"
|
||||
"Language-Team: English <LL@li.org>\n"
|
||||
|
@ -2991,6 +2991,10 @@ msgstr ""
|
|||
msgid "%(title)s: %(subtitle)s"
|
||||
msgstr ""
|
||||
|
||||
#: bookwyrm/views/authentication.py:58
|
||||
msgid "Username or password are incorrect"
|
||||
msgstr ""
|
||||
|
||||
#: bookwyrm/views/import_data.py:67
|
||||
msgid "Not a valid csv file"
|
||||
msgstr ""
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: 0.0.1\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-08-05 01:33+0000\n"
|
||||
"POT-Creation-Date: 2021-08-06 18:34+0000\n"
|
||||
"PO-Revision-Date: 2021-03-19 11:49+0800\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -3036,6 +3036,10 @@ msgstr ""
|
|||
msgid "%(title)s: %(subtitle)s"
|
||||
msgstr ""
|
||||
|
||||
#: bookwyrm/views/authentication.py:58
|
||||
msgid "Username or password are incorrect"
|
||||
msgstr ""
|
||||
|
||||
#: bookwyrm/views/import_data.py:67
|
||||
msgid "Not a valid csv file"
|
||||
msgstr "No un archivo csv válido"
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: 0.1.1\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-08-05 01:33+0000\n"
|
||||
"POT-Creation-Date: 2021-08-06 18:34+0000\n"
|
||||
"PO-Revision-Date: 2021-04-05 12:44+0100\n"
|
||||
"Last-Translator: Fabien Basmaison <contact@arkhi.org>\n"
|
||||
"Language-Team: Mouse Reeve <LL@li.org>\n"
|
||||
|
@ -3015,6 +3015,10 @@ msgstr "Ce fichier dépasse la taille limite : 10 Mo"
|
|||
msgid "%(title)s: %(subtitle)s"
|
||||
msgstr "%(title)s (%(subtitle)s)"
|
||||
|
||||
#: bookwyrm/views/authentication.py:58
|
||||
msgid "Username or password are incorrect"
|
||||
msgstr ""
|
||||
|
||||
#: bookwyrm/views/import_data.py:67
|
||||
msgid "Not a valid csv file"
|
||||
msgstr "Fichier CSV non valide"
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: 0.1.1\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-08-05 01:33+0000\n"
|
||||
"POT-Creation-Date: 2021-08-06 18:34+0000\n"
|
||||
"PO-Revision-Date: 2021-03-20 00:56+0000\n"
|
||||
"Last-Translator: Kana <gudzpoz@live.com>\n"
|
||||
"Language-Team: Mouse Reeve <LL@li.org>\n"
|
||||
|
@ -2992,6 +2992,10 @@ msgstr "文件超过了最大大小: 10MB"
|
|||
msgid "%(title)s: %(subtitle)s"
|
||||
msgstr "%(title)s:%(subtitle)s"
|
||||
|
||||
#: bookwyrm/views/authentication.py:58
|
||||
msgid "Username or password are incorrect"
|
||||
msgstr ""
|
||||
|
||||
#: bookwyrm/views/import_data.py:67
|
||||
msgid "Not a valid csv file"
|
||||
msgstr "不是有效的 csv 文件"
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: 0.0.1\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-08-05 01:33+0000\n"
|
||||
"POT-Creation-Date: 2021-08-06 18:34+0000\n"
|
||||
"PO-Revision-Date: 2021-06-30 10:36+0000\n"
|
||||
"Last-Translator: Grace Cheng <chengracecwy@gmail.com>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -3011,6 +3011,10 @@ msgstr "檔案超過了最大大小: 10MB"
|
|||
msgid "%(title)s: %(subtitle)s"
|
||||
msgstr ""
|
||||
|
||||
#: bookwyrm/views/authentication.py:58
|
||||
msgid "Username or password are incorrect"
|
||||
msgstr ""
|
||||
|
||||
#: bookwyrm/views/import_data.py:67
|
||||
msgid "Not a valid csv file"
|
||||
msgstr "不是有效的 csv 檔案"
|
||||
|
|
Loading…
Reference in a new issue