You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 regels
1.1 KiB

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