Additional constants for EDU types. (#12884)

Instead of hard-coding strings in many places.
This commit is contained in:
Patrick Cloke 2022-05-27 07:14:36 -04:00 committed by GitHub
parent d9f092285b
commit c52abc1cfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 146 additions and 96 deletions

View file

@ -21,6 +21,7 @@ from twisted.internet import defer
from twisted.test.proto_helpers import MemoryReactor
from twisted.web.resource import Resource
from synapse.api.constants import EduTypes
from synapse.api.errors import AuthError
from synapse.federation.transport.server import TransportLayerServer
from synapse.server import HomeServer
@ -184,7 +185,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
events[0],
[
{
"type": "m.typing",
"type": EduTypes.TYPING,
"room_id": ROOM_ID,
"content": {"user_ids": [U_APPLE.to_string()]},
}
@ -209,7 +210,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
"farm",
path="/_matrix/federation/v1/send/1000000",
data=_expect_edu_transaction(
"m.typing",
EduTypes.TYPING,
content={
"room_id": ROOM_ID,
"user_id": U_APPLE.to_string(),
@ -231,7 +232,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
"PUT",
"/_matrix/federation/v1/send/1000000",
_make_edu_transaction_json(
"m.typing",
EduTypes.TYPING,
content={
"room_id": ROOM_ID,
"user_id": U_ONION.to_string(),
@ -254,7 +255,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
events[0],
[
{
"type": "m.typing",
"type": EduTypes.TYPING,
"room_id": ROOM_ID,
"content": {"user_ids": [U_ONION.to_string()]},
}
@ -270,7 +271,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
"PUT",
"/_matrix/federation/v1/send/1000000",
_make_edu_transaction_json(
"m.typing",
EduTypes.TYPING,
content={
"room_id": OTHER_ROOM_ID,
"user_id": U_ONION.to_string(),
@ -324,7 +325,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
"farm",
path="/_matrix/federation/v1/send/1000000",
data=_expect_edu_transaction(
"m.typing",
EduTypes.TYPING,
content={
"room_id": ROOM_ID,
"user_id": U_APPLE.to_string(),
@ -345,7 +346,13 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
)
self.assertEqual(
events[0],
[{"type": "m.typing", "room_id": ROOM_ID, "content": {"user_ids": []}}],
[
{
"type": EduTypes.TYPING,
"room_id": ROOM_ID,
"content": {"user_ids": []},
}
],
)
def test_typing_timeout(self) -> None:
@ -379,7 +386,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
events[0],
[
{
"type": "m.typing",
"type": EduTypes.TYPING,
"room_id": ROOM_ID,
"content": {"user_ids": [U_APPLE.to_string()]},
}
@ -402,7 +409,13 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
)
self.assertEqual(
events[0],
[{"type": "m.typing", "room_id": ROOM_ID, "content": {"user_ids": []}}],
[
{
"type": EduTypes.TYPING,
"room_id": ROOM_ID,
"content": {"user_ids": []},
}
],
)
# SYN-230 - see if we can still set after timeout
@ -433,7 +446,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
events[0],
[
{
"type": "m.typing",
"type": EduTypes.TYPING,
"room_id": ROOM_ID,
"content": {"user_ids": [U_APPLE.to_string()]},
}