forked from mirrors/bookwyrm
Adds tests
This commit is contained in:
parent
5297b9d796
commit
5b8bd9ad44
1 changed files with 78 additions and 1 deletions
|
@ -6,7 +6,7 @@ from django.template.response import TemplateResponse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import forms, models
|
||||||
from bookwyrm import views
|
from bookwyrm import views
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,3 +50,80 @@ class InviteViews(TestCase):
|
||||||
self.assertIsInstance(result, TemplateResponse)
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
result.render()
|
result.render()
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_invite_request(self):
|
||||||
|
""" request to join a server """
|
||||||
|
form = forms.InviteRequestForm()
|
||||||
|
form.data["email"] = "new@user.email"
|
||||||
|
|
||||||
|
view = views.InviteRequest.as_view()
|
||||||
|
request = self.factory.post("", form.data)
|
||||||
|
|
||||||
|
result = view(request)
|
||||||
|
result.render()
|
||||||
|
|
||||||
|
req = models.InviteRequest.objects.get()
|
||||||
|
self.assertEqual(req.email, "new@user.email")
|
||||||
|
|
||||||
|
def test_invite_request_email_taken(self):
|
||||||
|
""" request to join a server with an existing user email """
|
||||||
|
form = forms.InviteRequestForm()
|
||||||
|
form.data["email"] = "mouse@mouse.mouse"
|
||||||
|
|
||||||
|
view = views.InviteRequest.as_view()
|
||||||
|
request = self.factory.post("", form.data)
|
||||||
|
|
||||||
|
result = view(request)
|
||||||
|
result.render()
|
||||||
|
|
||||||
|
# no request created
|
||||||
|
self.assertFalse(models.InviteRequest.objects.exists())
|
||||||
|
|
||||||
|
def test_manage_invite_requests(self):
|
||||||
|
""" there are so many views, this just makes sure it LOADS """
|
||||||
|
view = views.ManageInviteRequests.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)
|
||||||
|
|
||||||
|
# now with data
|
||||||
|
models.InviteRequest.objects.create(email="fish@example.com")
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
result.render()
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_manage_invite_requests_send(self):
|
||||||
|
""" send an invite """
|
||||||
|
req = models.InviteRequest.objects.create(email="fish@example.com")
|
||||||
|
|
||||||
|
view = views.InviteRequest.as_view()
|
||||||
|
request = self.factory.post("", {"id": req.id})
|
||||||
|
request.user = self.local_user
|
||||||
|
request.user.is_superuser = True
|
||||||
|
|
||||||
|
with patch("bookwyrm.emailing.send_email.delay") as mock:
|
||||||
|
view(request)
|
||||||
|
self.assertEqual(mock.call_count, 1)
|
||||||
|
self.assertIsNotNone(req.invite)
|
||||||
|
|
||||||
|
def test_ignore_invite_request(self):
|
||||||
|
""" don't invite that jerk """
|
||||||
|
req = models.InviteRequest.objects.create(email="fish@example.com")
|
||||||
|
|
||||||
|
view = views.ignore_invite_request
|
||||||
|
request = self.factory.post("", {"invite-request": req.id})
|
||||||
|
request.user = self.local_user
|
||||||
|
request.user.is_superuser = True
|
||||||
|
|
||||||
|
view(request)
|
||||||
|
req.refresh_from_db()
|
||||||
|
self.assertTrue(req.ignored)
|
||||||
|
|
||||||
|
view(request)
|
||||||
|
req.refresh_from_db()
|
||||||
|
self.assertFalse(req.ignored)
|
||||||
|
|
Loading…
Reference in a new issue