test_image_block_builder.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import uuid
  2. import pytest
  3. from sentry.integrations.slack.message_builder.image_block_builder import ImageBlockBuilder
  4. from sentry.issues.grouptype import PerformanceP95EndpointRegressionGroupType
  5. from sentry.models.group import Group
  6. from sentry.testutils.cases import AcceptanceTestCase, MetricsEnhancedPerformanceTestCase
  7. from sentry.testutils.helpers.datetime import before_now
  8. from sentry.testutils.helpers.features import with_feature
  9. from tests.sentry.issues.test_utils import OccurrenceTestMixin
  10. pytestmark = pytest.mark.sentry_metrics
  11. class TestSlackImageBlockBuilder(
  12. AcceptanceTestCase, MetricsEnhancedPerformanceTestCase, OccurrenceTestMixin
  13. ):
  14. def setUp(self):
  15. super().setUp()
  16. self.features = {
  17. "organizations:performance-use-metrics": True,
  18. "organizations:slack-endpoint-regression-image": True,
  19. }
  20. @with_feature("organizations:slack-endpoint-regression-image")
  21. def test_image_block(self):
  22. for i in range(10):
  23. event_id = uuid.uuid4().hex
  24. _ = self.process_occurrence(
  25. project_id=self.project.id,
  26. event_id=event_id,
  27. type=PerformanceP95EndpointRegressionGroupType.type_id,
  28. event_data={
  29. "fingerprint": ["group-1"],
  30. "timestamp": before_now(minutes=i + 10).isoformat(),
  31. "transaction": "/books/",
  32. },
  33. evidence_data={
  34. "breakpoint": before_now(minutes=i + 10).timestamp(),
  35. },
  36. )
  37. self.store_transaction_metric(
  38. metric="transaction.duration",
  39. tags={"transaction": "/books/"},
  40. value=1,
  41. timestamp=before_now(minutes=i + 10),
  42. project=self.project.id,
  43. )
  44. group = Group.objects.first()
  45. group.update(type=PerformanceP95EndpointRegressionGroupType.type_id)
  46. with self.feature(self.features):
  47. image_block = ImageBlockBuilder(group=group).build_image_block()
  48. assert image_block and "type" in image_block and image_block["type"] == "image"
  49. assert "_media/" in image_block["image_url"]