test_user_reports_api.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from django.shortcuts import reverse
  2. from django.test import TestCase
  3. from model_bakery import baker
  4. from glitchtip.test_utils.test_case import GlitchTipTestCaseMixin
  5. class IssuesUserReportTestCase(GlitchTipTestCaseMixin, TestCase):
  6. def setUp(self):
  7. super().create_logged_in_user()
  8. self.event = baker.make("issue_events.IssueEvent", issue__project=self.project)
  9. self.user_report = baker.make(
  10. "issue_events.UserReport",
  11. project=self.project,
  12. issue=self.event.issue,
  13. event_id=self.event.pk.hex,
  14. )
  15. def test_events_user_report(self):
  16. url = reverse(
  17. "api:get_issue_event",
  18. kwargs={"issue_id": self.event.issue_id, "event_id": self.event.pk.hex},
  19. )
  20. res = self.client.get(url)
  21. self.assertContains(res, self.user_report.email)
  22. self.assertContains(res, self.user_report.name)
  23. self.assertContains(res, self.user_report.comments)
  24. self.assertEqual(res.json()["userReport"]["eventID"], self.event.pk.hex)
  25. def test_issues_user_report_list(self):
  26. event2 = baker.make("issue_events.IssueEvent", issue__project=self.project)
  27. user_report2 = baker.make(
  28. "issue_events.UserReport",
  29. project=self.project,
  30. issue=event2.issue,
  31. event_id=event2.pk.hex,
  32. )
  33. url = reverse(
  34. "api:list_user_reports", kwargs={"issue_id": self.event.issue.id}
  35. )
  36. res = self.client.get(url)
  37. self.assertContains(res, self.user_report.email)
  38. self.assertNotContains(res, user_report2.email)