Lepsi Delani Orgu #35
1 changed files with 14 additions and 5 deletions
|
@ -1,6 +1,8 @@
|
|||
from django.test import TestCase
|
||||
from django.test import TestCase, RequestFactory
|
||||
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
from personalni.admin import OsobaAdmin
|
||||
# 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
|
||||
|
||||
|
@ -9,6 +11,15 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
class DelaniOrguTest(TestCase):
|
||||
def setUp(self):
|
||||
# Admin musí mít instanci
|
||||
# Ref: https://www.argpar.se/posts/programming/testing-django-admin/
|
||||
adm_site = AdminSite()
|
||||
self.admin = OsobaAdmin(m.Osoba, adm_site)
|
||||
|
||||
from django.contrib.messages.storage.cookie import CookieStorage
|
||||
self.request = RequestFactory().get('/admin')
|
||||
self.request._messages = CookieStorage(self.request)
|
||||
|
||||
self.org_group = Group.objects.get(name='org')
|
||||
|
||||
novy_user = User.objects.create(username='osoba')
|
||||
|
@ -31,9 +42,8 @@ class DelaniOrguTest(TestCase):
|
|||
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)
|
||||
self.admin.udelej_orgem(self.request, qs)
|
||||
|
||||
# A pak už to org má být.
|
||||
logger.info(f'Nová osoba je staff: {self.nova_osoba.user.is_staff}')
|
||||
|
@ -45,8 +55,7 @@ class DelaniOrguTest(TestCase):
|
|||
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
|
||||
self.admin.udelej_orgem(self.request, 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.
|
||||
|
||||
|
|
Loading…
Reference in a new issue