|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import random
|
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
import django.contrib.auth
|
|
|
|
from django.db import transaction
|
|
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni
|
|
|
|
|
|
|
|
User = django.contrib.auth.get_user_model()
|
|
|
|
|
|
|
|
@transaction.atomic
|
|
|
|
def create_test_data():
|
|
|
|
# pevna pseudo-nahodnost
|
|
|
|
rnd = random.Random(x=42)
|
|
|
|
|
|
|
|
# users
|
|
|
|
admin = User.objects.create_superuser(username='admin', email='', password='admin')
|
|
|
|
|
|
|
|
orgs = []
|
|
|
|
for org in ['anet', 'bara', 'cyril', 'david', 'eva', 'filip']:
|
|
|
|
o = User.objects.create_user(username=org, password=org)
|
|
|
|
o.first_name = org.capitalize()
|
|
|
|
o.save()
|
|
|
|
orgs.append(o)
|
|
|
|
|
|
|
|
# skoly
|
|
|
|
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='101 00', ulice=u'Krátká 5', nazev=u'První SŠ')
|
|
|
|
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='102 00', ulice=u'Dlouhá 5', nazev=u'Druhá SŠ')
|
|
|
|
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='103 00', ulice=u'Široká 3', nazev=u'Třetí SŠ')
|
|
|
|
Skola.objects.create(mesto = u'Ostrava', stat='CZ', psc='700 00', ulice=u'Hluboká 42', nazev=u'Hutní gympl')
|
|
|
|
Skola.objects.create(mesto = u'Humenné', stat='SK', psc='012 34', ulice=u'Pltká 1', nazev=u'Sredná škuola')
|
|
|
|
|
|
|
|
# resitele
|
|
|
|
for i in range(20):
|
|
|
|
skola = rnd.choice(Skola.objects.all())
|
|
|
|
pohlavi = rnd.randint(0,1)
|
|
|
|
Resitel.objects.create(skola = skola, datum_prihlaseni = datetime.date(rnd.randint(2002, 2014), rnd.randint(1,12), 1),
|
|
|
|
jmeno = u'Řešitel' if pohlavi else u'Řešitelka', prijmeni = 'Číslo-%s' % (i), rok_maturity = rnd.randint(2015, 2019),
|
|
|
|
stat = skola.stat, zasilat = Resitel.ZASILAT_NIKAM, pohlavi_muz = pohlavi)
|
|
|
|
resitele = list(Resitel.objects.all())
|
|
|
|
|
|
|
|
# rocniky
|
|
|
|
for ri in range(17, 22):
|
|
|
|
r = Rocnik.objects.create(prvni_rok = 1993 + ri, rocnik = ri)
|
|
|
|
|
|
|
|
# cisla
|
|
|
|
cisel = rnd.randint(4, 6)
|
|
|
|
cs = {}
|
|
|
|
for ci in range(1, cisel + 1):
|
|
|
|
vydano = datetime.date(r.prvni_rok, ci + 6, 1)
|
|
|
|
deadline = datetime.date(r.prvni_rok, ci + 8, 1) if ci + 2 < cisel else None
|
|
|
|
c = Cislo.objects.create(rocnik = r, cislo = str(ci), datum_vydani=vydano, datum_deadline=deadline)
|
|
|
|
cs[ci] = c
|
|
|
|
|
|
|
|
# problemy resene v ci
|
|
|
|
seq='#ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
|
|
if ci >= 3:
|
|
|
|
for pi in range(1, 4):
|
|
|
|
p = Problem.objects.create(autor = rnd.choice(orgs), cislo_zadani=cs[ci-2], cislo_reseni=cs[ci],
|
|
|
|
opravovatel = rnd.choice(orgs), kod = str(pi), nazev = u'Dummy úloha %s-%s' % (seq[ci], seq[pi]),
|
|
|
|
stav = Problem.STAV_ZADANY, typ = Problem.TYP_ULOHA, body = rnd.randint(1, 5))
|
|
|
|
p.text_problemu = (u"<p>Text problému <strong>%s.%s %s</strong><em> [id %d]</em> za %d body.</p>" %
|
|
|
|
(p.cislo_zadani.kod(), p.kod, p.nazev, p.id, p.body))
|
|
|
|
p.text_problemu_org = u"<p><strong>Neveřejný</strong> text problému.</p>"
|
|
|
|
p.save()
|
|
|
|
|
|
|
|
res_sel = rnd.sample(resitele, min(rnd.randint(3, 10), len(resitele) - 2))
|
|
|
|
for resitel in res_sel:
|
|
|
|
res = Reseni.objects.create(problem = p, resitel = resitel,
|
|
|
|
body = rnd.randint(0, p.body), cislo_body = cs[ci])
|
|
|
|
|
|
|
|
nastaveni = Nastaveni.objects.create(aktualni_rocnik = Rocnik.objects.last(),
|
|
|
|
aktualni_cislo = Cislo.objects.last())
|
|
|
|
|
|
|
|
|
|
|
|
class SeminarTests(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
create_test_data()
|
|
|
|
|
|
|
|
def test_rocniky(self):
|
|
|
|
r19 = Rocnik.objects.get(rocnik=19)
|
|
|
|
self.assertEqual(r19.roman(), 'XIX')
|
|
|
|
|