您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

40 行
1.2 KiB

  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. )