test_issue_event_api.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from django.test import TestCase
  2. from django.urls import reverse
  3. from model_bakery import baker
  4. from glitchtip.test_utils.test_case import GlitchTipTestCaseMixin
  5. class IssueEventAPITestCase(GlitchTipTestCaseMixin, TestCase):
  6. def setUp(self):
  7. super().create_logged_in_user()
  8. def test_list(self):
  9. event = baker.make("issue_events.IssueEvent", issue__project=self.project)
  10. baker.make("issue_events.IssueEvent", issue__project=self.project, _quantity=3)
  11. not_my_event = baker.make("issue_events.IssueEvent")
  12. url = reverse("api:list_issue_event", args=[event.issue_id])
  13. with self.assertNumQueries(1):
  14. res = self.client.get(url)
  15. self.assertContains(res, event.pk.hex)
  16. self.assertNotContains(res, not_my_event.pk.hex)
  17. def test_retrieve(self):
  18. event = baker.make("issue_events.IssueEvent", issue__project=self.project)
  19. url = reverse(
  20. "api:get_issue_event",
  21. kwargs={"issue_id": event.issue_id, "event_id": "a" * 32},
  22. )
  23. res = self.client.get(url)
  24. self.assertEqual(res.status_code, 404)
  25. url = reverse(
  26. "api:get_issue_event",
  27. kwargs={"issue_id": event.issue_id, "event_id": event.id},
  28. )
  29. res = self.client.get(url)
  30. self.assertContains(res, event.pk.hex)
  31. url = reverse("api:get_latest_issue_event", kwargs={"issue_id": event.issue_id})
  32. res = self.client.get(url)
  33. self.assertContains(res, event.pk.hex)
  34. def test_authentication(self):
  35. url = reverse("api:list_issue_event", args=[1])
  36. self.client.logout()
  37. res = self.client.get(url)
  38. self.assertEqual(res.status_code, 401)