Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

37 righe
1.3 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 .api import UserFactory
  6. from core.models import Image
  7. __all__ = ['CreateImageTest']
  8. class CreateImageTest(TestCase):
  9. def setUp(self):
  10. self.user = UserFactory(password='password')
  11. self.client.login(username=self.user.username, password='password')
  12. def test_get_browser(self):
  13. response = self.client.get(reverse('core:create-image'))
  14. self.assertRedirects(response, reverse('core:recent-pins'))
  15. def test_get_xml_http_request(self):
  16. with self.assertRaises(TemplateDoesNotExist):
  17. self.client.get(reverse('core:create-image'), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
  18. def test_post(self):
  19. with open(settings.SITE_ROOT + 'logo.png', mode='rb') as image:
  20. response = self.client.post(reverse('core:create-image'), {'qqfile': image})
  21. image = Image.objects.latest('pk')
  22. self.assertJSONEqual(response.content, {'success': {'id': image.pk}})
  23. def test_post_error(self):
  24. response = self.client.post(reverse('core:create-image'), {'qqfile': None})
  25. self.assertJSONEqual(response.content, {
  26. 'error': {'image': ['This field is required.']}
  27. })