euscan-ng/euscanwww/djeuscan/tests/test_models.py

48 lines
1.5 KiB
Python
Raw Normal View History

"""
tests for models
"""
2012-05-07 10:19:48 +02:00
from datetime import datetime
2012-05-07 14:27:54 +02:00
from django.test import TestCase
from django.db import IntegrityError
2012-05-12 16:07:49 +02:00
from django.utils.timezone import utc
2012-05-07 10:19:48 +02:00
from djeuscan.models import EuscanResult
from djeuscan.tests.euscan_factory import VersionFactory, PackageFactory, \
EuscanResultFactory
2012-05-07 14:27:54 +02:00
class VersionModelTests(TestCase):
def test_creation(self):
package = PackageFactory.build()
version = VersionFactory.build(package=package)
self.assertEqual(version.package, package)
def test_not_allowed_creation(self):
package = PackageFactory.create()
VersionFactory.create(package=package)
with self.assertRaises(IntegrityError):
VersionFactory.create(package=package)
2012-05-07 10:19:48 +02:00
2012-05-07 14:27:54 +02:00
class PackageModelTests(TestCase):
2012-05-07 10:19:48 +02:00
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"])
2012-05-07 14:27:54 +02:00
class EuscanResultModelTests(TestCase):
2012-05-07 10:19:48 +02:00
def test_lastest(self):
2012-05-12 16:07:49 +02:00
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)
)
2012-05-07 10:19:48 +02:00
self.assertEqual(result1, EuscanResult.objects.latest())
2012-05-07 10:56:54 +02:00
self.assertNotEqual(result2, EuscanResult.objects.latest())