Adds test for changing user group

This commit is contained in:
Mouse Reeve 2021-04-19 18:12:55 -07:00
parent 0a37b4665c
commit 63509c954d
2 changed files with 23 additions and 0 deletions

View file

@ -149,6 +149,7 @@ class LimitedEditUserForm(CustomForm):
]
help_texts = {f: None for f in fields}
class UserGroupForm(CustomForm):
class Meta:
model = models.User

View file

@ -1,4 +1,5 @@
""" test for app action functionality """
from django.contrib.auth.models import Group
from django.template.response import TemplateResponse
from django.test import TestCase
from django.test.client import RequestFactory
@ -44,3 +45,24 @@ class UserAdminViews(TestCase):
self.assertIsInstance(result, TemplateResponse)
result.render()
self.assertEqual(result.status_code, 200)
def test_user_admin_page_post(self):
""" set the user's group """
group = Group.objects.create(name="editor")
self.assertEqual(
list(self.local_user.groups.values_list("name", flat=True)), []
)
view = views.UserAdmin.as_view()
request = self.factory.post("", {"groups": [group.id]})
request.user = self.local_user
request.user.is_superuser = True
result = view(request, self.local_user.id)
self.assertIsInstance(result, TemplateResponse)
result.render()
self.assertEqual(
list(self.local_user.groups.values_list("name", flat=True)), ["editor"]
)