def test_delete_not_allowed(self): self.MockDeleteClass.side_effect = mocked_thumbor_delete_not_allowed_response filename = '/image/oooooo32chars_random_idooooooooo/foundations/gnu.png' thumbor_file = storages.ThumborStorageFile(filename, mode="wb") self.assertRaises(exceptions.MethodNotAllowedException, thumbor_file.delete) filename = '/image/oooooo32chars_random_idooooooooo/does_not_exists.png' thumbor_file = storages.ThumborStorageFile(filename, mode="wb") self.assertRaises(exceptions.MethodNotAllowedException, thumbor_file.delete)
def test_delete_allowed(self): filename = '/image/oooooo32chars_random_idooooooooo/foundations/gnu.png' thumbor_file = storages.ThumborStorageFile(filename, mode="wb") thumbor_file.delete() self.MockDeleteClass.assert_called_with( f"{settings.THUMBOR_RW_SERVER}{filename}") # TODO test status_code == 204 (how ?) filename = '/image/oooooo32chars_random_idooooooooo/does_not_exists.png' thumbor_file = storages.ThumborStorageFile(filename, mode="wb") self.assertRaises(exceptions.NotFoundException, thumbor_file.delete)
def test_delete_not_allowed_post_django_3_2_11(self): # See https://github.com/django/django/commit/6d343d01c57eb03ca1c6826318b652709e58a76e self.MockDeleteClass.side_effect = mocked_thumbor_delete_not_allowed_response filename = 'image/oooooo32chars_random_idooooooooo/foundations/gnu.png' thumbor_file = storages.ThumborStorageFile(filename, mode="wb") self.assertRaises(exceptions.MethodNotAllowedException, thumbor_file.delete) filename = '/mage/oooooo32chars_random_idooooooooo/does_not_exists.png' thumbor_file = storages.ThumborStorageFile(filename, mode="wb") self.assertRaises(exceptions.MethodNotAllowedException, thumbor_file.delete)
def test_delete_allowed_post_django_3_2_11(self): # See https://github.com/django/django/commit/6d343d01c57eb03ca1c6826318b652709e58a76e filename = 'image/oooooo32chars_random_idooooooooo/foundations/gnu.png' thumbor_file = storages.ThumborStorageFile(filename, mode="wb") thumbor_file.delete() self.MockDeleteClass.assert_called_with( f"{settings.THUMBOR_RW_SERVER}/{filename}") # TODO test status_code == 204 (how ?) filename = '/image/oooooo32chars_random_idooooooooo/does_not_exists.png' thumbor_file = storages.ThumborStorageFile(filename, mode="wb") self.assertRaises(exceptions.NotFoundException, thumbor_file.delete)
def test_delete_allowed(self): from django_thumborstorage import storages from django.conf import settings filename = '/image/oooooo32chars_random_idooooooooo/foundations/gnu.png' thumbor_file = storages.ThumborStorageFile(filename, mode="w") thumbor_file.delete() self.MockDeleteClass.assert_called_with( "%s%s" % (settings.THUMBOR_RW_SERVER, filename)) # TODO test status_code == 204 (how ?) from django_thumborstorage import exceptions filename = '/image/oooooo32chars_random_idooooooooo/does_not_exists.png' thumbor_file = storages.ThumborStorageFile(filename, mode="w") self.assertRaises(exceptions.NotFoundException, thumbor_file.delete)
def test_write_image_too_small(self): filename = 'beasts/bouboune.png' content = ContentFile(open(f'{IMAGE_DIR}/bouboune.png', "rb").read()) thumbor_file = storages.ThumborStorageFile(filename, mode="wb") self.assertRaises(exceptions.ThumborPostException, thumbor_file.write, content=content)
def test_read(self): filename = '/image/5247a82854384f228c6fba432c67e6a8/people/new/TempletonPeck.jpg' thumbor_file = storages.ThumborStorageFile(filename, mode='rb') content = thumbor_file.read() self.MockGetClass.assert_called_with( f'{settings.THUMBOR_RW_SERVER}{filename}') self.assertEqual(len(content), 9730)
def test_get_file_post_django_3_2_11(self): # See https://github.com/django/django/commit/6d343d01c57eb03ca1c6826318b652709e58a76e filename = 'image/5247a82854384f228c6fba432c67e6a8/people/new/TempletonPeck.jpg' thumbor_file = storages.ThumborStorageFile(filename, mode='rb') thumbor_file.file self.MockGetClass.assert_called_with( "%s/%s" % (settings.THUMBOR_RW_SERVER, filename))
def test_get_file(self): from django_thumborstorage import storages from django.conf import settings filename = '/image/5247a82854384f228c6fba432c67e6a8/people/new/TempletonPeck.jpg' thumbor_file = storages.ThumborStorageFile(filename, mode='r') thumbor_file.file self.MockGetClass.assert_called_with( "%s%s" % (settings.THUMBOR_RW_SERVER, filename))
def test_read_post_django_3_2_11(self): # See https://github.com/django/django/commit/6d343d01c57eb03ca1c6826318b652709e58a76e filename = 'image/5247a82854384f228c6fba432c67e6a8/people/new/TempletonPeck.jpg' thumbor_file = storages.ThumborStorageFile(filename, mode='rb') content = thumbor_file.read() self.MockGetClass.assert_called_with( f'{settings.THUMBOR_RW_SERVER}/{filename}') self.assertEqual(len(content), 9730)
def test_write_png(self): filename = 'foundations/gnu.png' content = ContentFile(open(f'{IMAGE_DIR}/gnu.png', "rb").read()) thumbor_file = storages.ThumborStorageFile(filename, mode="wb") thumbor_file.write(content=content) self.MockPostClass.assert_called_with( f"{settings.THUMBOR_RW_SERVER}/image", data=content.file.read(), headers={ "Content-Type": "image/png", "Slug": filename }) self.assertEqual( thumbor_file._location, f'/image/oooooo32chars_random_idooooooooo/{filename}')
def test_write_png(self): from django_thumborstorage import storages from django.conf import settings filename = 'foundations/gnu.png' content = ContentFile(open('%s/gnu.png' % IMAGE_DIR, "rb").read()) thumbor_file = storages.ThumborStorageFile(filename, mode="w") thumbor_file.write(content=content) self.MockPostClass.assert_called_with("%s/image" % settings.THUMBOR_RW_SERVER, data=content.file.read(), headers={ "Content-Type": "image/png", "Slug": filename }) self.assertEqual( thumbor_file._location, '/image/oooooo32chars_random_idooooooooo/%s' % filename)