Browse Source

ref: fix mypy in tests.sentry_plugins (#53549)

<!-- Describe your PR here. -->
anthony sottile 1 year ago
parent
commit
3cfa5c961f

+ 0 - 12
pyproject.toml

@@ -1247,18 +1247,6 @@ module = [
     "tests.sentry.web.frontend.test_vercel_extension_configuration",
     "tests.sentry.web.frontend.test_vercel_extension_configuration",
     "tests.sentry.web.frontend.test_vsts_extension_configuration",
     "tests.sentry.web.frontend.test_vsts_extension_configuration",
     "tests.sentry.web.test_client_config",
     "tests.sentry.web.test_client_config",
-    "tests.sentry_plugins.asana.test_plugin",
-    "tests.sentry_plugins.bitbucket.test_plugin",
-    "tests.sentry_plugins.bitbucket.test_repository_provider",
-    "tests.sentry_plugins.github.test_plugin",
-    "tests.sentry_plugins.github.test_provider",
-    "tests.sentry_plugins.jira.test_plugin",
-    "tests.sentry_plugins.pagerduty.test_plugin",
-    "tests.sentry_plugins.pushover.test_plugin",
-    "tests.sentry_plugins.test_client",
-    "tests.sentry_plugins.trello.test_plugin",
-    "tests.sentry_plugins.twilio.test_plugin",
-    "tests.sentry_plugins.victorops.test_plugin",
     "tests.snuba.rules.conditions.test_event_frequency",
     "tests.snuba.rules.conditions.test_event_frequency",
     "tests.snuba.sessions.test_sessions",
     "tests.snuba.sessions.test_sessions",
     "tests.snuba.tagstore.test_tagstore_backend",
     "tests.snuba.tagstore.test_tagstore_backend",

+ 5 - 0
src/sentry/testutils/cases.py

@@ -246,6 +246,8 @@ class BaseTestCase(Fixtures):
         path="/",
         path="/",
         secure_scheme=False,
         secure_scheme=False,
         subdomain=None,
         subdomain=None,
+        *,
+        GET: dict[str, str] | None = None,
     ) -> HttpRequest:
     ) -> HttpRequest:
         request = HttpRequest()
         request = HttpRequest()
         if subdomain:
         if subdomain:
@@ -256,6 +258,9 @@ class BaseTestCase(Fixtures):
         request.META["REMOTE_ADDR"] = "127.0.0.1"
         request.META["REMOTE_ADDR"] = "127.0.0.1"
         request.META["SERVER_NAME"] = "testserver"
         request.META["SERVER_NAME"] = "testserver"
         request.META["SERVER_PORT"] = 80
         request.META["SERVER_PORT"] = 80
+        if GET is not None:
+            for k, v in GET.items():
+                request.GET[k] = v
         if secure_scheme:
         if secure_scheme:
             secure_header = settings.SECURE_PROXY_SSL_HEADER
             secure_header = settings.SECURE_PROXY_SSL_HEADER
             request.META[secure_header[0]] = secure_header[1]
             request.META[secure_header[0]] = secure_header[1]

+ 4 - 1
src/social_auth/models.py

@@ -1,6 +1,9 @@
+from __future__ import annotations
+
 import re
 import re
 import time
 import time
 from datetime import datetime, timedelta
 from datetime import datetime, timedelta
+from typing import Any
 
 
 from django.apps import apps
 from django.apps import apps
 from django.conf import settings
 from django.conf import settings
@@ -29,7 +32,7 @@ class UserSocialAuth(models.Model):
     user = models.ForeignKey(AUTH_USER_MODEL, related_name="social_auth", on_delete=models.CASCADE)
     user = models.ForeignKey(AUTH_USER_MODEL, related_name="social_auth", on_delete=models.CASCADE)
     provider = models.CharField(max_length=32)
     provider = models.CharField(max_length=32)
     uid = models.CharField(max_length=UID_LENGTH)
     uid = models.CharField(max_length=UID_LENGTH)
-    extra_data = JSONField(default="{}")
+    extra_data: models.Field[dict[str, Any], dict[str, Any]] = JSONField(default="{}")
 
 
     class Meta:
     class Meta:
         """Meta data"""
         """Meta data"""

+ 1 - 1
tests/sentry_plugins/asana/test_plugin.py

@@ -5,7 +5,7 @@ import responses
 from django.contrib.auth.models import AnonymousUser
 from django.contrib.auth.models import AnonymousUser
 from django.test import RequestFactory
 from django.test import RequestFactory
 
 
-from sentry.plugins.bases.issue2 import PluginError
+from sentry.exceptions import PluginError
 from sentry.testutils import PluginTestCase
 from sentry.testutils import PluginTestCase
 from sentry.utils import json
 from sentry.utils import json
 from sentry_plugins.asana.plugin import AsanaPlugin
 from sentry_plugins.asana.plugin import AsanaPlugin

