Adds unit test for failing view

This commit is contained in:
Mouse Reeve 2022-11-15 21:41:19 -08:00
parent 1a8580cdbc
commit f95729a0c3
2 changed files with 15 additions and 1 deletions

View file

@ -15,6 +15,7 @@ from bookwyrm.tests.validate_html import validate_html
class ReportViews(TestCase): class ReportViews(TestCase):
"""every response to a get request, html or json""" """every response to a get request, html or json"""
# pylint: disable=invalid-name
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
@ -147,3 +148,16 @@ class ReportViews(TestCase):
self.rat.refresh_from_db() self.rat.refresh_from_db()
self.assertFalse(self.rat.is_active) self.assertFalse(self.rat.is_active)
self.assertEqual(self.rat.deactivation_reason, "moderator_deletion") self.assertEqual(self.rat.deactivation_reason, "moderator_deletion")
def test_delete_user_error(self, *_):
"""toggle whether a user is able to log in"""
self.assertTrue(self.rat.is_active)
request = self.factory.post("", {"password": "wrong password"})
request.user = self.local_user
result = views.moderator_delete_user(request, self.rat.id)
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.rat.refresh_from_db()
self.assertTrue(self.rat.is_active)

View file

@ -128,7 +128,7 @@ def moderator_delete_user(request, user_id):
form.errors["password"] = ["Invalid password"] form.errors["password"] = ["Invalid password"]
data = {"user": user, "group_form": forms.UserGroupForm(), "form": form} data = {"user": user, "group_form": forms.UserGroupForm(), "form": form}
return TemplateResponse(request, "user_admin/user.html", data) return TemplateResponse(request, "settings/users/user.html", data)
@login_required @login_required