Fix tests

This commit is contained in:
Ludovic Stephan 2020-08-03 19:07:09 +02:00
parent c145191e55
commit d6fa738a25
2 changed files with 18 additions and 14 deletions

View file

@ -10,7 +10,7 @@ from kfet.models import Account
from . import KFET_GENERIC_TRIGRAMME, KFET_GENERIC_USERNAME
from .backends import AccountBackend, GenericBackend
from .models import GenericTeamToken
from .models import GenericTeamToken, KFetGroup
from .utils import get_kfet_generic_user
from .views import GenericLoginView
@ -27,11 +27,8 @@ class UserGroupFormTests(TestCase):
self.user = User.objects.create(username="foo", password="foo")
# create some K-Fêt groups
prefix_name = "K-Fêt "
names = ["Group 1", "Group 2", "Group 3"]
self.kfet_groups = [
Group.objects.create(name=prefix_name + name) for name in names
]
self.kfet_groups = [KFetGroup.objects.create(name=name) for name in names]
# create a non-K-Fêt group
self.other_group = Group.objects.create(name="Other group")
@ -41,7 +38,9 @@ class UserGroupFormTests(TestCase):
form = UserGroupForm(instance=self.user)
groups_field = form.fields["groups"]
self.assertQuerysetEqual(
groups_field.queryset, [repr(g) for g in self.kfet_groups], ordered=False
groups_field.queryset,
[repr(g.group_ptr) for g in self.kfet_groups],
ordered=False,
)
def test_keep_others(self):
@ -59,7 +58,8 @@ class UserGroupFormTests(TestCase):
form.save()
self.assertQuerysetEqual(
user.groups.all(),
[repr(g) for g in [self.other_group] + self.kfet_groups],
[self.other_group.pk] + [group.pk for group in self.kfet_groups],
transform=lambda group: group.pk,
ordered=False,
)

View file

@ -3,13 +3,14 @@ from datetime import datetime, timedelta
from decimal import Decimal
from unittest import mock
from django.contrib.auth.models import Group, User
from django.contrib.auth.models import User
from django.test import Client, TestCase
from django.urls import reverse
from django.utils import timezone
from .. import KFET_DELETED_TRIGRAMME
from ..auth import KFET_GENERIC_TRIGRAMME
from ..auth.models import KFetGroup
from ..config import kfet_config
from ..models import (
Account,
@ -464,15 +465,18 @@ class AccountGroupListViewTests(ViewTestCaseMixin, TestCase):
def setUp(self):
super().setUp()
self.group1 = Group.objects.create(name="K-Fêt - Group1")
self.group2 = Group.objects.create(name="K-Fêt - Group2")
self.group1 = KFetGroup.objects.create(name="Group1")
self.group2 = KFetGroup.objects.create(name="Group2")
def test_ok(self):
r = self.client.get(self.url)
self.assertEqual(r.status_code, 200)
self.assertQuerysetEqual(
r.context["groups"], map(repr, [self.group1, self.group2]), ordered=False
r.context["groups"],
[self.group1.pk, self.group2.pk],
transform=lambda group: group.pk,
ordered=False,
)
@ -510,7 +514,7 @@ class AccountGroupCreateViewTests(ViewTestCaseMixin, TestCase):
r = self.client.post(self.url, self.post_data)
self.assertRedirects(r, reverse("kfet.account.group"))
group = Group.objects.get(name="K-Fêt The Group")
group = KFetGroup.objects.get(name="The Group")
self.assertQuerysetEqual(
group.permissions.all(),
@ -551,7 +555,7 @@ class AccountGroupUpdateViewTests(ViewTestCaseMixin, TestCase):
def setUp(self):
super().setUp()
self.perms = get_perms("kfet.is_team", "kfet.manage_perms")
self.group = Group.objects.create(name="K-Fêt - Group")
self.group = KFetGroup.objects.create(name="Group")
self.group.permissions.set(self.perms.values())
def test_get_ok(self):
@ -564,7 +568,7 @@ class AccountGroupUpdateViewTests(ViewTestCaseMixin, TestCase):
self.group.refresh_from_db()
self.assertEqual(self.group.name, "K-Fêt The Group")
self.assertEqual(self.group.name, "The Group")
self.assertQuerysetEqual(
self.group.permissions.all(),
map(repr, [self.perms["kfet.is_team"], self.perms["kfet.manage_perms"]]),