test_org_stats_v2.py 1.4 KB

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