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.
 
 
 
 
 
 

44 líneas
1.3 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('docs/src/imgs/logo-dark.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. )
  30. class TestDocs(TestCase):
  31. def test_should_doc_api_available_without_error(self):
  32. response = self.client.get("/api/v2/docs")
  33. self.assertEqual(response.status_code, 200)