From a27ca3e753007a31f943009b52218c8139cc89a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Domes?= Date: Wed, 29 May 2019 02:39:04 +0200 Subject: [PATCH] =?UTF-8?q?testutils.py:=20r=C5=AFzn=C3=A9=20opravy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/testutils.py | 53 ++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/seminar/testutils.py b/seminar/testutils.py index 9cdc842f..edd836fa 100644 --- a/seminar/testutils.py +++ b/seminar/testutils.py @@ -100,10 +100,12 @@ def gen_resitele(rnd, osoby, skoly): def gen_prijemci(rnd, osoby, kolik=10): prijemci = [] + osoby = [] + for i in range(kolik): + osoby.append(rnd.choice(osoby)) for i in range(kolik): - rand_os = rnd.choice(osoby) - prijemci.append(Prijemce.objects.create(osoba=rand_os)) - return prijemci + prijemci.append(Prijemce.objects.create(osoba=osoby[i])) + return prijemci def gen_organizatori(rnd, osoby, last_rocnik, users): organizatori = [] @@ -169,13 +171,22 @@ def gen_ulohy_do_cisla(rnd, cislo, organizatori, resitele, slovnik_cisel, size): rnd.choice(jmeno), rnd.choice(kde)] ) - p.vzorak = " - ".join([p.zadani, rnd.choice(reseni)]) + + #Tomův pokus o opravu bugu: + text_vzoraku = Text.objects.create( + na_web = rnd.choice(reseni), + do_cisla = rnd.choice(reseni) + ) + vzorak = TextNode.objects.create(text = text_vzoraku) + uloha_vzorak = UlohaVzorakNode.objects.create(uloha=p, first_child = vzorak) + p.UlohaVzorakNode = uloha_vzorak + p.opravovatele = rnd.sample(organizatori, poc_op) p.save() # reseni ulohy poc_reseni = rnd.randint(size // 2, size * 2) - poc_resitel = rnd.randint(1, 3) + #poc_resitel = rnd.randint(1, 3) <- k čemu je himbajs tahle proměnná? # vybereme nahodny vzorek resitelu o delce poctu reseni # (nebo skoro vsechny resitele, pokud jich je mene nez pocet reseni) res_vyber = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2)) @@ -204,8 +215,7 @@ def gen_soustredeni(): datum_zacatku=datetime.date(2000, 11, 23), datum_konce=datetime.date(2000, 11, 27) ) - - for res in rnd.sample(resitele, 6): + for res in rnd.sample(resitele, min(len(resitele), 20)): Soustredeni_Ucastnici.objects.create(resitel=res, soustredeni=sous) sous.save() @@ -276,14 +286,15 @@ def create_test_data(size = 6, rnd = None): # posledni 2 cisla v rocniku nemaji deadline if (ci + 2 > cisel): - deadline = datetime.date(r.druhy_rok, ci - 1, - rnd.randint(1, 28)) - else: deadline = None - cislo = Cislo.objects.create(rocnik = r, cislo = str(ci), - datum_vydani=vydano, datum_deadline=deadline, - verejne_db=True) + cislo = Cislo.objects.create( + rocnik = r, + cislo = str(ci), + datum_vydani=vydano, + datum_deadline=deadline, + verejne_db=True + ) slovnik_cisel[ci] = cislo # generovani uloh @@ -339,7 +350,17 @@ def create_test_data(size = 6, rnd = None): max_body = rnd.randint(1, 8)) p.zadani = " ".join([rnd.choice(sloveso), rnd.choice(koho), rnd.choice(ceho), rnd.choice(jmeno), rnd.choice(kde)]) - p.vzorak = " - ".join([p.zadani, rnd.choice(reseni)]) + + #Tomův pokus o opravu bugu: + text_vzoraku = Text.objects.create( + na_web = rnd.choice(reseni), + do_cisla = rnd.choice(reseni) + ) + vzorak = TextNode.objects.create(text = text_vzoraku) + uloha_vzorak = UlohaVzorakNode.objects.create(uloha=p, first_child = vzorak) + p.UlohaVzorakNode = uloha_vzorak + + #p.vzorak = " - ".join([p.zadani, rnd.choice(reseni)]) p.save() @@ -354,6 +375,10 @@ def create_test_data(size = 6, rnd = None): # FIXME: misto typu ruzne typy objektu a vnoreni do sebe # TODO: vytvorit temata s ruznymi vlakny # TODO: nagenerovat starsim rocnikum pohadku + # TODO: nagenerovat články + # TODO: nagenerovat konfery + # TODO: vecpat obrázky všude, kde to jde + # TODO: nagenerovat nějaký strom nodů? # TODO: nahodne nagenerovat problemum reseni a prilohy reseni, hodnoceni