tests for managers
This commit is contained in:
parent
2ec8cba794
commit
b339efe012
@ -1,7 +1,9 @@
|
|||||||
import random
|
import random
|
||||||
from string import letters
|
from string import letters
|
||||||
import factory
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
import factory
|
||||||
|
|
||||||
from djeuscan.models import Herd, Maintainer, Package, Version, EuscanResult
|
from djeuscan.models import Herd, Maintainer, Package, Version, EuscanResult
|
||||||
|
|
||||||
@ -52,3 +54,46 @@ class EuscanResultFactory(factory.Factory):
|
|||||||
package = factory.LazyAttribute(lambda a: PackageFactory())
|
package = factory.LazyAttribute(lambda a: PackageFactory())
|
||||||
datetime = datetime.now()
|
datetime = datetime.now()
|
||||||
result = "this is the result"
|
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
|
||||||
|
@ -8,9 +8,10 @@ from django.test import TestCase
|
|||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.utils.timezone import utc
|
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, \
|
from djeuscan.tests.euscan_factory import VersionFactory, PackageFactory, \
|
||||||
EuscanResultFactory
|
EuscanResultFactory, setup_maintainers, setup_herds, setup_categories, \
|
||||||
|
setup_overlays
|
||||||
|
|
||||||
|
|
||||||
class VersionModelTests(TestCase):
|
class VersionModelTests(TestCase):
|
||||||
@ -34,6 +35,63 @@ class PackageModelTests(TestCase):
|
|||||||
self.assertEqual(package.homepages,
|
self.assertEqual(package.homepages,
|
||||||
["http://gentoo.org", "http://mypackage.com"])
|
["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):
|
class EuscanResultModelTests(TestCase):
|
||||||
def test_lastest(self):
|
def test_lastest(self):
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
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
|
||||||
from djeuscan.tests.euscan_factory import PackageFactory, HerdFactory, \
|
from djeuscan.tests.euscan_factory import PackageFactory, setup_maintainers, \
|
||||||
MaintainerFactory, VersionFactory, random_string
|
setup_herds, setup_categories, setup_overlays
|
||||||
|
|
||||||
|
|
||||||
class PagesTest(SystemTestCase):
|
class PagesTest(SystemTestCase):
|
||||||
@ -59,8 +58,7 @@ class SectionTests(SystemTestCase):
|
|||||||
class CategoriesTests(SectionTests):
|
class CategoriesTests(SectionTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(CategoriesTests, self).setUp()
|
super(CategoriesTests, self).setUp()
|
||||||
self.packages = [PackageFactory.create() for _ in range(10)]
|
self.categories, self.packages = setup_categories()
|
||||||
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")
|
||||||
@ -84,13 +82,7 @@ class CategoriesTests(SectionTests):
|
|||||||
class HerdsTests(SectionTests):
|
class HerdsTests(SectionTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(HerdsTests, self).setUp()
|
super(HerdsTests, self).setUp()
|
||||||
self.herds = [HerdFactory.create() for _ in range(10)]
|
self.herds, self.packages = setup_herds()
|
||||||
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)
|
|
||||||
|
|
||||||
def test_herds(self):
|
def test_herds(self):
|
||||||
response = self.get("herds")
|
response = self.get("herds")
|
||||||
@ -114,13 +106,7 @@ class HerdsTests(SectionTests):
|
|||||||
class MaintainersTests(SectionTests):
|
class MaintainersTests(SectionTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(MaintainersTests, self).setUp()
|
super(MaintainersTests, self).setUp()
|
||||||
self.maintainers = [MaintainerFactory.create() for _ in range(10)]
|
self.maintainers, self.packages = setup_maintainers()
|
||||||
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)
|
|
||||||
|
|
||||||
def test_maintainers(self):
|
def test_maintainers(self):
|
||||||
response = self.get("maintainers")
|
response = self.get("maintainers")
|
||||||
@ -144,15 +130,7 @@ class MaintainersTests(SectionTests):
|
|||||||
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, self.packages = setup_overlays()
|
||||||
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)
|
|
||||||
|
|
||||||
def test_overlays(self):
|
def test_overlays(self):
|
||||||
response = self.get("overlays")
|
response = self.get("overlays")
|
||||||
|
Loading…
Reference in New Issue
Block a user