Reinstate removed EventBase methods (#19712)

Both `__getitem__` and `.user_id` were removed in #19680 to simplify the
event class. However, `EventBase` is exposed to modules who might also
make use of those methods, so let's reinstate them (but otherwise not
reinstate the usage of them in the code).
This commit is contained in:
Erik Johnston
2026-04-22 11:43:59 +01:00
committed by GitHub
parent 3cdae2e278
commit c8ce96f504
3 changed files with 28 additions and 0 deletions
+18
View File
@@ -828,6 +828,24 @@ class ModuleApiTestCase(BaseModuleApiTestCase):
# Ensure the pushers were deleted after the callback.
self.assertEqual(len(self.hs.get_pusherpool().pushers[user_id].values()), 0)
def test_event_deprecated_methods(self) -> None:
"""Test that deprecated methods on events are still functional."""
user_id = self.register_user("user", "password")
tok = self.login("user", "password")
room_id = self.helper.create_room_as(tok=tok)
state = self.get_success(
self.hs.get_storage_controllers().state.get_current_state(room_id)
)
create_event = state[(EventTypes.Create, "")]
# `.user_id` is a deprecated alias for `.sender`.
self.assertEqual(create_event.user_id, user_id)
# The event supports looking up keys via `__getitem__` although deprecated
self.assertEqual(create_event["room_id"], room_id)
class ModuleApiWorkerTestCase(BaseModuleApiTestCase, BaseMultiWorkerStreamTestCase):
"""For testing ModuleApi functionality in a multi-worker setup"""