Merge pull request #2188 from bookwyrm-social/more-tests

More tests
This commit is contained in:
Mouse Reeve 2022-07-06 15:31:41 -07:00 committed by GitHub
commit 060afd599d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1,13 @@
""" test searching for books """
import re
from django.test import TestCase
from bookwyrm.utils import regex
class TestUtils(TestCase):
"""utility functions"""
def test_regex(self):
"""Regexes used throughout the app"""
self.assertTrue(re.match(regex.DOMAIN, "xn--69aa8bzb.xn--y9a3aq"))

View file

@ -0,0 +1,80 @@
""" test for app action functionality """
from unittest.mock import patch
from django.template.response import TemplateResponse
from django.test import TestCase
from django.test.client import RequestFactory
from bookwyrm import forms, models, views
from bookwyrm.tests.validate_html import validate_html
class SiteSettingsViews(TestCase):
"""Edit site settings"""
def setUp(self):
"""we need basic test data and mocks"""
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",
"password",
local=True,
localname="mouse",
)
self.site = models.SiteSettings.objects.create()
def test_site_get(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.Site.as_view()
request = self.factory.get("")
request.user = self.local_user
request.user.is_superuser = True
result = view(request)
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)
def test_site_post(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.Site.as_view()
form = forms.SiteForm()
form.data["name"] = "Name!"
form.data["instance_tagline"] = "hi"
form.data["instance_description"] = "blah"
form.data["registration_closed_text"] = "blah"
form.data["invite_request_text"] = "blah"
form.data["code_of_conduct"] = "blah"
form.data["privacy_policy"] = "blah"
request = self.factory.post("", form.data)
request.user = self.local_user
request.user.is_superuser = True
result = view(request)
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)
site = models.SiteSettings.objects.get()
self.assertEqual(site.name, "Name!")
def test_site_post_invalid(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.Site.as_view()
form = forms.SiteForm()
request = self.factory.post("", form.data)
request.user = self.local_user
request.user.is_superuser = True
result = view(request)
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)
self.site.refresh_from_db()
self.assertEqual(self.site.name, "BookWyrm")