From c78554b2164b9b09fa30f93371fa6d89cf6b5e89 Mon Sep 17 00:00:00 2001 From: Gary Wilson Jr Date: Fri, 29 May 2009 04:06:09 +0000 Subject: [PATCH] Added test for pickling of a model with an `ImageField`, refs #11103. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10860 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../regressiontests/model_fields/imagefield.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/regressiontests/model_fields/imagefield.py b/tests/regressiontests/model_fields/imagefield.py index 09bda6bb2d..dd79e7aefa 100644 --- a/tests/regressiontests/model_fields/imagefield.py +++ b/tests/regressiontests/model_fields/imagefield.py @@ -150,6 +150,23 @@ if Image: _ = p.mugshot.size self.assertEqual(p.mugshot.closed, True) + def test_pickle(self): + """ + Tests that ImageField can be pickled, unpickled, and that the + image of the unpickled version is the same as the original. + """ + import pickle + + p = Person(name="Joe") + p.mugshot.save("mug", self.file1) + dump = pickle.dumps(p) + + p2 = Person(name="Bob") + p2.mugshot = self.file1 + + loaded_p = pickle.loads(dump) + self.assertEqual(p.mugshot, loaded_p.mugshot) + class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase): """