tests.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from io import BytesIO
  2. from django.core.files.uploadedfile import InMemoryUploadedFile
  3. from django.shortcuts import reverse
  4. from glitchtip.test_utils.test_case import GlitchTipTestCase
  5. from glitchtip.test_utils.test_case import APIPermissionTestCase
  6. class ChunkUploadAPITestCase(GlitchTipTestCase):
  7. def setUp(self):
  8. self.create_user_and_project()
  9. self.url = reverse(
  10. "chunk-upload", kwargs={"organization_slug": self.organization}
  11. )
  12. def test_get(self):
  13. res = self.client.get(self.url)
  14. self.assertEqual(res.status_code, 200)
  15. def test_post(self):
  16. im_io = BytesIO()
  17. file = InMemoryUploadedFile(
  18. im_io, None, "random-name.jpg", "image/jpeg", len(im_io.getvalue()), None
  19. )
  20. data = {"file_gzip": file}
  21. res = self.client.post(self.url, data)
  22. self.assertEqual(res.status_code, 200)
  23. class ChunkUploadAPIPermissionTests(APIPermissionTestCase):
  24. def setUp(self):
  25. self.create_user_org()
  26. self.set_client_credentials(self.auth_token.token)
  27. self.url = reverse(
  28. "chunk-upload", kwargs={"organization_slug": self.organization}
  29. )
  30. def test_get(self):
  31. self.assertGetReqStatusCode(self.url, 403)
  32. self.auth_token.add_permission("project:read")
  33. self.assertGetReqStatusCode(self.url, 200)
  34. def test_post(self):
  35. self.assertGetReqStatusCode(self.url, 403)
  36. self.auth_token.add_permission("project:write")
  37. self.assertGetReqStatusCode(self.url, 200)