Skip to content

Commit

Permalink
fixing typing
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunicorn committed Nov 15, 2023
1 parent 2a223c7 commit 2f8f0fa
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions synapse_super_invites/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, config: SynapseSuperInvitesConfig, api: ModuleApi):
self._config = config
self.setup()

def setup(self):
def setup(self) -> None:
self._api.register_web_resource(
"/_synapse/client/super_invites/static",
File(os.path.join(PKG_DIR, "static")),
Expand All @@ -42,4 +42,4 @@ def parse_config(config: Dict[str, Any]) -> SynapseSuperInvitesConfig:
try:
return SynapseSuperInvitesConfig(**config)
except TypeError as e:
raise ConfigError(e)
raise ConfigError(str(e))
8 changes: 4 additions & 4 deletions synapse_super_invites/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os

import alembic.config
from sqlalchemy import Engine
from alembic.config import Config
import alembic
import attr

PKG_DIR = os.path.dirname(os.path.realpath(__file__))


def run_alembic(engine):
from alembic.config import Config

def run_alembic(engine: Engine) -> None:
alembic_cfg = Config(os.path.join(PKG_DIR, "..", "alembic.ini"))
alembic_cfg.set_main_option("script_location", os.path.join(PKG_DIR, "migration"))

Expand Down
4 changes: 2 additions & 2 deletions synapse_super_invites/migration/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def run_migrations_offline() -> None:
context.run_migrations()


def run_migrations_online():
def run_migrations_online() -> None:
connectable = config.attributes.get("connection", None)

if connectable is None:
# only create Engine if we don't have a Connection
# from the outside
connectable = engine_from_config(
config.get_section(config.config_ini_section),
config.get_section(config.config_ini_section), # type: ignore[arg-type]
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
Expand Down
6 changes: 3 additions & 3 deletions synapse_super_invites/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from synapse.http.servlet import parse_json_object_from_request, parse_string
from synapse.http.site import SynapseRequest
from synapse.module_api import ModuleApi
from synapse.types import JsonDict, Requester, Tuple
from synapse.types import JsonDict, Requester, Tuple # type: ignore[attr-defined]

from synapse_super_invites.config import SynapseSuperInvitesConfig
from synapse_super_invites.model import Accepted, Room, Token
Expand All @@ -24,15 +24,15 @@ def serialize_token(token: Token) -> JsonDict:
}


def token_query(token_id: str):
def token_query(token_id: str): # type: ignore[no-untyped-def]
return select(Token).where(
Token.token == token_id, Token.deleted_at == None # noqa: E711
)


class SuperInviteResourceBase(DirectServeJsonResource):
def __init__(
self, config: SynapseSuperInvitesConfig, api: ModuleApi, sessions: sessionmaker
self, config: SynapseSuperInvitesConfig, api: ModuleApi, sessions: sessionmaker # type: ignore[type-arg]
):
super().__init__()
self.config = config
Expand Down
29 changes: 15 additions & 14 deletions tests/test_integrations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from matrix_synapse_testutils.unittest import HomeserverTestCase, override_config
from matrix_synapse_testutils.unittest import HomeserverTestCase, override_config # type: ignore[import-untyped]
from synapse.rest import admin
from synapse.rest.client import login, profile, register, room, sync
from synapse.server import HomeServer
from synapse.types import Dict
from synapse.types import Dict # type: ignore[attr-defined]
from synapse.util import Clock
from twisted.test.proto_helpers import MemoryReactor
from twisted.web.resource import Resource
Expand All @@ -20,7 +20,7 @@


# Some more local helpers
class SuperInviteHomeserverTestCase(HomeserverTestCase):
class SuperInviteHomeserverTestCase(HomeserverTestCase): # type: ignore[misc]
servlets = [
admin.register_servlets,
login.register_servlets,
Expand All @@ -38,20 +38,21 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
self.auth_handler = hs.get_auth_handler()

def create_resource_dict(self) -> Dict[str, Resource]:
d = super().create_resource_dict()
d : Dict[str, Resource] = super().create_resource_dict()
for key in self.hs._module_web_resources:
d[key] = self.hs._module_web_resources[key]
return d

# create a room with the given access_token, return the roomId
def create_room(self, user_id) -> str:
return self.get_success(
def create_room(self, user_id: str) -> str:
room_id: str = self.get_success(
self.module_api.create_room(user_id=user_id, config={}, ratelimit=False)
)[0]
return room_id


class SimpleInviteTests(SuperInviteHomeserverTestCase):
@override_config(DEFAULT_CONFIG)
@override_config(DEFAULT_CONFIG) #type: ignore[misc]
def test_edit_invite_token_rooms(self) -> None:
m_id = self.register_user("meeko", "password")
m_access_token = self.login("meeko", "password")
Expand Down Expand Up @@ -108,7 +109,7 @@ def test_edit_invite_token_rooms(self) -> None:
self.assertCountEqual(token_data["rooms"], rooms_to_invite)
self.assertEqual(token_data["create_dm"], True)

@override_config(DEFAULT_CONFIG)
@override_config(DEFAULT_CONFIG) # type: ignore[misc]
def test_simple_invite_token_test(self) -> None:
m_id = self.register_user("meeko", "password")
m_access_token = self.login("meeko", "password")
Expand Down Expand Up @@ -193,7 +194,7 @@ def test_simple_invite_token_test(self) -> None:
}
],
}
)
) # type: ignore[misc]
def test_simple_invite_as_registration_token_test(self) -> None:
_m_id = self.register_user("meeko", "password")
m_access_token = self.login("meeko", "password")
Expand Down Expand Up @@ -225,7 +226,7 @@ def test_simple_invite_as_registration_token_test(self) -> None:
self.assertEqual(channel.code, 200, msg=channel.result)
self.assertTrue(channel.json_body["valid"])