+ 1 - 1
tests/sentry_plugins/bitbucket/test_plugin.py

@@ -5,7 +5,7 @@ import responses
 from django.contrib.auth.models import AnonymousUser
 from django.contrib.auth.models import AnonymousUser
 from django.test import RequestFactory
 from django.test import RequestFactory
 
 
-from sentry.plugins.bases.issue2 import PluginError
+from sentry.exceptions import PluginError
 from sentry.testutils import PluginTestCase
 from sentry.testutils import PluginTestCase
 from sentry_plugins.bitbucket.plugin import BitbucketPlugin
 from sentry_plugins.bitbucket.plugin import BitbucketPlugin
 from social_auth.models import UserSocialAuth
 from social_auth.models import UserSocialAuth

+ 1 - 1
tests/sentry_plugins/bitbucket/test_repository_provider.py

@@ -4,7 +4,7 @@ import responses
 
 
 from sentry.models import Repository
 from sentry.models import Repository
 from sentry.testutils import TestCase
 from sentry.testutils import TestCase
-from sentry_plugins.bitbucket.plugin import BitbucketRepositoryProvider
+from sentry_plugins.bitbucket.repository_provider import BitbucketRepositoryProvider
 from sentry_plugins.bitbucket.testutils import COMMIT_DIFF_PATCH, COMPARE_COMMITS_EXAMPLE
 from sentry_plugins.bitbucket.testutils import COMMIT_DIFF_PATCH, COMPARE_COMMITS_EXAMPLE
 from social_auth.models import UserSocialAuth
 from social_auth.models import UserSocialAuth
 
 

+ 1 - 1
tests/sentry_plugins/github/test_plugin.py

@@ -5,7 +5,7 @@ import responses
 from django.contrib.auth.models import AnonymousUser
 from django.contrib.auth.models import AnonymousUser
 from django.test import RequestFactory
 from django.test import RequestFactory
 
 
-from sentry.plugins.bases.issue2 import PluginError
+from sentry.exceptions import PluginError
 from sentry.testutils import PluginTestCase
 from sentry.testutils import PluginTestCase
 from sentry.utils import json
 from sentry.utils import json
 from sentry_plugins.github.plugin import GitHubPlugin
 from sentry_plugins.github.plugin import GitHubPlugin

+ 4 - 1
tests/sentry_plugins/jira/test_plugin.py

@@ -1,4 +1,7 @@
+from __future__ import annotations
+
 from functools import cached_property
 from functools import cached_property
+from typing import Any
 
 
 import responses
 import responses
 from django.contrib.auth.models import AnonymousUser
 from django.contrib.auth.models import AnonymousUser
@@ -180,7 +183,7 @@ create_meta_response = {
     ],
     ],
 }
 }
 
 
-issue_response = {
+issue_response: dict[str, Any] = {
     "key": "SEN-19",
     "key": "SEN-19",
     "id": "10708",
     "id": "10708",
     "fields": {"summary": "TypeError: 'set' object has no attribute '__getitem__'"},
     "fields": {"summary": "TypeError: 'set' object has no attribute '__getitem__'"},

+ 1 - 0
tests/sentry_plugins/pagerduty/test_plugin.py

@@ -59,6 +59,7 @@ class PagerDutyPluginTest(PluginTestCase):
             },
             },
             project_id=self.project.id,
             project_id=self.project.id,
         )
         )
+        assert event.group is not None
         group = event.group
         group = event.group
 
 
         rule = Rule.objects.create(project=self.project, label="my rule")
         rule = Rule.objects.create(project=self.project, label="my rule")

+ 2 - 0
tests/sentry_plugins/pushover/test_plugin.py

@@ -40,6 +40,7 @@ class PushoverPluginTest(PluginTestCase):
         event = self.store_event(
         event = self.store_event(
             data={"message": "Hello world", "level": "warning"}, project_id=self.project.id
             data={"message": "Hello world", "level": "warning"}, project_id=self.project.id
         )
         )
+        assert event.group is not None
         group = event.group
         group = event.group
 
 
         rule = Rule.objects.create(project=self.project, label="my rule")
         rule = Rule.objects.create(project=self.project, label="my rule")
@@ -77,6 +78,7 @@ class PushoverPluginTest(PluginTestCase):
         event = self.store_event(
         event = self.store_event(
             data={"message": "Hello world", "level": "warning"}, project_id=self.project.id
             data={"message": "Hello world", "level": "warning"}, project_id=self.project.id
         )
         )
+        assert event.group is not None
         group = event.group
         group = event.group
 
 
         rule = Rule.objects.create(project=self.project, label="my rule")
         rule = Rule.objects.create(project=self.project, label="my rule")

Some files were not shown because too many files changed in this diff