tests for managers

This commit is contained in:
volpino 2012-05-13 11:37:05 +02:00
parent 2ec8cba794
commit b339efe012
3 changed files with 112 additions and 31 deletions

View File

@ -1,7 +1,9 @@
import random
from string import letters
import factory
from datetime import datetime
from collections import defaultdict
import factory
from djeuscan.models import Herd, Maintainer, Package, Version, EuscanResult
@ -52,3 +54,46 @@ class EuscanResultFactory(factory.Factory):
package = factory.LazyAttribute(lambda a: PackageFactory())
datetime = datetime.now()
result = "this is the result"
def setup_maintainers():
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)
return maintainers, packages
def setup_categories():
packages = [PackageFactory.create() for _ in range(10)]
categories = [p.category for p in packages]
return categories, packages
def setup_herds():
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)
return herds, packages
def setup_overlays():
overlays = [random_string() for _ in range(3)]
packages = defaultdict(list)
for _ in range(3):
package = PackageFactory.create()
for overlay in overlays:
VersionFactory.create(package=package,
overlay=overlay)
packages[overlay].append(package)
return overlays, packages

View File

@ -8,9 +8,10 @@ from django.test import TestCase
from django.db import IntegrityError
from django.utils.timezone import utc
from djeuscan.models import EuscanResult
from djeuscan.models import Package, EuscanResult
from djeuscan.tests.euscan_factory import VersionFactory, PackageFactory, \
EuscanResultFactory
EuscanResultFactory, setup_maintainers, setup_herds, setup_categories, \
setup_overlays
class VersionModelTests(TestCase):
@ -34,6 +35,63 @@ class PackageModelTests(TestCase):
self.assertEqual(package.homepages,
["http://gentoo.org", "http://mypackage.com"])
def test_for_maintainer(self):
maintainers, packages = setup_maintainers()
maintainer = maintainers[0]
self.assertEqual(
list(Package.objects.for_maintainer(maintainer)),
packages[:1]
)
def test_for_herd(self):
herds, packages = setup_herds()
herd = herds[0]
self.assertEqual(
list(Package.objects.for_herd(herd)),
packages[:1]
)
def test_for_category(self):
categories, packages = setup_categories()
category = categories[0]
self.assertEqual(
list(Package.objects.for_category(category)),
packages[:1]
)
def test_for_overlay(self):
overlays, packages = setup_overlays()
overlay = overlays[0]
package_ids = [p.pk for p in packages[overlay]]
for package in Package.objects.for_overlay(overlay):
self.assertTrue(package["id"] in package_ids)
def test_maintainers(self):
maintainers, packages = setup_maintainers()
maintainer_ids = [m.pk for m in maintainers]
for maintainer in Package.objects.maintainers():
self.assertTrue(maintainer["maintainers__id"] in maintainer_ids)
def test_herds(self):
herds, packages = setup_herds()
herd_names = [h.herd for h in herds]
for herd in Package.objects.herds():
self.assertTrue(herd["herds__herd"] in herd_names)
def test_categories(self):
categories, packages = setup_categories()
cat_names = [c["category"] for c in Package.objects.categories()]
for category in categories:
self.assertTrue(category in cat_names)
def test_overlays(self):
overlays, packages = setup_overlays()
overlay_names = [o["version__overlay"]
for o in Package.objects.overlays()]
for overlay in overlays:
self.assertTrue(overlay in overlay_names)
class EuscanResultModelTests(TestCase):
def test_lastest(self):

View File

@ -1,11 +1,10 @@
import StringIO
from collections import defaultdict
from BeautifulSoup import BeautifulSoup
from djeuscan.tests import SystemTestCase
from djeuscan.tests.euscan_factory import PackageFactory, HerdFactory, \
MaintainerFactory, VersionFactory, random_string
from djeuscan.tests.euscan_factory import PackageFactory, setup_maintainers, \
setup_herds, setup_categories, setup_overlays
class PagesTest(SystemTestCase):
@ -59,8 +58,7 @@ class SectionTests(SystemTestCase):
class CategoriesTests(SectionTests):
def setUp(self):
super(CategoriesTests, self).setUp()
self.packages = [PackageFactory.create() for _ in range(10)]
self.categories = [p.category for p in self.packages]
self.categories, self.packages = setup_categories()
def test_categories(self):
response = self.get("categories")
@ -84,13 +82,7 @@ class CategoriesTests(SectionTests):
class HerdsTests(SectionTests):
def setUp(self):
super(HerdsTests, self).setUp()
self.herds = [HerdFactory.create() for _ in range(10)]
self.packages = []
for i in range(0, 10, 2):
p = PackageFactory.create()
p.herds.add(self.herds[i])
p.herds.add(self.herds[i + 1])
self.packages.append(p)
self.herds, self.packages = setup_herds()
def test_herds(self):
response = self.get("herds")
@ -114,13 +106,7 @@ class HerdsTests(SectionTests):
class MaintainersTests(SectionTests):
def setUp(self):
super(MaintainersTests, self).setUp()
self.maintainers = [MaintainerFactory.create() for _ in range(10)]
self.packages = []
for i in range(0, 10, 2):
p = PackageFactory.create()
p.maintainers.add(self.maintainers[i])
p.maintainers.add(self.maintainers[i + 1])
self.packages.append(p)
self.maintainers, self.packages = setup_maintainers()
def test_maintainers(self):
response = self.get("maintainers")
@ -144,15 +130,7 @@ class MaintainersTests(SectionTests):
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):
package = PackageFactory.create()
for overlay in self.overlays:
VersionFactory.create(package=package,
overlay=overlay)
self.packages[overlay].append(package)
self.overlays, self.packages = setup_overlays()
def test_overlays(self):
response = self.get("overlays")