-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(notifications): Get default settings in `where_should_be_particip…
…ating` (#29757)
- Loading branch information
Showing
5 changed files
with
137 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
tests/sentry/notifications/utils/test_get_setting_mapping_from_mapping.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from unittest import TestCase | ||
|
||
from sentry.models import User | ||
from sentry.notifications.helpers import _get_setting_mapping_from_mapping | ||
from sentry.notifications.types import ( | ||
NotificationScopeType, | ||
NotificationSettingOptionValues, | ||
NotificationSettingTypes, | ||
) | ||
from sentry.types.integrations import ExternalProviders | ||
|
||
|
||
class GetSettingMappingFromMappingTest(TestCase): | ||
def setUp(self): | ||
self.user = User(id=1) | ||
|
||
def test_get_setting_mapping_from_mapping_issue_alerts(self): | ||
notification_settings = { | ||
self.user: { | ||
NotificationScopeType.USER: { | ||
ExternalProviders.EMAIL: NotificationSettingOptionValues.ALWAYS | ||
} | ||
} | ||
} | ||
mapping = _get_setting_mapping_from_mapping( | ||
notification_settings, | ||
self.user, | ||
NotificationSettingTypes.ISSUE_ALERTS, | ||
) | ||
assert mapping == { | ||
ExternalProviders.EMAIL: NotificationSettingOptionValues.ALWAYS, | ||
ExternalProviders.SLACK: NotificationSettingOptionValues.NEVER, | ||
} | ||
|
||
def test_get_setting_mapping_from_mapping_deploy(self): | ||
notification_settings = { | ||
self.user: { | ||
NotificationScopeType.USER: { | ||
ExternalProviders.EMAIL: NotificationSettingOptionValues.COMMITTED_ONLY | ||
} | ||
} | ||
} | ||
mapping = _get_setting_mapping_from_mapping( | ||
notification_settings, | ||
self.user, | ||
NotificationSettingTypes.DEPLOY, | ||
) | ||
assert mapping == { | ||
ExternalProviders.EMAIL: NotificationSettingOptionValues.COMMITTED_ONLY, | ||
ExternalProviders.SLACK: NotificationSettingOptionValues.NEVER, | ||
} | ||
|
||
def test_get_setting_mapping_from_mapping_workflow(self): | ||
notification_settings = { | ||
self.user: { | ||
NotificationScopeType.USER: { | ||
ExternalProviders.EMAIL: NotificationSettingOptionValues.SUBSCRIBE_ONLY | ||
} | ||
} | ||
} | ||
mapping = _get_setting_mapping_from_mapping( | ||
notification_settings, | ||
self.user, | ||
NotificationSettingTypes.WORKFLOW, | ||
) | ||
assert mapping == { | ||
ExternalProviders.EMAIL: NotificationSettingOptionValues.SUBSCRIBE_ONLY, | ||
ExternalProviders.SLACK: NotificationSettingOptionValues.NEVER, | ||
} | ||
|
||
def test_get_setting_mapping_from_mapping_empty(self): | ||
mapping = _get_setting_mapping_from_mapping( | ||
{}, self.user, NotificationSettingTypes.ISSUE_ALERTS | ||
) | ||
assert mapping == { | ||
ExternalProviders.EMAIL: NotificationSettingOptionValues.ALWAYS, | ||
ExternalProviders.SLACK: NotificationSettingOptionValues.NEVER, | ||
} | ||
|
||
def test_get_setting_mapping_from_mapping_slack_never(self): | ||
notification_settings = { | ||
self.user: { | ||
NotificationScopeType.USER: { | ||
ExternalProviders.SLACK: NotificationSettingOptionValues.NEVER | ||
} | ||
} | ||
} | ||
|
||
mapping = _get_setting_mapping_from_mapping( | ||
notification_settings, | ||
self.user, | ||
NotificationSettingTypes.ISSUE_ALERTS, | ||
) | ||
assert mapping == { | ||
ExternalProviders.EMAIL: NotificationSettingOptionValues.ALWAYS, | ||
ExternalProviders.SLACK: NotificationSettingOptionValues.NEVER, | ||
} | ||
|
||
def test_get_setting_mapping_from_mapping_slack_always(self): | ||
notification_settings = { | ||
self.user: { | ||
NotificationScopeType.USER: { | ||
ExternalProviders.SLACK: NotificationSettingOptionValues.ALWAYS | ||
} | ||
} | ||
} | ||
|
||
mapping = _get_setting_mapping_from_mapping( | ||
notification_settings, | ||
self.user, | ||
NotificationSettingTypes.ISSUE_ALERTS, | ||
) | ||
assert mapping == { | ||
ExternalProviders.EMAIL: NotificationSettingOptionValues.ALWAYS, | ||
ExternalProviders.SLACK: NotificationSettingOptionValues.ALWAYS, | ||
} |