forked from mirrors/bookwyrm
Adds tests
This commit is contained in:
parent
97f0d82b05
commit
7638f99c1b
2 changed files with 81 additions and 0 deletions
57
bookwyrm/tests/views/test_email_blocks.py
Normal file
57
bookwyrm/tests/views/test_email_blocks.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
""" 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 models, views
|
||||
|
||||
|
||||
class EmailBlocklistViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
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"
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_blocklist_page_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.EmailBlocklist.as_view()
|
||||
request = self.factory.get("")
|
||||
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)
|
||||
|
||||
def test_blocklist_page_post(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.EmailBlocklist.as_view()
|
||||
request = self.factory.post("", {"domain": "gmail.com"})
|
||||
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)
|
||||
|
||||
self.assertTrue(
|
||||
models.EmailBlocklist.objects.filter(domain="gmail.com").exists()
|
||||
)
|
|
@ -153,6 +153,30 @@ class RegisterViews(TestCase):
|
|||
with self.assertRaises(PermissionDenied):
|
||||
view(request)
|
||||
|
||||
def test_register_blocked_domain(self, *_):
|
||||
"""you can't register with a blocked domain"""
|
||||
view = views.Register.as_view()
|
||||
models.EmailBlocklist.objects.create(domain="gmail.com")
|
||||
|
||||
# one that fails
|
||||
request = self.factory.post(
|
||||
"register/",
|
||||
{"localname": "nutria ", "password": "mouseword", "email": "aa@gmail.com"},
|
||||
)
|
||||
result = view(request)
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertFalse(models.User.objects.filter(email="aa@gmail.com").exists())
|
||||
|
||||
# one that succeeds
|
||||
request = self.factory.post(
|
||||
"register/",
|
||||
{"localname": "nutria ", "password": "mouseword", "email": "aa@bleep.com"},
|
||||
)
|
||||
with patch("bookwyrm.views.register.login"):
|
||||
result = view(request)
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertTrue(models.User.objects.filter(email="aa@bleep.com").exists())
|
||||
|
||||
def test_register_invite(self, *_):
|
||||
"""you can't just register"""
|
||||
view = views.Register.as_view()
|
||||
|
|
Loading…
Reference in a new issue