diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2014-09-03 22:53:02 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2014-09-03 22:53:06 +0200 |
commit | 1a00eef263f787a9f3d98fbaa43ec30ad9ac4071 (patch) | |
tree | 8298969dd77e4119e54465c0597a94402f956540 /tests | |
parent | 82988e154391cc37f81eb398bbfa91f30f524349 (diff) | |
download | factory-boy-1a00eef263f787a9f3d98fbaa43ec30ad9ac4071.tar factory-boy-1a00eef263f787a9f3d98fbaa43ec30ad9ac4071.tar.gz |
Fix test running without django (Closes #161).
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_django.py | 101 |
1 files changed, 45 insertions, 56 deletions
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.") |