summary refs log tree commit diff
path: root/tests/rest/admin
diff options
context:
space:
mode:
authorMichael Albert <37796947+awesome-michael@users.noreply.github.com>2020-07-16 22:43:23 +0200
committerGitHub <noreply@github.com>2020-07-16 16:43:23 -0400
commitfff483ea96160912ee4e9f5f3f743b86a933058f (patch)
treea9fcc72cbbab8b54309d8cf0260402e710a3333b /tests/rest/admin
parentConsistently use `db_to_json` to convert from database values to JSON objects... (diff)
downloadsynapse-fff483ea96160912ee4e9f5f3f743b86a933058f.tar.xz
Add admin endpoint to get members in a room. (#7842)
Diffstat (limited to '')
-rw-r--r--tests/rest/admin/test_room.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/rest/admin/test_room.py b/tests/rest/admin/test_room.py
index a80537c4fc..946f06d151 100644
--- a/tests/rest/admin/test_room.py
+++ b/tests/rest/admin/test_room.py
@@ -1136,6 +1136,52 @@ class RoomTestCase(unittest.HomeserverTestCase):
 

         self.assertEqual(room_id_1, channel.json_body["room_id"])

 

+    def test_room_members(self):

+        """Test that room members can be requested correctly"""

+        # Create two test rooms

+        room_id_1 = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)

+        room_id_2 = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)

+

+        # Have another user join the room

+        user_1 = self.register_user("foo", "pass")

+        user_tok_1 = self.login("foo", "pass")

+        self.helper.join(room_id_1, user_1, tok=user_tok_1)

+

+        # Have another user join the room

+        user_2 = self.register_user("bar", "pass")

+        user_tok_2 = self.login("bar", "pass")

+        self.helper.join(room_id_1, user_2, tok=user_tok_2)

+        self.helper.join(room_id_2, user_2, tok=user_tok_2)

+

+        # Have another user join the room

+        user_3 = self.register_user("foobar", "pass")

+        user_tok_3 = self.login("foobar", "pass")

+        self.helper.join(room_id_2, user_3, tok=user_tok_3)

+

+        url = "/_synapse/admin/v1/rooms/%s/members" % (room_id_1,)

+        request, channel = self.make_request(

+            "GET", url.encode("ascii"), access_token=self.admin_user_tok,

+        )

+        self.render(request)

+        self.assertEqual(200, channel.code, msg=channel.json_body)

+

+        self.assertCountEqual(

+            ["@admin:test", "@foo:test", "@bar:test"], channel.json_body["members"]

+        )

+        self.assertEqual(channel.json_body["total"], 3)

+

+        url = "/_synapse/admin/v1/rooms/%s/members" % (room_id_2,)

+        request, channel = self.make_request(

+            "GET", url.encode("ascii"), access_token=self.admin_user_tok,

+        )

+        self.render(request)

+        self.assertEqual(200, channel.code, msg=channel.json_body)

+

+        self.assertCountEqual(

+            ["@admin:test", "@bar:test", "@foobar:test"], channel.json_body["members"]

+        )

+        self.assertEqual(channel.json_body["total"], 3)

+

 

 class JoinAliasRoomTestCase(unittest.HomeserverTestCase):