Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

43 rindas
1.2 KiB

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