From 21572fa2ac668a998c802cb3270a4b048bc9cad8 Mon Sep 17 00:00:00 2001 From: Anet Date: Thu, 23 May 2019 23:37:54 +0200 Subject: [PATCH] testutils: organizator nema usera + komentar k res_vyber (drive res_sel) --- seminar/testutils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/seminar/testutils.py b/seminar/testutils.py index 82688e37..a977dfb3 100644 --- a/seminar/testutils.py +++ b/seminar/testutils.py @@ -88,7 +88,7 @@ def gen_resitele(rnd, osoby, skoly): for os in osoby: rand = rnd.randint(0, 8) if not (rand % 8 == 0): - resitele.append(Resitel.objects.create(osoba=os, skola=rnd.choice([skoly]), + resitele.append(Resitel.objects.create(osoba=os, skola=rnd.choice(skoly), rok_maturity=rnd.randint(2019, 2029), zasilat=rnd.choice(Resitel.ZASILAT_CHOICES))) return resitele @@ -100,7 +100,7 @@ def gen_prijemci(rnd, osoby, kolik=10): prijemci.append(Prijemce.objects.create(osoba=rand_os)) return prijemci -def gen_organizatori(rnd, osoby, last_rocnik): +def gen_organizatori(rnd, osoby, last_rocnik, users): organizatori = [] for os in osoby: rand = rnd.randint(0, 8) @@ -114,7 +114,7 @@ def gen_organizatori(rnd, osoby, last_rocnik): organizatori.append(Organizator.objects.create(osoba=os, user=rnd.choice(users), organizuje_od=od, organizuje_do=do)) - return organizatri + return organizatori def gen_ulohy_do_cisla(rnd, cislo, organizatori, resitele, slovnik_cisel, size): '''cislo = cislo cisla v rocniku, nikoli objekt Cislo ''' @@ -161,6 +161,8 @@ def gen_ulohy_do_cisla(rnd, cislo, organizatori, resitele, slovnik_cisel, size): # reseni ulohy poc_reseni = rnd.randint(size // 2, size * 2) poc_resitel = rnd.randint(1, 3) + # vybereme nahodny vzorek resitelu o delce poctu reseni + # (nebo skoro vsechny resitele, pokud jich je mene nez pocet reseni) res_sel = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2)) for resitel in res_sel: res = Reseni.objects.create(problem = p, @@ -192,7 +194,7 @@ def create_test_data(size = 6, rnd = None): usernames = ['anet', 'bara', 'cyril', 'david', 'eva', 'filip'] users = [] for usr in usernames[:size]: - u = User.objects.create_user(username=usr, password=usr) + u = User.objects.create(username=usr, password=usr) u.first_name = usr.capitalize() u.save() users.append(u) @@ -207,7 +209,7 @@ def create_test_data(size = 6, rnd = None): # resitele a organizatori last_rocnik = 25 resitele = gen_resitele(rnd, osoby, skoly) - organizatori = gen_organizatori(rnd, osoby, last_rocnik) + organizatori = gen_organizatori(rnd, osoby, last_rocnik, users) # prijemci prijemci = gen_prijemci(rnd)