From 9a39328e3bef8554d912dba2eede1906be7cbb08 Mon Sep 17 00:00:00 2001 From: volpino Date: Mon, 7 May 2012 14:27:54 +0200 Subject: [PATCH] more and more tests --- euscanwww/djeuscan/templatetags/div.py | 5 +- euscanwww/djeuscan/tests/__init__.py | 4 +- euscanwww/djeuscan/tests/test_charts.py | 15 ++--- euscanwww/djeuscan/tests/test_models.py | 8 +-- euscanwww/djeuscan/tests/test_views.py | 84 ++++++++++++++++++++++++- 5 files changed, 99 insertions(+), 17 deletions(-) diff --git a/euscanwww/djeuscan/templatetags/div.py b/euscanwww/djeuscan/templatetags/div.py index 9acc319..d9eb880 100644 --- a/euscanwww/djeuscan/templatetags/div.py +++ b/euscanwww/djeuscan/templatetags/div.py @@ -4,6 +4,9 @@ register = template.Library() def div(value, arg=None): - return float(value) / float(arg) + try: + return float(value) / float(arg) + except ZeroDivisionError: + return 0 register.filter('div', div) diff --git a/euscanwww/djeuscan/tests/__init__.py b/euscanwww/djeuscan/tests/__init__.py index 30a7e5b..0e27290 100644 --- a/euscanwww/djeuscan/tests/__init__.py +++ b/euscanwww/djeuscan/tests/__init__.py @@ -1,11 +1,11 @@ from urllib import urlencode -from django.utils import unittest +from django.test import TestCase from django.test.client import Client from django.core.urlresolvers import reverse -class SystemTestCase(unittest.TestCase): +class SystemTestCase(TestCase): """ Base class for system tests """ diff --git a/euscanwww/djeuscan/tests/test_charts.py b/euscanwww/djeuscan/tests/test_charts.py index f4cb865..cb0ac08 100644 --- a/euscanwww/djeuscan/tests/test_charts.py +++ b/euscanwww/djeuscan/tests/test_charts.py @@ -8,12 +8,6 @@ class ChartTests(SystemTestCase): Test charts """ - def setUp(self): - super(ChartTests, self).setUp() - self.a_herd = HerdFactory.create() - self.a_maintainer = MaintainerFactory.create() - self.a_category = PackageFactory.create().category - def test_statistics(self): response = self.get("statistics") self.assertEqual(response.status_code, 200) @@ -69,16 +63,19 @@ class ChartTests(SystemTestCase): self.assertEqual(response.status_code, 404) def test_herd(self): + a_herd = HerdFactory.create() response = self.get("chart_herd", chart="pie-packages", - herd=self.a_herd.herd) + herd=a_herd.herd) self.assertEqual(response.status_code, 200) def test_maintainer(self): + a_maintainer = MaintainerFactory.create() response = self.get("chart_maintainer", chart="pie-packages", - maintainer_id=self.a_maintainer.pk) + maintainer_id=a_maintainer.pk) self.assertEqual(response.status_code, 200) def test_category(self): + a_category = PackageFactory.create().category response = self.get("chart_category", chart="pie-packages", - category=self.a_category) + category=a_category) self.assertEqual(response.status_code, 200) diff --git a/euscanwww/djeuscan/tests/test_models.py b/euscanwww/djeuscan/tests/test_models.py index 4a320df..28a6f88 100644 --- a/euscanwww/djeuscan/tests/test_models.py +++ b/euscanwww/djeuscan/tests/test_models.py @@ -4,7 +4,7 @@ tests for models from datetime import datetime -from django.utils import unittest +from django.test import TestCase from django.db import IntegrityError from djeuscan.models import EuscanResult @@ -12,7 +12,7 @@ from djeuscan.tests.euscan_factory import VersionFactory, PackageFactory, \ EuscanResultFactory -class VersionModelTests(unittest.TestCase): +class VersionModelTests(TestCase): def test_creation(self): package = PackageFactory.build() version = VersionFactory.build(package=package) @@ -26,7 +26,7 @@ class VersionModelTests(unittest.TestCase): VersionFactory.create(package=package) -class PackageModelTests(unittest.TestCase): +class PackageModelTests(TestCase): def test_homepages(self): homepage = "http://gentoo.org http://mypackage.com" package = PackageFactory.build(homepage=homepage) @@ -34,7 +34,7 @@ class PackageModelTests(unittest.TestCase): ["http://gentoo.org", "http://mypackage.com"]) -class EuscanResultModelTests(unittest.TestCase): +class EuscanResultModelTests(TestCase): def test_lastest(self): result1 = EuscanResultFactory.create(datetime=datetime(2012, 04, 01)) result2 = EuscanResultFactory.create(datetime=datetime(2012, 01, 01)) diff --git a/euscanwww/djeuscan/tests/test_views.py b/euscanwww/djeuscan/tests/test_views.py index e241501..a1f4105 100644 --- a/euscanwww/djeuscan/tests/test_views.py +++ b/euscanwww/djeuscan/tests/test_views.py @@ -1,4 +1,8 @@ -from euscanwww.djeuscan.tests import SystemTestCase +from BeautifulSoup import BeautifulSoup + +from djeuscan.tests import SystemTestCase +from djeuscan.tests.euscan_factory import PackageFactory, HerdFactory, \ + MaintainerFactory, VersionFactory, random_string class NavigationTest(SystemTestCase): @@ -12,3 +16,81 @@ class NavigationTest(SystemTestCase): """ response = self.get("index") self.assertEqual(response.status_code, 200) + + def test_categories(self): + categories = [PackageFactory.create().category + for _ in range(10)] + + response = self.get("categories") + self.assertEqual(response.status_code, 200) + + soup = BeautifulSoup(response.content) + rows = soup.findAll("tr") + + self.assertEqual(len(rows), len(categories)) + + for category in categories: + self.assertTrue(category in response.content) + + def test_herds(self): + herds = [HerdFactory.create() for _ in range(10)] + packages = [] + for i in range(0, 10, 2): + p = PackageFactory.create() + p.herds.add(herds[i]) + p.herds.add(herds[i + 1]) + packages.append(p) + + response = self.get("herds") + self.assertEqual(response.status_code, 200) + + soup = BeautifulSoup(response.content) + rows = soup.findAll("tr") + + self.assertEqual(len(rows), len(herds)) + + for herd in herds: + self.assertTrue(herd.herd in response.content) + + def test_maintainers(self): + maintainers = [MaintainerFactory.create() for _ in range(10)] + packages = [] + for i in range(0, 10, 2): + p = PackageFactory.create() + p.maintainers.add(maintainers[i]) + p.maintainers.add(maintainers[i + 1]) + packages.append(p) + + response = self.get("maintainers") + self.assertEqual(response.status_code, 200) + + soup = BeautifulSoup(response.content) + rows = soup.findAll("tr") + + self.assertEqual(len(rows), len(maintainers)) + + for maintainer in maintainers: + self.assertTrue(maintainer.name in response.content) + + def test_overlays(self): + overlays = [random_string() for _ in range(3)] + + for _ in range(3): + package = PackageFactory.create() + for overlay in overlays: + VersionFactory.create(package=package, overlay=overlay) + + response = self.get("overlays") + self.assertEqual(response.status_code, 200) + + soup = BeautifulSoup(response.content) + rows = soup.findAll("tr") + + self.assertEqual(len(rows), len(overlays)) + + for overlay in overlays: + self.assertTrue(overlay in response.content) + + def test_world(self): + response = self.get("world") + self.assertEqual(response.status_code, 200)