diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-08-28 01:30:15 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-08-28 01:30:15 +0200 |
commit | 297a111cc918c6451f1b66e3fe3572a9f3fc6b8f (patch) | |
tree | 1b7d68414a71b8e072b285d1a142da2ad3fc75af /tests/test_django.py | |
parent | 7fc3e4cbdae050dcde49ea3101636ddf57d6c96d (diff) | |
download | factory-boy-297a111cc918c6451f1b66e3fe3572a9f3fc6b8f.tar factory-boy-297a111cc918c6451f1b66e3fe3572a9f3fc6b8f.tar.gz |
Allow FACTORY_FOR = 'app.Model' for Django (Closes #66).
Diffstat (limited to 'tests/test_django.py')
-rw-r--r-- | tests/test_django.py | 29 |
1 files changed, 29 insertions, 0 deletions
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 @@ -158,6 +158,35 @@ class DjangoPkSequenceTestCase(django_test.TestCase): @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): super(DjangoNonIntegerPkTestCase, self).setUp() |