test_org_stats_v2.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from datetime import datetime, timedelta, timezone
  2. from django.test.client import RequestFactory
  3. from django.urls import reverse
  4. from fixtures.apidocs_test_case import APIDocsTestCase
  5. from sentry.constants import DataCategory
  6. from sentry.testutils.cases import OutcomesSnubaTest
  7. from sentry.utils.outcomes import Outcome
  8. class OrganizationStatsDocs(APIDocsTestCase, OutcomesSnubaTest):
  9. def setUp(self):
  10. super().setUp()
  11. self.now = datetime(2021, 3, 14, 12, 27, 28, tzinfo=timezone.utc)
  12. self.login_as(user=self.user)
  13. self.store_outcomes(
  14. {
  15. "org_id": self.organization.id,
  16. "timestamp": self.now - timedelta(hours=1),
  17. "project_id": self.project.id,
  18. "outcome": Outcome.ACCEPTED,
  19. "reason": "none",
  20. "category": DataCategory.ERROR,
  21. "quantity": 1,
  22. },
  23. 5,
  24. )
  25. self.url = reverse(
  26. "sentry-api-0-organization-stats-v2",
  27. kwargs={"organization_id_or_slug": self.organization.slug},
  28. )
  29. def test_get(self):
  30. query = {"interval": "1d", "field": "sum(quantity)", "groupBy": "category"}
  31. response = self.client.get(self.url, query, format="json")
  32. request = RequestFactory().get(self.url)
  33. self.validate_schema(request, response)