diff --git a/kfet/forms.py b/kfet/forms.py index 826df257..96787ddd 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -2,7 +2,6 @@ from datetime import timedelta from decimal import Decimal -from itertools import chain from django import forms from django.core.exceptions import ValidationError @@ -145,7 +144,7 @@ class UserGroupForm(forms.ModelForm): def clean_groups(self): kfet_groups = self.cleaned_data.get('groups') other_groups = self.instance.groups.exclude(name__icontains='K-Fêt') - return chain(kfet_groups, other_groups) + return list(kfet_groups) + list(other_groups) class Meta: model = User diff --git a/kfet/tests/test_forms.py b/kfet/tests/test_forms.py index 27c7b3d8..7f129a3f 100644 --- a/kfet/tests/test_forms.py +++ b/kfet/tests/test_forms.py @@ -28,7 +28,11 @@ class UserGroupFormTests(TestCase): """Only K-Fêt groups are selectable.""" form = UserGroupForm(instance=self.user) groups_field = form.fields['groups'] - self.assertEqual(len(groups_field.choices), len(self.kfet_groups)) + self.assertQuerysetEqual( + groups_field.queryset, + [repr(g) for g in self.kfet_groups], + ordered=False, + ) def test_keep_others(self): """User stays in its non-K-Fêt groups.""" @@ -45,4 +49,8 @@ class UserGroupFormTests(TestCase): form.is_valid() form.save() - self.assertEqual(len(user.groups.all()), 1+len(self.kfet_groups)) + self.assertQuerysetEqual( + user.groups.all(), + [repr(g) for g in [self.other_group] + self.kfet_groups], + ordered=False, + )