mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 03:51:08 +00:00
Adds test for delete view
This commit is contained in:
parent
8cd6712db3
commit
557aa2005b
2 changed files with 39 additions and 1 deletions
|
@ -1,9 +1,11 @@
|
|||
""" test for app action functionality """
|
||||
import json
|
||||
import pathlib
|
||||
from unittest.mock import patch
|
||||
from PIL import Image
|
||||
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.contrib.sessions.middleware import SessionMiddleware
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.template.response import TemplateResponse
|
||||
|
@ -108,3 +110,40 @@ class EditUserViews(TestCase):
|
|||
self.assertIsInstance(result, ContentFile)
|
||||
image_result = Image.open(result)
|
||||
self.assertEqual(image_result.size, (120, 120))
|
||||
|
||||
def test_delete_user_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.DeleteUser.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_delete_user(self):
|
||||
"""use a form to update a user"""
|
||||
view = views.DeleteUser.as_view()
|
||||
form = forms.DeleteUserForm()
|
||||
form.data["password"] = "password"
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
middleware = SessionMiddleware()
|
||||
middleware.process_request(request)
|
||||
request.session.save()
|
||||
|
||||
|
||||
self.assertIsNone(self.local_user.name)
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||
) as delay_mock:
|
||||
view(request)
|
||||
self.assertEqual(delay_mock.call_count, 1)
|
||||
activity = json.loads(delay_mock.call_args[0][1])
|
||||
self.assertEqual(activity["type"], "Delete")
|
||||
self.assertEqual(activity["actor"], self.local_user.remote_id)
|
||||
self.assertEqual(
|
||||
activity["cc"][0], "https://www.w3.org/ns/activitystreams#Public"
|
||||
)
|
||||
|
||||
self.assertFalse(self.local_user.is_active)
|
||||
|
|
|
@ -68,7 +68,6 @@ class DeleteUser(View):
|
|||
return TemplateResponse(request, "preferences/delete_user.html", data)
|
||||
|
||||
|
||||
|
||||
def save_user_form(form):
|
||||
"""special handling for the user form"""
|
||||
user = form.save(commit=False)
|
||||
|
|
Loading…
Reference in a new issue