From 297a111cc918c6451f1b66e3fe3572a9f3fc6b8f Mon Sep 17 00:00:00 2001 From: Raphaƫl Barrois Date: Wed, 28 Aug 2013 01:30:15 +0200 Subject: Allow FACTORY_FOR = 'app.Model' for Django (Closes #66). --- tests/test_django.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests') diff --git a/tests/test_django.py b/tests/test_django.py index 9d02131..b27562c 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -157,6 +157,35 @@ class DjangoPkSequenceTestCase(django_test.TestCase): self.assertEqual(11, std2.pk) +@unittest.skipIf(django is None, "Django not installed.") +class DjangoModelLoadingTestCase(django_test.TestCase): + """Tests FACTORY_FOR = 'app.Model' pattern.""" + + def test_loading(self): + class ExampleFactory(factory.DjangoModelFactory): + FACTORY_FOR = 'djapp.StandardModel' + + self.assertEqual(models.StandardModel, ExampleFactory._load_target_class()) + + def test_building(self): + class ExampleFactory(factory.DjangoModelFactory): + FACTORY_FOR = 'djapp.StandardModel' + + e = ExampleFactory.build() + self.assertEqual(models.StandardModel, e.__class__) + + def test_cache(self): + class ExampleFactory(factory.DjangoModelFactory): + FACTORY_FOR = 'djapp.StandardModel' + + self.assertEqual('djapp.StandardModel', ExampleFactory._associated_class) + self.assertIsNone(ExampleFactory._associated_model) + + self.assertEqual(models.StandardModel, ExampleFactory._load_target_class()) + self.assertEqual('djapp.StandardModel', ExampleFactory._associated_class) + self.assertEqual(models.StandardModel, ExampleFactory._associated_model) + + @unittest.skipIf(django is None, "Django not installed.") class DjangoNonIntegerPkTestCase(django_test.TestCase): def setUp(self): -- cgit v1.2.3