test_org_stats_v2.py 1.4 KB

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