Last active
May 18, 2017 06:54
-
-
Save leopard627/abc8bd95511f0801ae653ae9a3a0b3bb to your computer and use it in GitHub Desktop.
image_mocking.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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