Skip to content

Instantly share code, notes, and snippets.

@leopard627
Last active May 18, 2017 06:54
Show Gist options
  • Save leopard627/abc8bd95511f0801ae653ae9a3a0b3bb to your computer and use it in GitHub Desktop.
Save leopard627/abc8bd95511f0801ae653ae9a3a0b3bb to your computer and use it in GitHub Desktop.
image_mocking.py
def using_mock():
import mock
from django.core.files import File
file_mock = mock.MagicMock(spec=File, name='FileMock')
def using_tempfile():
import tempfile
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
def using_django_upload_file()
from django.core.files.uploadedfile import SimpleUploadedFile
newPhoto.image = SimpleUploadedFile(name='test_image.jpg', content=open(image_path, 'rb').read(), content_type='image/jpeg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment