test_group_manager.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from sentry.models.group import Group
  2. from sentry.models.integrations.integration import Integration
  3. from sentry.services.hybrid_cloud.integration.serial import serialize_integration
  4. from sentry.testutils.cases import TestCase
  5. from sentry.testutils.skips import requires_snuba
  6. pytestmark = requires_snuba
  7. class SentryManagerTest(TestCase):
  8. def test_valid_only_message(self):
  9. proj = self.create_project()
  10. event = Group.objects.from_kwargs(proj.id, message="foo")
  11. self.assertEqual(event.group.last_seen, event.datetime)
  12. self.assertEqual(event.message, "foo")
  13. self.assertEqual(event.project_id, proj.id)
  14. def test_get_groups_by_external_issue(self):
  15. external_issue_key = "api-123"
  16. group = self.create_group()
  17. integration_model = Integration.objects.create(
  18. provider="jira",
  19. external_id="some_id",
  20. name="Hello world",
  21. metadata={"base_url": "https://example.com"},
  22. )
  23. integration_model.add_organization(group.organization, self.user)
  24. integration = serialize_integration(integration=integration_model)
  25. self.create_integration_external_issue(
  26. group=group, integration=integration, key=external_issue_key
  27. )
  28. affected_groups_no_orgs = Group.objects.get_groups_by_external_issue(
  29. integration,
  30. [],
  31. external_issue_key,
  32. )
  33. assert set(affected_groups_no_orgs) == set()
  34. affected_groups_wrong_key = Group.objects.get_groups_by_external_issue(
  35. integration,
  36. [group.organization],
  37. "invalid",
  38. )
  39. assert set(affected_groups_wrong_key) == set()
  40. affected_groups = Group.objects.get_groups_by_external_issue(
  41. integration,
  42. [group.organization],
  43. external_issue_key,
  44. )
  45. assert set(affected_groups) == {group}