|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import random
|
|
|
|
import django.contrib.auth
|
|
|
|
from unittest import TestCase
|
|
|
|
from django.test import Client
|
|
|
|
from django.core.urlresolvers import reverse, resolve
|
|
|
|
from django.core.management import call_command
|
|
|
|
|
|
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Soustredeni, Nastaveni
|
|
|
|
from seminar.testutils import create_test_data
|
|
|
|
from seminar import ovvpfile
|
|
|
|
|
|
|
|
class SeminarBasicTests(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
create_test_data(size=2)
|
|
|
|
self.client = Client()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
call_command('flush', noinput=True, verbosity=0, interactive=False)
|
|
|
|
self.cleint = None
|
|
|
|
|
|
|
|
def test_rocniky(self):
|
|
|
|
r19 = Rocnik.objects.get(rocnik=21)
|
|
|
|
self.assertEqual(r19.roman(), 'XXI')
|
|
|
|
|
|
|
|
def test_render_cislo_e2e(self):
|
|
|
|
cs = Cislo.objects.all()
|
|
|
|
for c in cs[:4]:
|
|
|
|
url = reverse('seminar_cislo', args=(c.id,))
|
|
|
|
r = self.client.get(url)
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert len(r.content) >= 100
|
|
|
|
# TODO: Validate cntent as HTML
|
|
|
|
|
|
|
|
def test_render_problem_e2e(self):
|
|
|
|
ps = Problem.objects.all()
|
|
|
|
for p in ps[:4]:
|
|
|
|
url = reverse('seminar_problem', args=(p.id,))
|
|
|
|
r = self.client.get(url)
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert len(r.content) >= 100
|
|
|
|
# TODO: Validate cntent as HTML
|
|
|
|
|
|
|
|
def test_admin_url(self):
|
|
|
|
for m in [Skola, Resitel, Rocnik, Cislo, Problem, Reseni, Nastaveni]:
|
|
|
|
o = m.objects.first()
|
|
|
|
url = o.admin_url()
|
|
|
|
assert url
|
|
|
|
view = resolve(url)
|
|
|
|
assert view
|
|
|
|
|
|
|
|
def test_verejne_url(self):
|
|
|
|
for m in [Rocnik, Cislo, Problem]:
|
|
|
|
p = Problem.objects.first()
|
|
|
|
url = p.verejne_url()
|
|
|
|
assert url
|
|
|
|
view = resolve(url)
|
|
|
|
assert view
|
|
|
|
|
|
|
|
def test_ovvpfile(self):
|
|
|
|
filetext = "H1\ta\nH2\tb\tc\n\nx\ty\tz\n0\t1\t2\n3\t4\t5\n"
|
|
|
|
o = ovvpfile.parse(filetext)
|
|
|
|
assert len(o.headers) == 2
|
|
|
|
assert o.headers['H2'] == 'b\tc'
|
|
|
|
|
|
|
|
assert o.columns == ['x','y','z']
|
|
|
|
assert len(o.rows) == 2
|
|
|
|
assert o.rows[0]['z'] == '2'
|
|
|
|
|
|
|
|
t = o.to_string()
|
|
|
|
assert t == filetext
|
|
|
|
|
|
|
|
|