tests.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import uuid
  2. from django.shortcuts import reverse
  3. from model_bakery import baker
  4. from rest_framework.test import APITestCase
  5. from glitchtip import test_utils # pylint: disable=unused-import
  6. from ..models import UserReport
  7. class ErrorPageEmbedTestCase(APITestCase):
  8. def setUp(self):
  9. self.url = reverse("error_page")
  10. self.project = baker.make("projects.Project")
  11. self.project_key = baker.make("projects.ProjectKey", project=self.project)
  12. def test_get_not_found(self):
  13. res = self.client.get(self.url)
  14. # Slight deviation from OSS Sentry as it would 404, but better consistency with DRF
  15. self.assertEqual(res.status_code, 400)
  16. res = self.client.get(self.url + "?dsn=lol")
  17. self.assertEqual(res.status_code, 400)
  18. def test_get_embed(self):
  19. params = {"dsn": self.project_key.get_dsn(), "eventId": uuid.uuid4().hex}
  20. res = self.client.get(self.url, params)
  21. self.assertContains(res, self.project_key.public_key.hex)
  22. def test_submit_report(self):
  23. params = f"?dsn={self.project_key.get_dsn()}&eventId={uuid.uuid4().hex}"
  24. data = {"name": "Test Name", "email": "test@example.com", "comments": "hmm"}
  25. res = self.client.post(self.url + params, data)
  26. self.assertEqual(res.status_code, 200)
  27. self.assertTrue(UserReport.objects.filter(project=self.project).exists())
  28. def test_submit_report_with_issue(self):
  29. issue = baker.make("issues.Issue", project=self.project)
  30. event = baker.make("events.Event", issue=issue)
  31. params = f"?dsn={self.project_key.get_dsn()}&eventId={event.event_id.hex}"
  32. data = {"name": "Test Name", "email": "test@example.com", "comments": "hmm"}
  33. res = self.client.post(self.url + params, data)
  34. self.assertEqual(res.status_code, 200)
  35. self.assertTrue(UserReport.objects.filter(issue=issue).exists())