test_org_stats_v2.py 1.3 KB

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