From 1a00eef263f787a9f3d98fbaa43ec30ad9ac4071 Mon Sep 17 00:00:00 2001 From: Raphaƫl Barrois Date: Wed, 3 Sep 2014 22:53:02 +0200 Subject: Fix test running without django (Closes #161). --- tests/test_django.py | 101 +++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 56 deletions(-) (limited to 'tests') diff --git a/tests/test_django.py b/tests/test_django.py index fd9c876..95e0256 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -57,21 +57,9 @@ if django is not None: from django.test import utils as django_test_utils from django.db.models import signals from .djapp import models -else: # pragma: no cover - django_test = unittest - - class Fake(object): - pass - models = Fake() - models.StandardModel = Fake - models.StandardSon = None - models.AbstractBase = Fake - models.ConcreteSon = Fake - models.NonIntegerPk = Fake - models.WithFile = Fake - models.WithImage = Fake - models.WithSignals = Fake +else: + django_test = unittest test_state = {} @@ -98,72 +86,73 @@ def tearDownModule(): django_test_utils.teardown_test_environment() -class StandardFactory(factory.django.DjangoModelFactory): - class Meta: - model = models.StandardModel +if django is not None: + class StandardFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.StandardModel - foo = factory.Sequence(lambda n: "foo%d" % n) + foo = factory.Sequence(lambda n: "foo%d" % n) -class StandardFactoryWithPKField(factory.django.DjangoModelFactory): - class Meta: - model = models.StandardModel - django_get_or_create = ('pk',) + class StandardFactoryWithPKField(factory.django.DjangoModelFactory): + class Meta: + model = models.StandardModel + django_get_or_create = ('pk',) - foo = factory.Sequence(lambda n: "foo%d" % n) - pk = None + foo = factory.Sequence(lambda n: "foo%d" % n) + pk = None -class NonIntegerPkFactory(factory.django.DjangoModelFactory): - class Meta: - model = models.NonIntegerPk + class NonIntegerPkFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.NonIntegerPk - foo = factory.Sequence(lambda n: "foo%d" % n) - bar = '' + foo = factory.Sequence(lambda n: "foo%d" % n) + bar = '' -class AbstractBaseFactory(factory.django.DjangoModelFactory): - class Meta: - model = models.AbstractBase - abstract = True + class AbstractBaseFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.AbstractBase + abstract = True - foo = factory.Sequence(lambda n: "foo%d" % n) + foo = factory.Sequence(lambda n: "foo%d" % n) -class ConcreteSonFactory(AbstractBaseFactory): - class Meta: - model = models.ConcreteSon + class ConcreteSonFactory(AbstractBaseFactory): + class Meta: + model = models.ConcreteSon -class AbstractSonFactory(AbstractBaseFactory): - class Meta: - model = models.AbstractSon + class AbstractSonFactory(AbstractBaseFactory): + class Meta: + model = models.AbstractSon -class ConcreteGrandSonFactory(AbstractBaseFactory): - class Meta: - model = models.ConcreteGrandSon + class ConcreteGrandSonFactory(AbstractBaseFactory): + class Meta: + model = models.ConcreteGrandSon -class WithFileFactory(factory.django.DjangoModelFactory): - class Meta: - model = models.WithFile + class WithFileFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.WithFile - if django is not None: - afile = factory.django.FileField() + if django is not None: + afile = factory.django.FileField() -class WithImageFactory(factory.django.DjangoModelFactory): - class Meta: - model = models.WithImage + class WithImageFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.WithImage - if django is not None: - animage = factory.django.ImageField() + if django is not None: + animage = factory.django.ImageField() -class WithSignalsFactory(factory.django.DjangoModelFactory): - class Meta: - model = models.WithSignals + class WithSignalsFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.WithSignals @unittest.skipIf(django is None, "Django not installed.") -- cgit v1.2.3