@override_config(DEFAULT_CONFIG)
@override_config(DEFAULT_CONFIG) # type: ignore[misc]
def test_simple_invite_token_only_dm_test(self) -> None:
_m_id = self.register_user("meeko", "password")
m_access_token = self.login("meeko", "password")
Expand Down Expand Up @@ -292,7 +293,7 @@ def test_simple_invite_token_only_dm_test(self) -> None:
self.assertEqual(channel.json_body["rooms"].get("invite"), None)
self.assertCountEqual(channel.json_body["rooms"]["join"].keys(), [new_dm])

@override_config(DEFAULT_CONFIG)
@override_config(DEFAULT_CONFIG) # type: ignore[misc]
def test_simple_invite_token_with_dm_test(self) -> None:
m_id = self.register_user("meeko", "password")
m_access_token = self.login("meeko", "password")
Expand Down Expand Up @@ -374,7 +375,7 @@ def test_simple_invite_token_with_dm_test(self) -> None:
# the dm is sent in our name, we already joined it.
self.assertCountEqual(channel.json_body["rooms"]["join"].keys(), [my_dm])

@override_config(DEFAULT_CONFIG)
@override_config(DEFAULT_CONFIG) # type: ignore[misc]
def test_only_dm_redeem_once(self) -> None:
_m_id = self.register_user("meeko", "password")
m_access_token = self.login("meeko", "password")
Expand Down Expand Up @@ -436,7 +437,7 @@ def test_only_dm_redeem_once(self) -> None:
)
self.assertEqual(channel.code, 400, msg=channel.result)

@override_config(DEFAULT_CONFIG)
@override_config(DEFAULT_CONFIG) # type: ignore[misc]
def test_deletion(self) -> None:
_m_id = self.register_user("meeko", "password")
m_access_token = self.login("meeko", "password")
Expand Down Expand Up @@ -510,7 +511,7 @@ def test_deletion(self) -> None:
)
self.assertEqual(channel.code, 404, msg=channel.result)

@override_config(DEFAULT_CONFIG)
@override_config(DEFAULT_CONFIG) # type: ignore[misc]
def test_cant_redeem_my_own(self) -> None:
_m_id = self.register_user("meeko", "password")
m_access_token = self.login("meeko", "password")
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ commands =
extras = dev

commands =
mypy synapse_super_invites {posargs:tests}
mypy synapse_super_invites tests

0 comments on commit 2f8f0fa

Please sign in to comment.