more tests
This commit is contained in:
parent
d3676250ab
commit
c790618a51
@ -131,6 +131,12 @@ class VersionLogMixin(object):
|
|||||||
res = res.order_by('-id')
|
res = res.order_by('-id')
|
||||||
return res
|
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):
|
class VersionLogQuerySet(models.query.QuerySet, VersionLogMixin):
|
||||||
pass
|
pass
|
||||||
|
@ -6,6 +6,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
|
from django.utils.timezone import utc
|
||||||
|
|
||||||
from djeuscan.models import EuscanResult
|
from djeuscan.models import EuscanResult
|
||||||
from djeuscan.tests.euscan_factory import VersionFactory, PackageFactory, \
|
from djeuscan.tests.euscan_factory import VersionFactory, PackageFactory, \
|
||||||
@ -36,7 +37,11 @@ class PackageModelTests(TestCase):
|
|||||||
|
|
||||||
class EuscanResultModelTests(TestCase):
|
class EuscanResultModelTests(TestCase):
|
||||||
def test_lastest(self):
|
def test_lastest(self):
|
||||||
result1 = EuscanResultFactory.create(datetime=datetime(2012, 04, 01))
|
result1 = EuscanResultFactory.create(
|
||||||
result2 = EuscanResultFactory.create(datetime=datetime(2012, 01, 01))
|
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.assertEqual(result1, EuscanResult.objects.latest())
|
||||||
self.assertNotEqual(result2, EuscanResult.objects.latest())
|
self.assertNotEqual(result2, EuscanResult.objects.latest())
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import StringIO
|
import StringIO
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from BeautifulSoup import BeautifulSoup
|
from BeautifulSoup import BeautifulSoup
|
||||||
|
|
||||||
from djeuscan.tests import SystemTestCase
|
from djeuscan.tests import SystemTestCase
|
||||||
@ -12,9 +14,6 @@ class PagesTest(SystemTestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
"""
|
|
||||||
Test index
|
|
||||||
"""
|
|
||||||
response = self.get("index")
|
response = self.get("index")
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
@ -27,6 +26,17 @@ class PagesTest(SystemTestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
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):
|
class SectionTests(SystemTestCase):
|
||||||
def _check_table(self, response, items, attr=None):
|
def _check_table(self, response, items, attr=None):
|
||||||
soup = BeautifulSoup(response.content)
|
soup = BeautifulSoup(response.content)
|
||||||
@ -45,8 +55,8 @@ class SectionTests(SystemTestCase):
|
|||||||
class CategoriesTests(SectionTests):
|
class CategoriesTests(SectionTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(CategoriesTests, self).setUp()
|
super(CategoriesTests, self).setUp()
|
||||||
self.categories = [PackageFactory.create().category
|
self.packages = [PackageFactory.create() for _ in range(10)]
|
||||||
for _ in range(10)]
|
self.categories = [p.category for p in self.packages]
|
||||||
|
|
||||||
def test_categories(self):
|
def test_categories(self):
|
||||||
response = self.get("categories")
|
response = self.get("categories")
|
||||||
@ -54,6 +64,13 @@ class CategoriesTests(SectionTests):
|
|||||||
|
|
||||||
self._check_table(response, self.categories)
|
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):
|
class HerdsTests(SectionTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -72,6 +89,13 @@ class HerdsTests(SectionTests):
|
|||||||
|
|
||||||
self._check_table(response, self.herds, attr="herd")
|
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):
|
class MaintainersTests(SectionTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -90,17 +114,26 @@ class MaintainersTests(SectionTests):
|
|||||||
|
|
||||||
self._check_table(response, self.maintainers, attr="name")
|
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):
|
class OverlayTests(SectionTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(OverlayTests, self).setUp()
|
super(OverlayTests, self).setUp()
|
||||||
self.overlays = [random_string() for _ in range(3)]
|
self.overlays = [random_string() for _ in range(3)]
|
||||||
|
self.packages = defaultdict(list)
|
||||||
|
|
||||||
for _ in range(3):
|
for _ in range(3):
|
||||||
self.package = PackageFactory.create()
|
package = PackageFactory.create()
|
||||||
for overlay in self.overlays:
|
for overlay in self.overlays:
|
||||||
VersionFactory.create(package=self.package,
|
VersionFactory.create(package=package,
|
||||||
overlay=overlay)
|
overlay=overlay)
|
||||||
|
self.packages[overlay].append(package)
|
||||||
|
|
||||||
def test_overlays(self):
|
def test_overlays(self):
|
||||||
response = self.get("overlays")
|
response = self.get("overlays")
|
||||||
@ -108,6 +141,13 @@ class OverlayTests(SectionTests):
|
|||||||
|
|
||||||
self._check_table(response, self.overlays)
|
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):
|
class WorldScanTests(SectionTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -84,7 +84,7 @@ def overlays(request):
|
|||||||
|
|
||||||
@render_to('euscan/overlay.html')
|
@render_to('euscan/overlay.html')
|
||||||
def overlay(request, overlay):
|
def overlay(request, overlay):
|
||||||
packages = Package.objects.for_overlay(overlay, last_versions=True)
|
packages = Package.objects.for_overlay(overlay)
|
||||||
if not packages:
|
if not packages:
|
||||||
raise Http404
|
raise Http404
|
||||||
return {'overlay': overlay, 'packages': packages}
|
return {'overlay': overlay, 'packages': packages}
|
||||||
|
Loading…
Reference in New Issue
Block a user