Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.1 KiB
54 lines
2.1 KiB
1 year ago
|
from django.test import TestCase
|
||
|
|
||
|
from django.contrib.auth.models import User, Group
|
||
|
# Tohle bude peklo, až jednou ty modely fakt rozstřelíme… Možná vyrobit various.all_models, které půjdou importovat jako m? :-)
|
||
|
import seminar.models as m
|
||
|
|
||
|
import logging
|
||
|
logger = logging.getLogger(__name__)
|
||
|
|
||
|
class DelaniOrguTest(TestCase):
|
||
|
def setUp(self):
|
||
|
self.org_group = Group.objects.get(name='org')
|
||
|
|
||
|
novy_user = User.objects.create(username='osoba')
|
||
|
self.nova_osoba = m.Osoba.objects.create(
|
||
|
jmeno='Milada',
|
||
|
prijmeni='Von Kolej',
|
||
|
user = novy_user,
|
||
|
# Snad nic dalšího nepotřebujeme, kdyžtak se doplní…
|
||
|
)
|
||
|
stary_user = User.objects.create(username='stary_user')
|
||
|
stara_osoba = m.Osoba.objects.create(user=stary_user)
|
||
|
self.stary_org = m.Organizator.objects.create(osoba=stara_osoba)
|
||
|
|
||
|
def test_pridani_orga(self):
|
||
|
# Nejdřív to není org…
|
||
|
self.assertFalse(m.Organizator.objects.filter(osoba=self.nova_osoba).exists())
|
||
|
self.assertNotIn(self.org_group, self.nova_osoba.user.groups.all())
|
||
|
self.assertFalse(self.nova_osoba.user.has_perm('auth.org'))
|
||
|
self.assertFalse(self.nova_osoba.user.is_staff)
|
||
|
breakpoint
|
||
|
|
||
|
# Pak orga uděláme…
|
||
|
from personalni.admin import OsobaAdmin
|
||
|
qs = m.Osoba.objects.filter(id=self.nova_osoba.id)
|
||
|
OsobaAdmin.udelej_orgem(None, None, qs)
|
||
|
|
||
|
# A pak už to org má být.
|
||
|
logger.info(f'Nová osoba je staff: {self.nova_osoba.user.is_staff}')
|
||
|
self.assertTrue(self.nova_osoba.user.is_staff)
|
||
|
self.assertTrue(self.nova_osoba.user.has_perm('auth.org'))
|
||
|
self.assertIn(self.org_group, self.nova_osoba.user.groups.all())
|
||
|
self.assertTrue(m.Organizator.objects.filter(osoba=self.nova_osoba).exists())
|
||
|
novy_org = m.Organizator.objects.get(osoba=self.nova_osoba)
|
||
|
self.assertIsNotNone(novy_org.organizuje_od)
|
||
|
|
||
|
def test_pridani_stareho_orga(self):
|
||
|
from personalni.admin import OsobaAdmin
|
||
|
OsobaAdmin.udelej_orgem(None, None, m.Osoba.objects.filter(id=self.stary_org.osoba.id)) # Ugly
|
||
|
# Když to spadne, tak jsem se to dozvěděl, takže už nepotřebuju nic kontrolovat.
|
||
|
# Jestli to funguje správně má řešit jiný test.
|
||
|
|
||
|
|