test test test!

This commit is contained in:
volpino 2012-05-07 10:19:48 +02:00
parent 23f43e869a
commit cb3dcaf713
5 changed files with 92 additions and 7 deletions

View File

@ -1,5 +1,13 @@
import random
from string import letters
import factory
from djeuscan.models import Herd, Maintainer, Package, Version
from datetime import datetime
from djeuscan.models import Herd, Maintainer, Package, Version, EuscanResult
def random_string(length=10):
return "".join([random.choice(letters) for _ in range(length)])
class HerdFactory(factory.Factory):
@ -19,8 +27,8 @@ class MaintainerFactory(factory.Factory):
class PackageFactory(factory.Factory):
FACTORY_FOR = Package
category = "Test Category"
name = "Test Package"
category = factory.LazyAttribute(lambda a: random_string())
name = factory.LazyAttribute(lambda a: random_string())
description = "This is a test package"
homepage = "http://testpackage.com"
@ -36,3 +44,11 @@ class VersionFactory(factory.Factory):
overlay = "gentoo"
urls = "http://packageurl.com"
alive = True
class EuscanResultFactory(factory.Factory):
FACTORY_FOR = EuscanResult
package = factory.LazyAttribute(lambda a: PackageFactory())
datetime = datetime.now()
result = "this is the result"

View File

@ -3,7 +3,7 @@ from euscanwww.djeuscan.tests import SystemTestCase
class ChartTests(SystemTestCase):
"""
Test main pages
Test charts
"""
def test_statistics(self):
@ -13,3 +13,49 @@ class ChartTests(SystemTestCase):
def test_pie_versions(self):
response = self.get("chart", chart="pie-versions")
self.assertEqual(response.status_code, 200)
def test_pie_packages(self):
response = self.get("chart", chart="pie-packages")
self.assertEqual(response.status_code, 200)
def test_packages(self):
response = self.get("chart", chart="packages")
self.assertEqual(response.status_code, 200)
def test_packages_options(self):
response = self.get("chart", chart="packages-small")
self.assertEqual(response.status_code, 200)
response = self.get("chart", chart="packages-weekly")
self.assertEqual(response.status_code, 200)
response = self.get("chart", chart="packages-monthly")
self.assertEqual(response.status_code, 200)
response = self.get("chart", chart="packages-yearly")
self.assertEqual(response.status_code, 200)
def test_packages_option_incorrect(self):
response = self.get("chart", chart="packages-trololol")
self.assertEqual(response.status_code, 404)
def test_versions(self):
response = self.get("chart", chart="versions")
self.assertEqual(response.status_code, 200)
def test_versions_options(self):
response = self.get("chart", chart="versions-small")
self.assertEqual(response.status_code, 200)
response = self.get("chart", chart="versions-weekly")
self.assertEqual(response.status_code, 200)
response = self.get("chart", chart="versions-monthly")
self.assertEqual(response.status_code, 200)
response = self.get("chart", chart="versions-yearly")
self.assertEqual(response.status_code, 200)
def test_versions_option_incorrect(self):
response = self.get("chart", chart="versions-trololol")
self.assertEqual(response.status_code, 404)

View File

@ -2,10 +2,14 @@
tests for models
"""
from datetime import datetime
from django.utils import unittest
from django.db import IntegrityError
from djeuscan.tests.euscan_factory import VersionFactory, PackageFactory
from djeuscan.models import EuscanResult
from djeuscan.tests.euscan_factory import VersionFactory, PackageFactory, \
EuscanResultFactory
class VersionModelTests(unittest.TestCase):
@ -20,3 +24,18 @@ class VersionModelTests(unittest.TestCase):
with self.assertRaises(IntegrityError):
VersionFactory.create(package=package)
class PackageModelTests(unittest.TestCase):
def test_homepages(self):
homepage = "http://gentoo.org http://mypackage.com"
package = PackageFactory.build(homepage=homepage)
self.assertEqual(package.homepages,
["http://gentoo.org", "http://mypackage.com"])
class EuscanResultModelTests(unittest.TestCase):
def test_lastest(self):
result1 = EuscanResultFactory.create(datetime=datetime(2012, 04, 01))
result2 = EuscanResultFactory.create(datetime=datetime(2012, 01, 01))
self.assertEqual(result1, EuscanResult.objects.latest())

View File

@ -0,0 +1 @@
<h1>Not Found</h1>

View File

@ -7,13 +7,16 @@ import os
from os.path import dirname, abspath
from django.conf import settings
EUSCAN_ROOT = os.path.join(dirname(dirname(abspath(__file__))), "euscanwww")
settings.configure(
DATABASES={
'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory;'}
},
INSTALLED_APPS=['euscanwww', 'djeuscan'],
INSTALLED_APPS=['euscanwww.euscanwww', 'djeuscan'],
ROOT_URLCONF='euscanwww.euscanwww.urls',
EUSCAN_ROOT=os.path.join(dirname(dirname(abspath(__file__))), "euscanwww"),
EUSCAN_ROOT=EUSCAN_ROOT,
RRD_ROOT=os.path.join(EUSCAN_ROOT, 'var', 'rrd')
)