Browse Source

testutils: organizator nema usera + komentar k res_vyber (drive res_sel)

export_seznamu_prednasek
Anet 6 years ago
parent
commit
21572fa2ac
  1. 12
      seminar/testutils.py

12
seminar/testutils.py

@ -88,7 +88,7 @@ def gen_resitele(rnd, osoby, skoly):
for os in osoby: for os in osoby:
rand = rnd.randint(0, 8) rand = rnd.randint(0, 8)
if not (rand % 8 == 0): 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), rok_maturity=rnd.randint(2019, 2029),
zasilat=rnd.choice(Resitel.ZASILAT_CHOICES))) zasilat=rnd.choice(Resitel.ZASILAT_CHOICES)))
return resitele return resitele
@ -100,7 +100,7 @@ def gen_prijemci(rnd, osoby, kolik=10):
prijemci.append(Prijemce.objects.create(osoba=rand_os)) prijemci.append(Prijemce.objects.create(osoba=rand_os))
return prijemci return prijemci
def gen_organizatori(rnd, osoby, last_rocnik): def gen_organizatori(rnd, osoby, last_rocnik, users):
organizatori = [] organizatori = []
for os in osoby: for os in osoby:
rand = rnd.randint(0, 8) rand = rnd.randint(0, 8)
@ -114,7 +114,7 @@ def gen_organizatori(rnd, osoby, last_rocnik):
organizatori.append(Organizator.objects.create(osoba=os, organizatori.append(Organizator.objects.create(osoba=os,
user=rnd.choice(users), user=rnd.choice(users),
organizuje_od=od, organizuje_do=do)) organizuje_od=od, organizuje_do=do))
return organizatri return organizatori
def gen_ulohy_do_cisla(rnd, cislo, organizatori, resitele, slovnik_cisel, size): def gen_ulohy_do_cisla(rnd, cislo, organizatori, resitele, slovnik_cisel, size):
'''cislo = cislo cisla v rocniku, nikoli objekt Cislo ''' '''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 # reseni ulohy
poc_reseni = rnd.randint(size // 2, size * 2) poc_reseni = rnd.randint(size // 2, size * 2)
poc_resitel = rnd.randint(1, 3) 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)) res_sel = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2))
for resitel in res_sel: for resitel in res_sel:
res = Reseni.objects.create(problem = p, 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'] usernames = ['anet', 'bara', 'cyril', 'david', 'eva', 'filip']
users = [] users = []
for usr in usernames[:size]: 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.first_name = usr.capitalize()
u.save() u.save()
users.append(u) users.append(u)
@ -207,7 +209,7 @@ def create_test_data(size = 6, rnd = None):
# resitele a organizatori # resitele a organizatori
last_rocnik = 25 last_rocnik = 25
resitele = gen_resitele(rnd, osoby, skoly) resitele = gen_resitele(rnd, osoby, skoly)
organizatori = gen_organizatori(rnd, osoby, last_rocnik) organizatori = gen_organizatori(rnd, osoby, last_rocnik, users)
# prijemci # prijemci
prijemci = gen_prijemci(rnd) prijemci = gen_prijemci(rnd)

Loading…
Cancel
Save