def test_create_resized_copies(self): """ Ensure the create_resized_copies function produces and stores copies with the correct sizes and data. """ field_value = ResizingImageFieldFile(self.model_instance, self.field, 'test_name') with mock.patch.object(field_value, 'storage') as mock_storage: with make_image_file((300, 300)) as image_file: mock_storage.listdir = mock.Mock(return_value=([], [])) field_value.file = image_file field_value.create_resized_copies() self.assertEqual(mock_storage.save.call_count, len(TEST_SIZES)) actual_calls = dict((v[1] for v in mock_storage.save.mock_calls)) for width, height in TEST_SIZES: expected_name = 'test_name__{}x{}.jpg'.format(width, height) actual_data = actual_calls[expected_name] image_object = Image.open(actual_data) self.assertEqual(image_object.size, (width, height))