test_organization_group_index_stats.py 2.6 KB

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