I'm trying to write a test for a FileField on a model Photo. The FieldField is inherited from an base class Asset. I need to save the dimensions of the photo in the database, so I've got my own save method on my Photo model:
def save(self, *args, **kwargs): # save the instance, so we can use the uploaded photo super(Photo, self).save(*args, **kwargs) im = Image.open(os.path.join(MEDIA_ROOT, self.file.name)) self.width, self.height = im.size super(Photo, self).save(*args, **kwargs) This works, but I can't test it. When I try to create an instance of this model in the test suite, it appears that the file is never moved to the MEDIA_ROOT, and self.file.name refers to the original file in the test directory of my app. ====================================================================== ERROR: testPhoto (caramel.content.tests.modelTests.ContentTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "../myproject/myproject/myapp/tests/modelTests.py", line 22, in setUp credit="John Smith") File "/Users/username/workspace/eclipse/lib/python2.7/site-packages/django/db/models/manager.py", line 138, in create return self.get_query_set().create(**kwargs) File "/Users/username/workspace/eclipse/lib/python2.7/site-packages/django/db/models/query.py", line 360, in create obj.save(force_insert=True, using=self.db) File "../myproject/myproject/myapp/models.py", line 97, in save im = Image.open(os.path.join(MEDIA_ROOT, self.file.name)) File "/Users/username/workspace/eclipse/lib/python2.7/site-packages/PIL/Image.py", line 1952, in open fp = __builtin__.open(fp, "rb") IOError: [Errno 2] No such file or directory: '/Users/username/workspace/eclipse/project/media/../myproject/myproject/myapp/tests/assets/test.jpg' I'm using PIL's width/height methods here because I can't use Django's own get_image_dimensions, as it's not an ImageField. Thanks in advance. Kevin -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/NQnc9nXpZXkJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.