1
0

test_groups.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright 2021 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from synapse.rest.client import groups, room
  15. from tests import unittest
  16. from tests.unittest import override_config
  17. class GroupsTestCase(unittest.HomeserverTestCase):
  18. user_id = "@alice:test"
  19. room_creator_user_id = "@bob:test"
  20. servlets = [room.register_servlets, groups.register_servlets]
  21. @override_config({"enable_group_creation": True})
  22. def test_rooms_limited_by_visibility(self) -> None:
  23. group_id = "+spqr:test"
  24. # Alice creates a group
  25. channel = self.make_request("POST", "/create_group", {"localpart": "spqr"})
  26. self.assertEqual(channel.code, 200, msg=channel.text_body)
  27. self.assertEqual(channel.json_body, {"group_id": group_id})
  28. # Bob creates a private room
  29. room_id = self.helper.create_room_as(self.room_creator_user_id, is_public=False)
  30. self.helper.auth_user_id = self.room_creator_user_id
  31. self.helper.send_state(
  32. room_id, "m.room.name", {"name": "bob's secret room"}, tok=None
  33. )
  34. self.helper.auth_user_id = self.user_id
  35. # Alice adds the room to her group.
  36. channel = self.make_request(
  37. "PUT", f"/groups/{group_id}/admin/rooms/{room_id}", {}
  38. )
  39. self.assertEqual(channel.code, 200, msg=channel.text_body)
  40. self.assertEqual(channel.json_body, {})
  41. # Alice now tries to retrieve the room list of the space.
  42. channel = self.make_request("GET", f"/groups/{group_id}/rooms")
  43. self.assertEqual(channel.code, 200, msg=channel.text_body)
  44. self.assertEqual(
  45. channel.json_body, {"chunk": [], "total_room_count_estimate": 0}
  46. )