summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorJason Robinson <jasonr@element.io>2021-08-04 13:40:25 +0300
committerGitHub <noreply@github.com>2021-08-04 10:40:25 +0000
commitc2000ab35b76288a625f598d2382d4e3f29f65f6 (patch)
treeb0f5bdd7e9fe5fb2002d0cf166ce73b2c16d336f /tests
parentAdd warnings to ip_range_blacklist usage with proxies (#10129) (diff)
downloadsynapse-c2000ab35b76288a625f598d2382d4e3f29f65f6.tar.xz
Add `get_userinfo_by_id` method to `ModuleApi` (#9581)
Makes it easier to fetch user details in for example spam checker modules, without needing to use api._store or figure out database interactions.

Signed-off-by: Jason Robinson <jasonr@matrix.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/module_api/test_api.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/module_api/test_api.py b/tests/module_api/test_api.py
index 81d9e2f484..0b817cc701 100644
--- a/tests/module_api/test_api.py
+++ b/tests/module_api/test_api.py
@@ -79,6 +79,16 @@ class ModuleApiTestCase(HomeserverTestCase):
         displayname = self.get_success(self.store.get_profile_displayname("bob"))
         self.assertEqual(displayname, "Bobberino")
 
+    def test_get_userinfo_by_id(self):
+        user_id = self.register_user("alice", "1234")
+        found_user = self.get_success(self.module_api.get_userinfo_by_id(user_id))
+        self.assertEqual(found_user.user_id.to_string(), user_id)
+        self.assertIdentical(found_user.is_admin, False)
+
+    def test_get_userinfo_by_id__no_user_found(self):
+        found_user = self.get_success(self.module_api.get_userinfo_by_id("@alice:test"))
+        self.assertIsNone(found_user)
+
     def test_sending_events_into_room(self):
         """Tests that a module can send events into a room"""
         # Mock out create_and_send_nonmember_event to check whether events are being sent