more tests

This commit is contained in:
volpino 2012-05-12 16:07:49 +02:00
parent d3676250ab
commit c790618a51
4 changed files with 61 additions and 10 deletions

View File

@ -131,6 +131,12 @@ class VersionLogMixin(object):
res = res.order_by('-id')
return res
def for_herd(self, herd, order=False):
res = self.filter(package__herds__id=herd.id)
if order:
res = res.order_by('-id')
return res
class VersionLogQuerySet(models.query.QuerySet, VersionLogMixin):
pass

View File

@ -6,6 +6,7 @@ from datetime import datetime
from django.test import TestCase
from django.db import IntegrityError
from django.utils.timezone import utc
from djeuscan.models import EuscanResult
from djeuscan.tests.euscan_factory import VersionFactory, PackageFactory, \
@ -36,7 +37,11 @@ class PackageModelTests(TestCase):
class EuscanResultModelTests(TestCase):
def test_lastest(self):
result1 = EuscanResultFactory.create(datetime=datetime(2012, 04, 01))
result2 = EuscanResultFactory.create(datetime=datetime(2012, 01, 01))
result1 = EuscanResultFactory.create(
datetime=datetime(2012, 04, 01, 12, 0, 0, 0, utc)
)
result2 = EuscanResultFactory.create(
datetime=datetime(2012, 01, 01, 12, 0, 0, 0, utc)
)
self.assertEqual(result1, EuscanResult.objects.latest())
self.assertNotEqual(result2, EuscanResult.objects.latest())

View File

@ -1,4 +1,6 @@
import StringIO
from collections import defaultdict
from BeautifulSoup import BeautifulSoup
from djeuscan.tests import SystemTestCase
@ -12,9 +14,6 @@ class PagesTest(SystemTestCase):
"""
def test_index(self):
"""
Test index
"""
response = self.get("index")
self.assertEqual(response.status_code, 200)
@ -27,6 +26,17 @@ class PagesTest(SystemTestCase):
self.assertEqual(response.status_code, 200)
class PackageTests(SystemTestCase):
def setUp(self):
super(PackageTests, self).setUp()
self.package = PackageFactory.create()
def test_package(self):
response = self.get("package", category=self.package.category,
package=self.package.name)
self.assertEqual(response.status_code, 200)
class SectionTests(SystemTestCase):
def _check_table(self, response, items, attr=None):
soup = BeautifulSoup(response.content)
@ -45,8 +55,8 @@ class SectionTests(SystemTestCase):
class CategoriesTests(SectionTests):
def setUp(self):
super(CategoriesTests, self).setUp()
self.categories = [PackageFactory.create().category
for _ in range(10)]
self.packages = [PackageFactory.create() for _ in range(10)]
self.categories = [p.category for p in self.packages]
def test_categories(self):
response = self.get("categories")
@ -54,6 +64,13 @@ class CategoriesTests(SectionTests):
self._check_table(response, self.categories)
def test_category(self):
category = self.categories[0]
response = self.get("category", category=category)
self.assertEqual(response.status_code, 200)
self._check_table(response, self.packages[:1], attr="name")
class HerdsTests(SectionTests):
def setUp(self):
@ -72,6 +89,13 @@ class HerdsTests(SectionTests):
self._check_table(response, self.herds, attr="herd")
def test_herd(self):
herd = self.herds[0]
response = self.get("herd", herd=herd.herd)
self.assertEqual(response.status_code, 200)
self._check_table(response, self.packages[:1], attr="name")
class MaintainersTests(SectionTests):
def setUp(self):
@ -90,17 +114,26 @@ class MaintainersTests(SectionTests):
self._check_table(response, self.maintainers, attr="name")
def test_maintainer(self):
maintainer = self.maintainers[0]
response = self.get("maintainer", maintainer_id=maintainer.pk)
self.assertEqual(response.status_code, 200)
self._check_table(response, self.packages[:1], attr="name")
class OverlayTests(SectionTests):
def setUp(self):
super(OverlayTests, self).setUp()
self.overlays = [random_string() for _ in range(3)]
self.packages = defaultdict(list)
for _ in range(3):
self.package = PackageFactory.create()
package = PackageFactory.create()
for overlay in self.overlays:
VersionFactory.create(package=self.package,
VersionFactory.create(package=package,
overlay=overlay)
self.packages[overlay].append(package)
def test_overlays(self):
response = self.get("overlays")
@ -108,6 +141,13 @@ class OverlayTests(SectionTests):
self._check_table(response, self.overlays)
def test_overlay(self):
overlay = self.overlays[0]
response = self.get("overlay", overlay=overlay)
self.assertEqual(response.status_code, 200)
self._check_table(response, self.packages[overlay], attr="name")
class WorldScanTests(SectionTests):
def setUp(self):

View File

@ -84,7 +84,7 @@ def overlays(request):
@render_to('euscan/overlay.html')
def overlay(request, overlay):
packages = Package.objects.for_overlay(overlay, last_versions=True)
packages = Package.objects.for_overlay(overlay)
if not packages:
raise Http404
return {'overlay': overlay, 'packages': packages}