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>
69 lines
2.6 KiB
Python
69 lines
2.6 KiB
Python
from unittest.mock import PropertyMock, patch
|
|
|
|
import pytest
|
|
|
|
from apps.schedules.models.on_call_schedule import OnCallScheduleQuerySet
|
|
from apps.slack.models import SlackUserGroup
|
|
from apps.slack.slack_client import SlackClientWithErrorHandling
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_update_members(make_organization_with_slack_team_identity, make_slack_user_group):
|
|
organization, slack_team_identity = make_organization_with_slack_team_identity()
|
|
user_group = make_slack_user_group(slack_team_identity)
|
|
|
|
slack_ids = ["slack_id_1", "slack_id_2"]
|
|
|
|
with patch.object(SlackClientWithErrorHandling, "api_call") as mock:
|
|
user_group.update_members(slack_ids)
|
|
mock.assert_called()
|
|
|
|
assert user_group.members == slack_ids
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_oncall_slack_user_identities(
|
|
make_organization_with_slack_team_identity,
|
|
make_slack_user_group,
|
|
make_user_with_slack_user_identity,
|
|
make_user_for_organization,
|
|
):
|
|
organization, slack_team_identity = make_organization_with_slack_team_identity()
|
|
user_group = make_slack_user_group(slack_team_identity)
|
|
|
|
user_1, slack_user_identity_1 = make_user_with_slack_user_identity(
|
|
slack_team_identity, organization, slack_id="user_1"
|
|
)
|
|
user_2, slack_user_identity_2 = make_user_with_slack_user_identity(
|
|
slack_team_identity, organization, slack_id="user_2"
|
|
)
|
|
user_3 = make_user_for_organization(organization)
|
|
|
|
with patch.object(OnCallScheduleQuerySet, "get_oncall_users", return_value=[user_1, user_2, user_3]):
|
|
assert user_group.oncall_slack_user_identities == [slack_user_identity_1, slack_user_identity_2]
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_update_oncall_members(
|
|
make_organization_with_slack_team_identity,
|
|
make_slack_user_group,
|
|
make_user_with_slack_user_identity,
|
|
):
|
|
organization, slack_team_identity = make_organization_with_slack_team_identity()
|
|
user_group = make_slack_user_group(slack_team_identity)
|
|
|
|
user_1, slack_user_identity_1 = make_user_with_slack_user_identity(
|
|
slack_team_identity, organization, slack_id="slack_id_1"
|
|
)
|
|
user_2, slack_user_identity_2 = make_user_with_slack_user_identity(
|
|
slack_team_identity, organization, slack_id="slack_id_2"
|
|
)
|
|
|
|
with patch.object(
|
|
SlackUserGroup, "oncall_slack_user_identities", new_callable=PropertyMock
|
|
) as oncall_slack_user_identities_mock:
|
|
oncall_slack_user_identities_mock.return_value = [slack_user_identity_1, slack_user_identity_2]
|
|
|
|
with patch.object(SlackUserGroup, "update_members") as update_members_mock:
|
|
user_group.update_oncall_members()
|
|
update_members_mock.assert_called()
|