Example #1
0
 def test_empty(self):
     """
     Thumbnails are not generated if there isn't anything to generate...
     """
     profile = models.Profile(avatar=None)
     files = self.fake_save(profile)
     self.assertEqual(len(files), 1)
Example #2
0
 def test_no_change(self):
     """
     Thumbnails are only generated when the file is modified.
     """
     profile = models.Profile(avatar='avatars/test.jpg')
     files = self.fake_save(profile)
     self.assertEqual(len(files), 1)
Example #3
0
 def test_standard_filefield(self):
     profile = models.Profile(avatar='avatars/test.jpg')
     # Attach a File object to the FileField descriptor, emulating an
     # upload.
     profile.logo = self.storage.open(
         self.create_image(self.storage, 'avatars/second.jpg'))
     list_files = self.fake_save(profile)
     # 2 source, 2 thumbs.
     self.assertEqual(len(list_files), 4)
Example #4
0
 def test_changed(self):
     """
     When a file is modified, thumbnails are built for all matching and
     project-wide aliases.
     """
     profile = models.Profile(avatar='avatars/test.jpg')
     profile.avatar._committed = False
     files = self.fake_save(profile)
     # 1 source, 4 specific thumbs, 1 project-wide thumb.
     self.assertEqual(len(files), 6)
Example #5
0
 def test_changed(self):
     """
     When a file is modified, thumbnails are built for all matching
     non-global aliases.
     """
     profile = models.Profile(avatar='avatars/test.jpg')
     profile.avatar._committed = False
     files = self.fake_save(profile)
     # 1 source, 4 thumbs.
     self.assertEqual(len(files), 5)
Example #6
0
    def test_clearable(self):
        """
        A ClearablFileInput will set field value to False before pre_save
        """
        profile = models.Profile(avatar='avatars/test.jpg')
        cls = profile.__class__

        profile.avatar = False
        pre_save.send(sender=cls, instance=profile)

        # Saving will then properly clear
        profile.avatar = ''
        post_save.send(sender=cls, instance=profile)

        # FileField is cleared, but not explicitly deleted, file remains
        files = self.storage.listdir('avatars')[1]
        self.assertEqual(len(files), 1)
Example #7
0
 def test_deleted(self):
     profile = models.Profile(avatar='avatars/test.jpg')
     profile.avatar.delete(save=False)
     files = self.fake_save(profile)
     self.assertEqual(len(files), 0)
Example #8
0
 def test_thumbnailer_fieldfile(self):
     profile = models.Profile(avatar='avatars/test.jpg')
     thumbnailer = files.get_thumbnailer(profile.avatar)
     thumb = thumbnailer['small']
     self.assertEqual((thumb.width, thumb.height), (20, 20))