Co-authored-by: Eve832 <eve.meelan@grafana.com>
Co-authored-by: Francisco Montes de Oca <nevermind89x@gmail.com>
Co-authored-by: Ildar Iskhakov <ildar.iskhakov@grafana.com>
Co-authored-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
Co-authored-by: Julia <ferril.darkdiver@gmail.com>
Co-authored-by: maskin25 <kengurek@gmail.com>
Co-authored-by: Matias Bordese <mbordese@gmail.com>
Co-authored-by: Matvey Kukuy <motakuk@gmail.com>
Co-authored-by: Michael Derynck <michael.derynck@grafana.com>
Co-authored-by: Richard Hartmann <richih@richih.org>
Co-authored-by: Robby Milo <robbymilo@fastmail.com>
Co-authored-by: Timur Olzhabayev <timur.olzhabayev@grafana.com>
Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
Co-authored-by: Yulia Shanyrova <yulia.shanyrova@grafana.com>
82 lines
2.7 KiB
Python
82 lines
2.7 KiB
Python
import pytest
|
|
from django.utils.timezone import timedelta
|
|
|
|
from apps.base.models import UserNotificationPolicy
|
|
from apps.base.models.user_notification_policy import (
|
|
NotificationChannelAPIOptions,
|
|
NotificationChannelOptions,
|
|
NotificationChannelPublicAPIOptions,
|
|
validate_channel_choice,
|
|
)
|
|
from apps.base.tests.messaging_backend import TestOnlyBackend
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"notification_type,kwargs, expected_verbal",
|
|
[
|
|
(
|
|
UserNotificationPolicy.Step.WAIT,
|
|
{
|
|
"wait_delay": timedelta(minutes=5),
|
|
},
|
|
"5 min",
|
|
),
|
|
(UserNotificationPolicy.Step.NOTIFY, {"notify_by": UserNotificationPolicy.NotificationChannel.SLACK}, "Slack"),
|
|
(UserNotificationPolicy.Step.WAIT, {}, "0 min"),
|
|
(None, {}, "Not set"),
|
|
],
|
|
)
|
|
@pytest.mark.django_db
|
|
def test_short_verbal(
|
|
make_organization,
|
|
make_user_for_organization,
|
|
make_user_notification_policy,
|
|
notification_type,
|
|
kwargs,
|
|
expected_verbal,
|
|
):
|
|
organization = make_organization()
|
|
user = make_user_for_organization(organization)
|
|
|
|
policy = make_user_notification_policy(user, notification_type, **kwargs)
|
|
assert policy.short_verbal == expected_verbal
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_short_verbals_for_user(
|
|
make_organization,
|
|
make_user_for_organization,
|
|
make_user_notification_policy,
|
|
):
|
|
organization = make_organization()
|
|
user = make_user_for_organization(organization)
|
|
|
|
make_user_notification_policy(
|
|
user, UserNotificationPolicy.Step.NOTIFY, notify_by=UserNotificationPolicy.NotificationChannel.SLACK
|
|
)
|
|
|
|
make_user_notification_policy(user, UserNotificationPolicy.Step.WAIT, wait_delay=timedelta(minutes=5))
|
|
|
|
make_user_notification_policy(
|
|
user,
|
|
UserNotificationPolicy.Step.NOTIFY,
|
|
notify_by=UserNotificationPolicy.NotificationChannel.SMS,
|
|
important=True,
|
|
)
|
|
|
|
expected = (("Slack", "5 min"), ("SMS",))
|
|
assert UserNotificationPolicy.get_short_verbals_for_user(user) == expected
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_extra_messaging_backends_details():
|
|
assert TestOnlyBackend.backend_id in UserNotificationPolicy.NotificationChannel.names
|
|
assert TestOnlyBackend.backend_id not in NotificationChannelOptions.AVAILABLE_FOR_USE
|
|
channel_choice = getattr(UserNotificationPolicy.NotificationChannel, TestOnlyBackend.backend_id)
|
|
assert NotificationChannelAPIOptions.LABELS[channel_choice] == "Test Only Backend"
|
|
assert NotificationChannelAPIOptions.SHORT_LABELS[channel_choice] == TestOnlyBackend.short_label
|
|
assert NotificationChannelPublicAPIOptions.LABELS[channel_choice] == "notify_by_{}".format(
|
|
TestOnlyBackend.backend_id.lower()
|
|
)
|
|
|
|
assert validate_channel_choice(channel_choice) is None
|