Last active
January 18, 2017 01:28
-
-
Save victorcarrico/da0ebd94c1c1fcf7ef6f3cd3f1f6fb9c to your computer and use it in GitHub Desktop.
Django REST Framework - Testing image upload
This file contains hidden or 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
import tempfile | |
from PIL import Image | |
class PhotoCreateAPIViewTest(TestCase): | |
def setUp(self): | |
super().setUp() | |
self.tmp_file = tempfile.NamedTemporaryFile(suffix='.jpg') | |
image = Image.new('RGB', (100, 100)) | |
image.save(self.tmp_file.name) | |
self.params = { | |
'photo': self.tmp_file | |
} | |
def test_valid_authenticated_post_returns_201(self): | |
response = self.auth_client.post( | |
reverse(self.view_name), data=self.params, format='multipart') | |
self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment