Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add Module API for reading and writing global account data. #12391

Merged
merged 12 commits into from
Apr 11, 2022
46 changes: 46 additions & 0 deletions tests/module_api/test_account_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,49 @@ def test_get_global_no_mutability(self) -> None:
),
{"wombat": True},
)

def test_put_global(self) -> None:
"""
Tests that written account data using `put_global` can be read out again later.
"""

self.get_success(
self._module_api.account_data_manager.put_global(
self.user_id, "test.data", {"wombat": True}
)
)

# Request that account data from the normal store; check it's as we expect.
self.assertEqual(
self.get_success(
self._store.get_global_account_data_by_type_for_user(
self.user_id, "test.data"
)
),
{"wombat": True},
)

def test_put_global_validation(self) -> None:
clokep marked this conversation as resolved.
Show resolved Hide resolved
"""
Tests that a module can't write account data to user IDs that don't have
actual users registered to them.
"""

with self.assertRaises(SynapseError):
self.get_success_or_raise(
self._account_data_mgr.put_global(
"this isn't a user id", "test.data", {}
)
)

with self.assertRaises(ValueError):
self.get_success_or_raise(
self._account_data_mgr.put_global("@valid.but:remote", "test.data", {})
)

with self.assertRaises(ValueError):
self.get_success_or_raise(
self._module_api.account_data_manager.put_global(
"@notregistered:test", "test.data", {}
)
)