Merge pull request #2387 from bookwyrm-social/admin-template

Adds unit test for failing view
This commit is contained in:
Mouse Reeve 2022-11-16 06:43:02 -08:00 committed by GitHub
commit 55a603562c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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):
"""every response to a get request, html or json"""
# pylint: disable=invalid-name
def setUp(self):
"""we need basic test data and mocks"""
self.factory = RequestFactory()
@ -147,3 +148,16 @@ class ReportViews(TestCase):
self.rat.refresh_from_db()
self.assertFalse(self.rat.is_active)
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"]
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