|
@@ -3,10 +3,8 @@ from sentry.integrations.slack.webhooks.action import (
|
|
NO_IDENTITY_MESSAGE,
|
|
NO_IDENTITY_MESSAGE,
|
|
)
|
|
)
|
|
from sentry.models.identity import Identity
|
|
from sentry.models.identity import Identity
|
|
-from sentry.models.notificationsetting import NotificationSetting
|
|
|
|
|
|
+from sentry.models.notificationsettingprovider import NotificationSettingProvider
|
|
from sentry.models.user import User
|
|
from sentry.models.user import User
|
|
-from sentry.notifications.types import NotificationSettingOptionValues, NotificationSettingTypes
|
|
|
|
-from sentry.types.integrations import ExternalProviders
|
|
|
|
|
|
|
|
from . import BaseEventTest
|
|
from . import BaseEventTest
|
|
|
|
|
|
@@ -27,13 +25,14 @@ class EnableNotificationsActionTest(BaseEventTest):
|
|
assert response.data["text"] == NO_IDENTITY_MESSAGE
|
|
assert response.data["text"] == NO_IDENTITY_MESSAGE
|
|
|
|
|
|
def test_enable_all_slack_already_enabled(self):
|
|
def test_enable_all_slack_already_enabled(self):
|
|
- NotificationSetting.objects.update_settings(
|
|
|
|
- ExternalProviders.EMAIL,
|
|
|
|
- NotificationSettingTypes.ISSUE_ALERTS,
|
|
|
|
- NotificationSettingOptionValues.NEVER,
|
|
|
|
|
|
+ NotificationSettingProvider.objects.create(
|
|
user_id=self.user.id,
|
|
user_id=self.user.id,
|
|
|
|
+ scope_type="user",
|
|
|
|
+ scope_identifier=self.user.id,
|
|
|
|
+ type="alerts",
|
|
|
|
+ provider="slack",
|
|
|
|
+ value="never",
|
|
)
|
|
)
|
|
-
|
|
|
|
response = self.post_webhook(
|
|
response = self.post_webhook(
|
|
action_data=[{"name": "enable_notifications", "value": "all_slack"}]
|
|
action_data=[{"name": "enable_notifications", "value": "all_slack"}]
|
|
)
|
|
)
|
|
@@ -41,14 +40,19 @@ class EnableNotificationsActionTest(BaseEventTest):
|
|
assert response.status_code == 200, response.content
|
|
assert response.status_code == 200, response.content
|
|
assert response.data["text"] == ENABLE_SLACK_SUCCESS_MESSAGE
|
|
assert response.data["text"] == ENABLE_SLACK_SUCCESS_MESSAGE
|
|
|
|
|
|
- assert NotificationSetting.objects.has_any_provider_settings(
|
|
|
|
- self.user, ExternalProviders.SLACK
|
|
|
|
|
|
+ assert (
|
|
|
|
+ NotificationSettingProvider.objects.get(
|
|
|
|
+ user_id=self.user.id,
|
|
|
|
+ scope_type="user",
|
|
|
|
+ scope_identifier=self.user.id,
|
|
|
|
+ type="alerts",
|
|
|
|
+ provider="slack",
|
|
|
|
+ ).value
|
|
|
|
+ == "always"
|
|
)
|
|
)
|
|
|
|
|
|
def test_enable_all_slack(self):
|
|
def test_enable_all_slack(self):
|
|
- assert not NotificationSetting.objects.has_any_provider_settings(
|
|
|
|
- self.user, ExternalProviders.SLACK
|
|
|
|
- )
|
|
|
|
|
|
+ assert not NotificationSettingProvider.objects.all().exists()
|
|
|
|
|
|
response = self.post_webhook(
|
|
response = self.post_webhook(
|
|
action_data=[{"name": "enable_notifications", "value": "all_slack"}]
|
|
action_data=[{"name": "enable_notifications", "value": "all_slack"}]
|
|
@@ -57,6 +61,13 @@ class EnableNotificationsActionTest(BaseEventTest):
|
|
assert response.status_code == 200, response.content
|
|
assert response.status_code == 200, response.content
|
|
assert response.data["text"] == ENABLE_SLACK_SUCCESS_MESSAGE
|
|
assert response.data["text"] == ENABLE_SLACK_SUCCESS_MESSAGE
|
|
|
|
|
|
- assert NotificationSetting.objects.has_any_provider_settings(
|
|
|
|
- self.user, ExternalProviders.SLACK
|
|
|
|
|
|
+ assert (
|
|
|
|
+ NotificationSettingProvider.objects.get(
|
|
|
|
+ user_id=self.user.id,
|
|
|
|
+ scope_type="user",
|
|
|
|
+ scope_identifier=self.user.id,
|
|
|
|
+ type="alerts",
|
|
|
|
+ provider="slack",
|
|
|
|
+ ).value
|
|
|
|
+ == "always"
|
|
)
|
|
)
|