test_embed_api.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import uuid
  2. from django.urls import reverse
  3. from model_bakery import baker
  4. from apps.issue_events.models import UserReport
  5. from .utils import EventIngestTestCase
  6. class ErrorPageEmbedTestCase(EventIngestTestCase):
  7. def setUp(self):
  8. self.url = reverse("api:get_embed_error_page")
  9. self.project = baker.make("projects.Project")
  10. self.project_key = baker.make("projects.ProjectKey", project=self.project)
  11. def test_get_not_found(self):
  12. res = self.client.get(self.url)
  13. # Slight deviation from OSS Sentry as it would 404, but better consistency with DRF
  14. self.assertEqual(res.status_code, 401)
  15. params = {"dsn": "lol", "eventId": uuid.uuid4().hex}
  16. res = self.client.get(self.url, params)
  17. self.assertEqual(res.status_code, 401)
  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_get_embed_throttle(self):
  23. params = {"dsn": self.project_key.get_dsn(), "eventId": uuid.uuid4().hex}
  24. self.project.organization.event_throttle_rate = 100
  25. self.project.organization.save()
  26. res = self.client.get(self.url, params)
  27. self.assertEqual(res.status_code, 401)
  28. self.project.organization.event_throttle_rate = 50
  29. self.project.organization.save()
  30. res = self.client.get(self.url, params)
  31. self.assertContains(res, self.project_key.public_key.hex)
  32. def test_submit_report(self):
  33. params = f"?dsn={self.project_key.get_dsn()}&eventId={uuid.uuid4().hex}"
  34. data = {"name": "Test Name", "email": "test@example.com", "comments": "hmm"}
  35. res = self.client.post(self.url + params, data)
  36. self.assertEqual(res.status_code, 200)
  37. self.assertTrue(UserReport.objects.filter(project=self.project).exists())
  38. def test_submit_report_with_issue(self):
  39. issue = baker.make("issue_events.Issue", project=self.project)
  40. event = baker.make("issue_events.IssueEvent", issue=issue)
  41. params = f"?dsn={self.project_key.get_dsn()}&eventId={event.id.hex}"
  42. data = {"name": "Test Name", "email": "test@example.com", "comments": "hmm"}
  43. res = self.client.post(self.url + params, data)
  44. self.assertEqual(res.status_code, 200)
  45. created_report = UserReport.objects.filter(issue=issue).first()
  46. self.assertEqual(created_report.comments, data["comments"])
  47. self.assertEqual(created_report.name, data["name"])