summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2013-07-02 11:14:08 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2013-07-02 11:31:00 +0200
commit5b285bca1f6572d4eda7fb04fe7d4d4fef33ab0b (patch)
tree07fe7d8de673815376b25cf11330d52ee1537eb1
parent0a35ba85329803ef39028edb238d5b5241585128 (diff)
downloadfactory-boy-5b285bca1f6572d4eda7fb04fe7d4d4fef33ab0b.tar
factory-boy-5b285bca1f6572d4eda7fb04fe7d4d4fef33ab0b.tar.gz
Fix default color for factory.django.ImageField
-rw-r--r--factory/django.py2
-rw-r--r--tests/test_django.py22
2 files changed, 22 insertions, 2 deletions
diff --git a/factory/django.py b/factory/django.py
index 04bdbbf..1672fcc 100644
--- a/factory/django.py
+++ b/factory/django.py
@@ -191,7 +191,7 @@ class ImageField(FileField):
width = params.get('width', 100)
height = params.get('height', width)
- color = params.get('blue')
+ color = params.get('color', 'blue')
image_format = params.get('format', 'JPEG')
thumb = Image.new('RGB', (width, height), color)
diff --git a/tests/test_django.py b/tests/test_django.py
index 05ee961..5335a94 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -51,6 +51,7 @@ if django is not None:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.djapp.settings')
from django import test as django_test
+ from django.conf import settings
from django.db import models as django_models
from django.test import simple as django_test_simple
from django.test import utils as django_test_utils
@@ -306,12 +307,31 @@ class DjangoImageFieldTestCase(unittest.TestCase):
self.assertEqual('django/example.jpg', o.animage.name)
def test_with_content(self):
- o = WithImageFactory.build(animage__width=13, animage__color='blue')
+ o = WithImageFactory.build(animage__width=13, animage__color='red')
self.assertIsNone(o.pk)
self.assertEqual(13, o.animage.width)
self.assertEqual(13, o.animage.height)
self.assertEqual('django/example.jpg', o.animage.name)
+ i = Image.open(os.path.join(settings.MEDIA_ROOT, o.animage.name))
+ colors = i.getcolors()
+ # 169 pixels with rgb(254, 0, 0)
+ self.assertEqual([(169, (254, 0, 0))], colors)
+ self.assertEqual('JPEG', i.format)
+
+ def test_gif(self):
+ o = WithImageFactory.build(animage__width=13, animage__color='blue', animage__format='GIF')
+ self.assertIsNone(o.pk)
+ self.assertEqual(13, o.animage.width)
+ self.assertEqual(13, o.animage.height)
+ self.assertEqual('django/example.jpg', o.animage.name)
+
+ i = Image.open(os.path.join(settings.MEDIA_ROOT, o.animage.name))
+ colors = i.getcolors()
+ # 169 pixels with color 190 from the GIF palette
+ self.assertEqual([(169, 190)], colors)
+ self.assertEqual('GIF', i.format)
+
def test_with_file(self):
with open(testdata.TESTIMAGE_PATH, 'rb') as f:
o = WithImageFactory.build(animage__from_file=f)