Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ module = [
"tests.sentry.incidents.serializers.*",
"tests.sentry.insights.*",
"tests.sentry.integrations.api.serializers.*",
"tests.sentry.integrations.discord.message_builder.*",
"tests.sentry.integrations.discord.*",
"tests.sentry.integrations.jira.models.*",
"tests.sentry.integrations.jira.utils.*",
"tests.sentry.integrations.middleware.*",
Expand Down
20 changes: 10 additions & 10 deletions tests/sentry/integrations/discord/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def setUp(self) -> None:
@mock.patch("sentry.integrations.discord.client.DiscordClient.set_application_command")
def assert_setup_flow(
self,
mock_set_application_command,
guild_id="1234567890",
server_name="Cool server",
auth_code="auth_code",
command_response_empty=True,
):
mock_set_application_command: mock.MagicMock,
guild_id: str = "1234567890",
server_name: str = "Cool server",
auth_code: str = "auth_code",
command_response_empty: bool = True,
) -> None:
responses.reset()

resp = self.client.get(self.init_path)
Expand Down Expand Up @@ -128,10 +128,10 @@ def assert_setup_flow(

def assert_setup_flow_from_discord(
self,
guild_id="1234567890",
server_name="Cool server",
auth_code="auth_code",
):
guild_id: str = "1234567890",
server_name: str = "Cool server",
auth_code: str = "auth_code",
) -> None:
responses.reset()

resp = self.client.get(self.configure_path)
Expand Down
18 changes: 11 additions & 7 deletions tests/sentry/integrations/discord/test_issue_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def setUp(self) -> None:
)

@mock.patch("sentry.integrations.utils.metrics.EventLifecycle.record_event")
def assert_lifecycle_metrics(self, mock_record_event):
def assert_lifecycle_metrics(self, mock_record_event: mock.MagicMock) -> None:
notification_uuid = str(uuid4())
self.rule.after(self.event, notification_uuid=notification_uuid)

Expand All @@ -82,7 +82,9 @@ def assert_lifecycle_metrics(self, mock_record_event):
"sentry.integrations.discord.client.DiscordClient.send_message", side_effect=Exception
)
@mock.patch("sentry.integrations.utils.metrics.EventLifecycle.record_event")
def assert_lifecycle_metrics_failure(self, mock_record_event, mock_send_message):
def assert_lifecycle_metrics_failure(
self, mock_record_event: mock.MagicMock, mock_send_message: mock.MagicMock
) -> None:
self.rule.after(self.event)
assert_slo_metric(mock_record_event, EventLifecycleOutcome.FAILURE)

Expand All @@ -91,7 +93,9 @@ def assert_lifecycle_metrics_failure(self, mock_record_event, mock_send_message)
side_effect=ApiRateLimitedError(text="Rate limited"),
)
@mock.patch("sentry.integrations.utils.metrics.EventLifecycle.record_event")
def assert_lifecycle_metrics_halt_for_rate_limit(self, mock_record_event, mock_send_message):
def assert_lifecycle_metrics_halt_for_rate_limit(
self, mock_record_event: mock.MagicMock, mock_send_message: mock.MagicMock
) -> None:
self.rule.after(self.event)
assert_slo_metric(mock_record_event, EventLifecycleOutcome.HALTED)

Expand All @@ -101,8 +105,8 @@ def assert_lifecycle_metrics_halt_for_rate_limit(self, mock_record_event, mock_s
)
@mock.patch("sentry.integrations.utils.metrics.EventLifecycle.record_event")
def assert_lifecycle_metrics_halt_for_missing_access(
self, mock_record_event, mock_send_message
):
self, mock_record_event: mock.MagicMock, mock_send_message: mock.MagicMock
) -> None:
self.rule.after(self.event)
assert_slo_metric(mock_record_event, EventLifecycleOutcome.HALTED)

Expand All @@ -112,8 +116,8 @@ def assert_lifecycle_metrics_halt_for_missing_access(
)
@mock.patch("sentry.integrations.utils.metrics.EventLifecycle.record_event")
def assert_lifecycle_metrics_failure_for_other_api_error(
self, mock_record_event, mock_send_message
):
self, mock_record_event: mock.MagicMock, mock_send_message: mock.MagicMock
) -> None:
self.rule.after(self.event)
assert_slo_metric(mock_record_event, EventLifecycleOutcome.FAILURE)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self) -> None:
super().setUp()
self.alert_rule = self.create_alert_rule()

def get_url(self, link, identifier, detection_type, uuid: str | None):
def get_url(self, link: str, identifier: str, detection_type: str, uuid: str | None) -> str:
if uuid is None:
return f"{link}?alert={identifier}&referrer=metric_alert_discord&detection_type={detection_type}"
return f"{link}?alert={identifier}&referrer=metric_alert_discord&detection_type={detection_type}&notification_uuid={uuid}"
Expand Down
3 changes: 2 additions & 1 deletion tests/sentry/integrations/discord/test_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from typing import Any
from unittest import mock

import orjson
Expand All @@ -12,7 +13,7 @@

@control_silo_test
class DiscordRequestTest(TestCase):
def mock_request(self, request_data: dict | None = None) -> DiscordRequest:
def mock_request(self, request_data: dict[str, Any] | None = None) -> DiscordRequest:
self.request = mock.Mock()
self.request.data = (
{
Expand Down
8 changes: 4 additions & 4 deletions tests/sentry/integrations/discord/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create_discord_integration(
user: RpcUser | User,
guild_id: str = GUILD_ID,
**kwargs: Any,
):
) -> Integration:
integration = Factories.create_integration(
provider="discord",
name="Cool server",
Expand All @@ -45,7 +45,7 @@ def create_discord_integration(

return integration

def uninstall(self):
def uninstall(self) -> None:
org_integration = OrganizationIntegration.objects.get(
integration=self.integration, organization_id=self.organization.id
)
Expand All @@ -66,14 +66,14 @@ def uninstall(self):
object_id=org_integration.id,
).exists()

def mock_discord_guild_leave(self, status: int = 204):
def mock_discord_guild_leave(self, status: int = 204) -> None:
responses.add(
responses.DELETE,
url=f"{DiscordClient.base_url}{USERS_GUILD_URL.format(guild_id=GUILD_ID)}",
status=status,
)

def assert_leave_guild_api_call_count(self, count: int):
def assert_leave_guild_api_call_count(self, count: int) -> None:
assert responses.assert_call_count(count=count, url=LEAVE_GUILD_URL)

@responses.activate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from unittest import mock
from unittest.mock import MagicMock, patch

from rest_framework.response import Response

from sentry.integrations.discord.message_builder.base.component import (
DiscordComponentCustomIds as CustomIds,
)
Expand Down Expand Up @@ -56,7 +58,7 @@ def setUp(self) -> None:
user=self.user, identity_provider=self.provider, external_id=self.discord_user_id
)

def send_interaction(self, data: Any | None = None, member: Any | None = None):
def send_interaction(self, data: Any | None = None, member: Any | None = None) -> Response:
if data is None:
data = {"custom_id": f"unknown:{self.group.id}"}
if member is None:
Expand Down
Loading