model validators
This commit is contained in:
@ -8,7 +8,9 @@ import factory
|
||||
from djeuscan.models import Herd, Maintainer, Package, Version, EuscanResult
|
||||
|
||||
|
||||
def random_string(length=10):
|
||||
def random_string(length=None):
|
||||
if length is None:
|
||||
length = random.randint(1, 30)
|
||||
return "".join([random.choice(letters) for _ in range(length)])
|
||||
|
||||
|
||||
@ -29,7 +31,9 @@ class MaintainerFactory(factory.Factory):
|
||||
class PackageFactory(factory.Factory):
|
||||
FACTORY_FOR = Package
|
||||
|
||||
category = factory.LazyAttribute(lambda a: random_string())
|
||||
category = factory.LazyAttribute(
|
||||
lambda a: "%s-%s" % (random_string(), random_string())
|
||||
)
|
||||
name = factory.LazyAttribute(lambda a: random_string())
|
||||
description = "This is a test package"
|
||||
homepage = "http://testpackage.com"
|
||||
|
@ -6,6 +6,7 @@ from datetime import datetime
|
||||
|
||||
from django.test import TestCase
|
||||
from django.db import IntegrityError
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.timezone import utc
|
||||
|
||||
from djeuscan.models import Package, EuscanResult
|
||||
@ -24,7 +25,7 @@ class VersionModelTests(TestCase):
|
||||
package = PackageFactory.create()
|
||||
VersionFactory.create(package=package)
|
||||
|
||||
with self.assertRaises(IntegrityError):
|
||||
with self.assertRaises((IntegrityError, ValidationError)):
|
||||
VersionFactory.create(package=package)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user