test_user_reports.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from django.shortcuts import reverse
  2. from model_bakery import baker
  3. from glitchtip.test_utils.test_case import GlitchTipTestCase
  4. class IssuesUserReportTestCase(GlitchTipTestCase):
  5. def setUp(self):
  6. self.create_user_and_project()
  7. self.event = baker.make("events.Event", issue__project=self.project)
  8. self.user_report = baker.make(
  9. "user_reports.UserReport",
  10. project=self.project,
  11. issue=self.event.issue,
  12. event_id=self.event.pk.hex,
  13. )
  14. def test_events_user_report(self):
  15. url = reverse(
  16. "project-events-detail",
  17. kwargs={
  18. "project_pk": self.organization.slug + "/" + self.project.slug,
  19. "pk": self.event.pk.hex,
  20. },
  21. )
  22. res = self.client.get(url)
  23. self.assertContains(res, self.user_report.email)
  24. self.assertContains(res, self.user_report.name)
  25. self.assertContains(res, self.user_report.comments)
  26. self.assertEqual(res.data["userReport"]["eventId"], self.event.pk.hex)
  27. def test_issues_list_user_report_count(self):
  28. url = reverse("issue-detail", kwargs={"pk": self.event.issue.pk})
  29. with self.assertNumQueries(6):
  30. res = self.client.get(url)
  31. self.assertEqual(res.data["userReportCount"], 1)
  32. def test_issues_user_report_list(self):
  33. event2 = baker.make("events.Event", issue__project=self.project)
  34. user_report2 = baker.make(
  35. "user_reports.UserReport",
  36. project=self.project,
  37. issue=event2.issue,
  38. event_id=event2.pk.hex,
  39. )
  40. url = reverse(
  41. "issue-user-reports-list", kwargs={"issue_pk": self.event.issue.pk}
  42. )
  43. res = self.client.get(url)
  44. self.assertContains(res, self.user_report.email)
  45. self.assertNotContains(res, user_report2.email)