test_organization_group_index_stats.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. from sentry.issues.grouptype import ProfileFileIOGroupType
  2. from sentry.testutils import APITestCase, SnubaTestCase
  3. from sentry.testutils.helpers import parse_link_header
  4. from sentry.testutils.helpers.datetime import before_now, iso_format
  5. from sentry.testutils.silo import region_silo_test
  6. from tests.sentry.issues.test_utils import OccurrenceTestMixin
  7. @region_silo_test
  8. class GroupListTest(APITestCase, SnubaTestCase, OccurrenceTestMixin):
  9. endpoint = "sentry-api-0-organization-group-index-stats"
  10. def setUp(self):
  11. super().setUp()
  12. self.min_ago = before_now(minutes=1)
  13. def _parse_links(self, header):
  14. # links come in {url: {...attrs}}, but we need {rel: {...attrs}}
  15. links = {}
  16. for url, attrs in parse_link_header(header).items():
  17. links[attrs["rel"]] = attrs
  18. attrs["href"] = url
  19. return links
  20. def get_response(self, *args, **kwargs):
  21. if not args:
  22. org = self.project.organization.slug
  23. else:
  24. org = args[0]
  25. return super().get_response(org, **kwargs)
  26. def test_simple(self):
  27. self.store_event(
  28. data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-1"]},
  29. project_id=self.project.id,
  30. )
  31. group_a = self.store_event(
  32. data={"timestamp": iso_format(before_now(seconds=1)), "fingerprint": ["group-a"]},
  33. project_id=self.project.id,
  34. ).group
  35. self.store_event(
  36. data={"timestamp": iso_format(before_now(seconds=2)), "fingerprint": ["group-b"]},
  37. project_id=self.project.id,
  38. )
  39. group_c = self.store_event(
  40. data={"timestamp": iso_format(before_now(seconds=3)), "fingerprint": ["group-c"]},
  41. project_id=self.project.id,
  42. ).group
  43. self.login_as(user=self.user)
  44. response = self.get_response(query="is:unresolved", groups=[group_a.id, group_c.id])
  45. response_data = sorted(response.data, key=lambda x: x["firstSeen"], reverse=True)
  46. assert response.status_code == 200
  47. assert len(response_data) == 2
  48. assert int(response_data[0]["id"]) == group_a.id
  49. assert int(response_data[1]["id"]) == group_c.id
  50. assert "title" not in response_data[0]
  51. assert "hasSeen" not in response_data[0]
  52. assert "stats" in response_data[0]
  53. assert "firstSeen" in response_data[0]
  54. assert "lastSeen" in response_data[0]
  55. assert "count" in response_data[0]
  56. assert "userCount" in response_data[0]
  57. assert "lifetime" in response_data[0]
  58. assert "filtered" in response_data[0]
  59. def test_issue_platform_issue(self):
  60. event = self.store_event(
  61. data={"timestamp": iso_format(before_now(seconds=1)), "fingerprint": ["group-a"]},
  62. project_id=self.project.id,
  63. )
  64. event_group = event.for_group(event.group)
  65. event_group.occurrence = self.build_occurrence()
  66. event.group.type = ProfileFileIOGroupType.type_id
  67. self.login_as(user=self.user)
  68. response = self.get_response(
  69. query=f"issue:{event.group.qualified_short_id}", groups=[event.group.id]
  70. )
  71. response_data = sorted(response.data, key=lambda x: x["firstSeen"], reverse=True)
  72. assert response.status_code == 200
  73. assert len(response_data) == 1
  74. assert int(response_data[0]["id"]) == event.group.id
  75. assert "title" not in response_data[0]
  76. assert "hasSeen" not in response_data[0]
  77. assert "stats" in response_data[0]
  78. assert "firstSeen" in response_data[0]
  79. assert "lastSeen" in response_data[0]
  80. assert "count" in response_data[0]
  81. assert "userCount" in response_data[0]
  82. assert "lifetime" in response_data[0]
  83. assert "filtered" in response_data[0]
  84. def test_no_matching_groups(self):
  85. self.login_as(user=self.user)
  86. response = self.get_response(sort_by="date", limit=10, query="is:unresolved", groups=[1337])
  87. assert response.status_code == 400
  88. def test_simple_with_project(self):
  89. self.store_event(
  90. data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-1"]},
  91. project_id=self.project.id,
  92. )
  93. group_a = self.store_event(
  94. data={"timestamp": iso_format(before_now(seconds=1)), "fingerprint": ["group-a"]},
  95. project_id=self.project.id,
  96. ).group
  97. self.store_event(
  98. data={"timestamp": iso_format(before_now(seconds=2)), "fingerprint": ["group-b"]},
  99. project_id=self.project.id,
  100. )
  101. group_c = self.store_event(
  102. data={"timestamp": iso_format(before_now(seconds=3)), "fingerprint": ["group-c"]},
  103. project_id=self.project.id,
  104. ).group
  105. self.login_as(user=self.user)
  106. response = self.get_response(
  107. query=f"project:{self.project.slug}", groups=[group_a.id, group_c.id]
  108. )
  109. assert response.status_code == 200
  110. assert len(response.data) == 2