Skip to content

Instantly share code, notes, and snippets.

@victorcarrico
Last active January 18, 2017 01:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorcarrico/da0ebd94c1c1fcf7ef6f3cd3f1f6fb9c to your computer and use it in GitHub Desktop.
Save victorcarrico/da0ebd94c1c1fcf7ef6f3cd3f1f6fb9c to your computer and use it in GitHub Desktop.
Django REST Framework - Testing image upload
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