From 5363951bb62ca90d971bf036851dea564204ed2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Fri, 27 Mar 2015 17:00:32 +0100 Subject: Support declarations in FileField/ImageField. Previously, the declarations (``factory.Sequence`` & co) weren't properly computed. --- tests/djapp/models.py | 1 + tests/test_django.py | 11 +++++++++++ 2 files changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/djapp/models.py b/tests/djapp/models.py index 96ee5cf..1c1fd8e 100644 --- a/tests/djapp/models.py +++ b/tests/djapp/models.py @@ -79,6 +79,7 @@ if Image is not None: # PIL is available class WithImage(models.Model): animage = models.ImageField(upload_to=WITHFILE_UPLOAD_TO) + size = models.IntegerField(default=0) else: class WithImage(models.Model): diff --git a/tests/test_django.py b/tests/test_django.py index 9ac8f5c..ac52769 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -497,6 +497,17 @@ class DjangoImageFieldTestCase(unittest.TestCase): self.assertEqual(100, o.animage.height) self.assertEqual('django/example.jpg', o.animage.name) + def test_complex_create(self): + o = WithImageFactory.create( + size=10, + animage__filename=factory.Sequence(lambda n: 'img%d.jpg' % n), + __sequence=42, + animage__width=factory.SelfAttribute('..size'), + animage__height=factory.SelfAttribute('width'), + ) + self.assertIsNotNone(o.pk) + self.assertEqual('django/img42.jpg', o.animage.name) + def test_with_content(self): o = WithImageFactory.build(animage__width=13, animage__color='red') self.assertIsNone(o.pk) -- cgit v1.2.3