mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-14 10:45:26 -04:00
Add type hints to tests/rest/client
(#12108)
* Add type hints to `tests/rest/client` * newsfile * fix imports * add `test_account.py` * Remove one type hint in `test_report_event.py` * change `on_create_room` to `async` * update new functions in `test_third_party_rules.py` * Add `test_filter.py` * add `test_rooms.py` * change to `assertEquals` to `assertEqual` * lint
This commit is contained in:
parent
b4461e7d8a
commit
2ffaf30803
9 changed files with 421 additions and 350 deletions
|
@ -14,11 +14,16 @@
|
|||
# limitations under the License.
|
||||
|
||||
"""Tests REST events for /rooms paths."""
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import Mock
|
||||
|
||||
from twisted.test.proto_helpers import MemoryReactor
|
||||
|
||||
from synapse.rest.client import room
|
||||
from synapse.server import HomeServer
|
||||
from synapse.storage.databases.main.registration import TokenLookupResult
|
||||
from synapse.types import UserID
|
||||
from synapse.util import Clock
|
||||
|
||||
from tests import unittest
|
||||
|
||||
|
@ -33,7 +38,7 @@ class RoomTypingTestCase(unittest.HomeserverTestCase):
|
|||
user = UserID.from_string(user_id)
|
||||
servlets = [room.register_servlets]
|
||||
|
||||
def make_homeserver(self, reactor, clock):
|
||||
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
|
||||
|
||||
hs = self.setup_test_homeserver(
|
||||
"red",
|
||||
|
@ -43,30 +48,34 @@ class RoomTypingTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
self.event_source = hs.get_event_sources().sources.typing
|
||||
|
||||
hs.get_federation_handler = Mock()
|
||||
hs.get_federation_handler = Mock() # type: ignore[assignment]
|
||||
|
||||
async def get_user_by_access_token(token=None, allow_guest=False):
|
||||
return {
|
||||
"user": UserID.from_string(self.auth_user_id),
|
||||
"token_id": 1,
|
||||
"is_guest": False,
|
||||
}
|
||||
async def get_user_by_access_token(
|
||||
token: str,
|
||||
rights: str = "access",
|
||||
allow_expired: bool = False,
|
||||
) -> TokenLookupResult:
|
||||
return TokenLookupResult(
|
||||
user_id=self.user_id,
|
||||
is_guest=False,
|
||||
token_id=1,
|
||||
)
|
||||
|
||||
hs.get_auth().get_user_by_access_token = get_user_by_access_token
|
||||
hs.get_auth().get_user_by_access_token = get_user_by_access_token # type: ignore[assignment]
|
||||
|
||||
async def _insert_client_ip(*args, **kwargs):
|
||||
async def _insert_client_ip(*args: Any, **kwargs: Any) -> None:
|
||||
return None
|
||||
|
||||
hs.get_datastores().main.insert_client_ip = _insert_client_ip
|
||||
hs.get_datastores().main.insert_client_ip = _insert_client_ip # type: ignore[assignment]
|
||||
|
||||
return hs
|
||||
|
||||
def prepare(self, reactor, clock, hs):
|
||||
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
|
||||
self.room_id = self.helper.create_room_as(self.user_id)
|
||||
# Need another user to make notifications actually work
|
||||
self.helper.join(self.room_id, user="@jim:red")
|
||||
|
||||
def test_set_typing(self):
|
||||
def test_set_typing(self) -> None:
|
||||
channel = self.make_request(
|
||||
"PUT",
|
||||
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
||||
|
@ -95,7 +104,7 @@ class RoomTypingTestCase(unittest.HomeserverTestCase):
|
|||
],
|
||||
)
|
||||
|
||||
def test_set_not_typing(self):
|
||||
def test_set_not_typing(self) -> None:
|
||||
channel = self.make_request(
|
||||
"PUT",
|
||||
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
||||
|
@ -103,7 +112,7 @@ class RoomTypingTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
self.assertEqual(200, channel.code)
|
||||
|
||||
def test_typing_timeout(self):
|
||||
def test_typing_timeout(self) -> None:
|
||||
channel = self.make_request(
|
||||
"PUT",
|
||||
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue