mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-11-09 16:14:57 -05:00
Add tests for using _flatten_dict with an event. (#15002)
This commit is contained in:
parent
d0fed7a37b
commit
5b55c32d61
3 changed files with 68 additions and 9 deletions
|
|
@ -22,7 +22,7 @@ import synapse.rest.admin
|
|||
from synapse.api.constants import EventTypes, HistoryVisibility, Membership
|
||||
from synapse.api.room_versions import RoomVersions
|
||||
from synapse.appservice import ApplicationService
|
||||
from synapse.events import FrozenEvent
|
||||
from synapse.events import FrozenEvent, make_event_from_dict
|
||||
from synapse.push.bulk_push_rule_evaluator import _flatten_dict
|
||||
from synapse.push.httppusher import tweaks_for_actions
|
||||
from synapse.rest import admin
|
||||
|
|
@ -60,6 +60,67 @@ class FlattenDictTestCase(unittest.TestCase):
|
|||
}
|
||||
self.assertEqual({"woo": "woo"}, _flatten_dict(input))
|
||||
|
||||
def test_event(self) -> None:
|
||||
"""Events can also be flattened."""
|
||||
event = make_event_from_dict(
|
||||
{
|
||||
"room_id": "!test:test",
|
||||
"type": "m.room.message",
|
||||
"sender": "@alice:test",
|
||||
"content": {
|
||||
"msgtype": "m.text",
|
||||
"body": "Hello world!",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "<h1>Hello world!</h1>",
|
||||
},
|
||||
},
|
||||
room_version=RoomVersions.V8,
|
||||
)
|
||||
expected = {
|
||||
"content.msgtype": "m.text",
|
||||
"content.body": "hello world!",
|
||||
"content.format": "org.matrix.custom.html",
|
||||
"content.formatted_body": "<h1>hello world!</h1>",
|
||||
"room_id": "!test:test",
|
||||
"sender": "@alice:test",
|
||||
"type": "m.room.message",
|
||||
}
|
||||
self.assertEqual(expected, _flatten_dict(event))
|
||||
|
||||
def test_extensible_events(self) -> None:
|
||||
"""Extensible events has compatibility behaviour."""
|
||||
event_dict = {
|
||||
"room_id": "!test:test",
|
||||
"type": "m.room.message",
|
||||
"sender": "@alice:test",
|
||||
"content": {
|
||||
"org.matrix.msc1767.markup": [
|
||||
{"mimetype": "text/plain", "body": "Hello world!"},
|
||||
{"mimetype": "text/html", "body": "<h1>Hello world!</h1>"},
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
# For a current room version, there's no special behavior.
|
||||
event = make_event_from_dict(event_dict, room_version=RoomVersions.V8)
|
||||
expected = {
|
||||
"room_id": "!test:test",
|
||||
"sender": "@alice:test",
|
||||
"type": "m.room.message",
|
||||
}
|
||||
self.assertEqual(expected, _flatten_dict(event))
|
||||
|
||||
# For a room version with extensible events, they parse out the text/plain
|
||||
# to a content.body property.
|
||||
event = make_event_from_dict(event_dict, room_version=RoomVersions.MSC1767v10)
|
||||
expected = {
|
||||
"content.body": "hello world!",
|
||||
"room_id": "!test:test",
|
||||
"sender": "@alice:test",
|
||||
"type": "m.room.message",
|
||||
}
|
||||
self.assertEqual(expected, _flatten_dict(event))
|
||||
|
||||
|
||||
class PushRuleEvaluatorTestCase(unittest.TestCase):
|
||||
def _get_evaluator(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue