From 5b285bca1f6572d4eda7fb04fe7d4d4fef33ab0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Tue, 2 Jul 2013 11:14:08 +0200 Subject: Fix default color for factory.django.ImageField --- tests/test_django.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'tests') 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) -- cgit v1.2.3