more and more tests

This commit is contained in:
volpino 2012-05-07 14:27:54 +02:00
parent 04d54f4689
commit 9a39328e3b
5 changed files with 99 additions and 17 deletions

View File

@ -4,6 +4,9 @@ register = template.Library()
def div(value, arg=None): def div(value, arg=None):
try:
return float(value) / float(arg) return float(value) / float(arg)
except ZeroDivisionError:
return 0
register.filter('div', div) register.filter('div', div)

View File

@ -1,11 +1,11 @@
from urllib import urlencode from urllib import urlencode
from django.utils import unittest from django.test import TestCase
from django.test.client import Client from django.test.client import Client
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
class SystemTestCase(unittest.TestCase): class SystemTestCase(TestCase):
""" """
Base class for system tests Base class for system tests
""" """

View File

@ -8,12 +8,6 @@ class ChartTests(SystemTestCase):
Test charts 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): def test_statistics(self):
response = self.get("statistics") response = self.get("statistics")
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@ -69,16 +63,19 @@ class ChartTests(SystemTestCase):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_herd(self): def test_herd(self):
a_herd = HerdFactory.create()
response = self.get("chart_herd", chart="pie-packages", response = self.get("chart_herd", chart="pie-packages",
herd=self.a_herd.herd) herd=a_herd.herd)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_maintainer(self): def test_maintainer(self):
a_maintainer = MaintainerFactory.create()
response = self.get("chart_maintainer", chart="pie-packages", 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) self.assertEqual(response.status_code, 200)
def test_category(self): def test_category(self):
a_category = PackageFactory.create().category
response = self.get("chart_category", chart="pie-packages", response = self.get("chart_category", chart="pie-packages",
category=self.a_category) category=a_category)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)

View File

@ -4,7 +4,7 @@ tests for models
from datetime import datetime from datetime import datetime
from django.utils import unittest from django.test import TestCase
from django.db import IntegrityError from django.db import IntegrityError
from djeuscan.models import EuscanResult from djeuscan.models import EuscanResult
@ -12,7 +12,7 @@ from djeuscan.tests.euscan_factory import VersionFactory, PackageFactory, \
EuscanResultFactory EuscanResultFactory
class VersionModelTests(unittest.TestCase): class VersionModelTests(TestCase):
def test_creation(self): def test_creation(self):
package = PackageFactory.build() package = PackageFactory.build()
version = VersionFactory.build(package=package) version = VersionFactory.build(package=package)
@ -26,7 +26,7 @@ class VersionModelTests(unittest.TestCase):
VersionFactory.create(package=package) VersionFactory.create(package=package)
class PackageModelTests(unittest.TestCase): class PackageModelTests(TestCase):
def test_homepages(self): def test_homepages(self):
homepage = "http://gentoo.org http://mypackage.com" homepage = "http://gentoo.org http://mypackage.com"
package = PackageFactory.build(homepage=homepage) package = PackageFactory.build(homepage=homepage)
@ -34,7 +34,7 @@ class PackageModelTests(unittest.TestCase):
["http://gentoo.org", "http://mypackage.com"]) ["http://gentoo.org", "http://mypackage.com"])
class EuscanResultModelTests(unittest.TestCase): class EuscanResultModelTests(TestCase):
def test_lastest(self): def test_lastest(self):
result1 = EuscanResultFactory.create(datetime=datetime(2012, 04, 01)) result1 = EuscanResultFactory.create(datetime=datetime(2012, 04, 01))
result2 = EuscanResultFactory.create(datetime=datetime(2012, 01, 01)) result2 = EuscanResultFactory.create(datetime=datetime(2012, 01, 01))

View File

@ -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): class NavigationTest(SystemTestCase):
@ -12,3 +16,81 @@ class NavigationTest(SystemTestCase):
""" """
response = self.get("index") response = self.get("index")
self.assertEqual(response.status_code, 200) 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)