test_organization_group_index_stats.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from sentry.testutils import APITestCase, SnubaTestCase
  2. from sentry.testutils.helpers import parse_link_header
  3. from sentry.testutils.helpers.datetime import before_now, iso_format
  4. from sentry.testutils.silo import region_silo_test
  5. @region_silo_test
  6. class GroupListTest(APITestCase, SnubaTestCase):
  7. endpoint = "sentry-api-0-organization-group-index-stats"
  8. def setUp(self):
  9. super().setUp()
  10. self.min_ago = before_now(minutes=1)
  11. def _parse_links(self, header):
  12. # links come in {url: {...attrs}}, but we need {rel: {...attrs}}
  13. links = {}
  14. for url, attrs in parse_link_header(header).items():
  15. links[attrs["rel"]] = attrs
  16. attrs["href"] = url
  17. return links
  18. def get_response(self, *args, **kwargs):
  19. if not args:
  20. org = self.project.organization.slug
  21. else:
  22. org = args[0]
  23. return super().get_response(org, **kwargs)
  24. def test_simple(self):
  25. self.store_event(
  26. data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-1"]},
  27. project_id=self.project.id,
  28. )
  29. group_a = self.store_event(
  30. data={"timestamp": iso_format(before_now(seconds=1)), "fingerprint": ["group-a"]},
  31. project_id=self.project.id,
  32. ).group
  33. self.store_event(
  34. data={"timestamp": iso_format(before_now(seconds=2)), "fingerprint": ["group-b"]},
  35. project_id=self.project.id,
  36. )
  37. group_c = self.store_event(
  38. data={"timestamp": iso_format(before_now(seconds=3)), "fingerprint": ["group-c"]},
  39. project_id=self.project.id,
  40. ).group
  41. self.login_as(user=self.user)
  42. response = self.get_response(query="is:unresolved", groups=[group_a.id, group_c.id])
  43. response_data = sorted(response.data, key=lambda x: x["firstSeen"], reverse=True)
  44. assert response.status_code == 200
  45. assert len(response_data) == 2
  46. assert int(response_data[0]["id"]) == group_a.id
  47. assert int(response_data[1]["id"]) == group_c.id
  48. assert "title" not in response_data[0]
  49. assert "hasSeen" not in response_data[0]
  50. assert "stats" in response_data[0]
  51. assert "firstSeen" in response_data[0]
  52. assert "lastSeen" in response_data[0]
  53. assert "count" in response_data[0]
  54. assert "userCount" in response_data[0]
  55. assert "lifetime" in response_data[0]
  56. assert "filtered" in response_data[0]
  57. def test_no_matching_groups(self):
  58. self.login_as(user=self.user)
  59. response = self.get_response(sort_by="date", limit=10, query="is:unresolved", groups=[1337])
  60. assert response.status_code == 400