From 3ac2b34dd8120eb247f0364dc8f374a511f55ba5 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Thu, 14 May 2015 00:49:20 +0200 Subject: [PATCH] Cleanup po upravach routingu a testu --- seminar/tests.py | 27 +++++++++++++++++++++------ seminar/utils.py | 12 ++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 seminar/utils.py diff --git a/seminar/tests.py b/seminar/tests.py index b9a2fe38..ce61a1b7 100644 --- a/seminar/tests.py +++ b/seminar/tests.py @@ -5,10 +5,10 @@ import random import django.contrib.auth from unittest import TestCase from django.test import Client -from django.core.urlresolvers import reverse +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, Nastaveni +from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Soustredeni, Nastaveni from seminar.testutils import create_test_data class SeminarBasicTests(TestCase): @@ -26,8 +26,8 @@ class SeminarBasicTests(TestCase): def test_render_cislo_e2e(self): cs = Cislo.objects.all() - for c in cs[:8]: - url = reverse('seminar.cislo', args=(c.id,)) + 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 @@ -35,11 +35,26 @@ class SeminarBasicTests(TestCase): def test_render_problem_e2e(self): ps = Problem.objects.all() - for p in ps[:10]: - url = reverse('seminar.problem', args=(p.id,)) + 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 diff --git a/seminar/utils.py b/seminar/utils.py new file mode 100644 index 00000000..26b23750 --- /dev/null +++ b/seminar/utils.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- + +def roman(num): + ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1) + nums = ('M', 'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I') + res = "" + for i, n in zip(ints, nums): + res += n * (num // i) + num %= i + return res + +