No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

views.py 1.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from django.conf import settings
  2. from django.core.urlresolvers import reverse
  3. from django.template import TemplateDoesNotExist
  4. from django.test import TestCase
  5. from core.models import Image
  6. from core.tests import create_user
  7. from users.models import User
  8. __all__ = ['CreateImageTest']
  9. class CreateImageTest(TestCase):
  10. def setUp(self):
  11. self.user = create_user("default")
  12. self.client.login(username=self.user.username, password='password')
  13. def tearDown(self):
  14. User.objects.all().delete()
  15. Image.objects.all().delete()
  16. def test_post(self):
  17. with open('logo.png', mode='rb') as image:
  18. response = self.client.post(reverse('image-list'), {'image': image})
  19. image = Image.objects.latest('pk')
  20. self.assertEqual(response.json()['id'], image.pk)
  21. def test_post_error(self):
  22. response = self.client.post(reverse('image-list'), {'image': None})
  23. self.assertEqual(
  24. response.json(),
  25. {
  26. 'image': [
  27. 'The submitted data was not a file. '
  28. 'Check the encoding type on the form.'
  29. ]
  30. }
  31. )