tests.py 996 B

12345678910111213141516171819202122232425262728
  1. from datetime import datetime
  2. from django.urls import reverse
  3. from django.utils import timezone
  4. from model_bakery import baker
  5. from glitchtip.test_utils.test_case import GlitchTipTestCase
  6. class StatsV2APITestCase(GlitchTipTestCase):
  7. def setUp(self):
  8. self.create_user_and_project()
  9. self.url = reverse("api:stats_v2", args=[self.organization.slug])
  10. def test_get(self):
  11. baker.make("issue_events.IssueEvent", issue__project=self.project)
  12. start = timezone.now() - timezone.timedelta(hours=2)
  13. end = timezone.now()
  14. res = self.client.get(
  15. self.url,
  16. {"category": "error", "start": start, "end": end, "field": "sum(quantity)"},
  17. )
  18. self.assertEqual(res.status_code, 200)
  19. response = res.json()
  20. self.assertIsInstance(response["intervals"], list)
  21. self.assertEqual(len(response["intervals"]), 4)
  22. self.assertIsInstance(datetime.fromisoformat(response["intervals"][0]), datetime)