|
@@ -4,12 +4,14 @@ from sentry.integrations.slack.webhooks.action import (
|
|
|
)
|
|
|
from sentry.models.identity import Identity
|
|
|
from sentry.models.notificationsettingprovider import NotificationSettingProvider
|
|
|
-from sentry.models.user import User
|
|
|
+from sentry.silo.base import SiloMode
|
|
|
+from sentry.testutils.silo import assume_test_silo_mode, region_silo_test
|
|
|
from sentry.utils import json
|
|
|
|
|
|
from . import BaseEventTest
|
|
|
|
|
|
|
|
|
+@region_silo_test
|
|
|
class EnableNotificationsActionTest(BaseEventTest):
|
|
|
def setUp(self):
|
|
|
super().setUp()
|
|
@@ -17,7 +19,12 @@ class EnableNotificationsActionTest(BaseEventTest):
|
|
|
self.team_id = "TXXXXXXX1"
|
|
|
|
|
|
def test_enable_all_slack_no_identity(self):
|
|
|
- Identity.objects.delete_identity(user=self.user, idp=self.idp, external_id=self.external_id)
|
|
|
+ with assume_test_silo_mode(SiloMode.CONTROL):
|
|
|
+ Identity.objects.delete_identity(
|
|
|
+ user=self.user,
|
|
|
+ idp=self.idp,
|
|
|
+ external_id=self.external_id,
|
|
|
+ )
|
|
|
response = self.post_webhook(
|
|
|
action_data=[{"name": "enable_notifications", "value": "all_slack"}]
|
|
|
)
|
|
@@ -26,7 +33,7 @@ class EnableNotificationsActionTest(BaseEventTest):
|
|
|
assert response.data["text"] == NO_IDENTITY_MESSAGE
|
|
|
|
|
|
def test_enable_all_slack_already_enabled(self):
|
|
|
- NotificationSettingProvider.objects.create(
|
|
|
+ provider = self.create_notification_settings_provider(
|
|
|
user_id=self.user.id,
|
|
|
scope_type="user",
|
|
|
scope_identifier=self.user.id,
|
|
@@ -37,44 +44,37 @@ class EnableNotificationsActionTest(BaseEventTest):
|
|
|
response = self.post_webhook(
|
|
|
action_data=[{"name": "enable_notifications", "value": "all_slack"}]
|
|
|
)
|
|
|
- self.user = User.objects.get(id=self.user.id) # Reload to fetch actor
|
|
|
assert response.status_code == 200, response.content
|
|
|
assert response.data["text"] == ENABLE_SLACK_SUCCESS_MESSAGE
|
|
|
|
|
|
- assert (
|
|
|
- NotificationSettingProvider.objects.get(
|
|
|
- user_id=self.user.id,
|
|
|
- scope_type="user",
|
|
|
- scope_identifier=self.user.id,
|
|
|
- type="alerts",
|
|
|
- provider="slack",
|
|
|
- ).value
|
|
|
- == "always"
|
|
|
- )
|
|
|
+ self.user.refresh_from_db() # Reload to fetch actor
|
|
|
+ provider.refresh_from_db()
|
|
|
+ assert provider.value == "always"
|
|
|
|
|
|
def test_enable_all_slack(self):
|
|
|
- assert not NotificationSettingProvider.objects.all().exists()
|
|
|
+ with assume_test_silo_mode(SiloMode.CONTROL):
|
|
|
+ assert not NotificationSettingProvider.objects.all().exists()
|
|
|
|
|
|
response = self.post_webhook(
|
|
|
action_data=[{"name": "enable_notifications", "value": "all_slack"}]
|
|
|
)
|
|
|
- self.user = User.objects.get(id=self.user.id) # Reload to fetch actor
|
|
|
+ self.user.refresh_from_db() # Reload to fetch actor
|
|
|
assert response.status_code == 200, response.content
|
|
|
assert response.data["text"] == ENABLE_SLACK_SUCCESS_MESSAGE
|
|
|
|
|
|
- assert (
|
|
|
- NotificationSettingProvider.objects.get(
|
|
|
+ with assume_test_silo_mode(SiloMode.CONTROL):
|
|
|
+ provider = NotificationSettingProvider.objects.get(
|
|
|
user_id=self.user.id,
|
|
|
scope_type="user",
|
|
|
scope_identifier=self.user.id,
|
|
|
type="alerts",
|
|
|
provider="slack",
|
|
|
- ).value
|
|
|
- == "always"
|
|
|
- )
|
|
|
+ )
|
|
|
+ assert provider.value == "always"
|
|
|
|
|
|
def test_enable_all_slack_block_kit(self):
|
|
|
- assert not NotificationSettingProvider.objects.all().exists()
|
|
|
+ with assume_test_silo_mode(SiloMode.CONTROL):
|
|
|
+ assert not NotificationSettingProvider.objects.all().exists()
|
|
|
original_message = {
|
|
|
"blocks": [
|
|
|
{
|
|
@@ -106,17 +106,16 @@ class EnableNotificationsActionTest(BaseEventTest):
|
|
|
original_message=original_message,
|
|
|
data={"callback_id": json.dumps({"enable_notifications": True})},
|
|
|
)
|
|
|
- self.user = User.objects.get(id=self.user.id) # Reload to fetch actor
|
|
|
+ self.user.refresh_from_db() # Reload to fetch actor
|
|
|
assert response.status_code == 200, response.content
|
|
|
assert response.data["text"] == ENABLE_SLACK_SUCCESS_MESSAGE
|
|
|
|
|
|
- assert (
|
|
|
- NotificationSettingProvider.objects.get(
|
|
|
+ with assume_test_silo_mode(SiloMode.CONTROL):
|
|
|
+ provider = NotificationSettingProvider.objects.get(
|
|
|
user_id=self.user.id,
|
|
|
scope_type="user",
|
|
|
scope_identifier=self.user.id,
|
|
|
type="alerts",
|
|
|
provider="slack",
|
|
|
- ).value
|
|
|
- == "always"
|
|
|
- )
|
|
|
+ )
|
|
|
+ assert provider.value == "always"
|