From 63509c954da2192058abb2cfcb88f9009fcbc9fc Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 19 Apr 2021 18:12:55 -0700 Subject: [PATCH] Adds test for changing user group --- bookwyrm/forms.py | 1 + bookwyrm/tests/views/test_user_admin.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index ac5bd027..1f1f1a3b 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -149,6 +149,7 @@ class LimitedEditUserForm(CustomForm): ] help_texts = {f: None for f in fields} + class UserGroupForm(CustomForm): class Meta: model = models.User diff --git a/bookwyrm/tests/views/test_user_admin.py b/bookwyrm/tests/views/test_user_admin.py index 1884d000..4e1e106d 100644 --- a/bookwyrm/tests/views/test_user_admin.py +++ b/bookwyrm/tests/views/test_user_admin.py @@ -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"] + )