test_room.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright 2014-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 twisted.test.proto_helpers import MemoryReactor
  15. from synapse.api.room_versions import RoomVersions
  16. from synapse.server import HomeServer
  17. from synapse.types import RoomAlias, RoomID, UserID
  18. from synapse.util import Clock
  19. from tests.unittest import HomeserverTestCase
  20. class RoomStoreTestCase(HomeserverTestCase):
  21. def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
  22. # We can't test RoomStore on its own without the DirectoryStore, for
  23. # management of the 'room_aliases' table
  24. self.store = hs.get_datastores().main
  25. self.room = RoomID.from_string("!abcde:test")
  26. self.alias = RoomAlias.from_string("#a-room-name:test")
  27. self.u_creator = UserID.from_string("@creator:test")
  28. self.get_success(
  29. self.store.store_room(
  30. self.room.to_string(),
  31. room_creator_user_id=self.u_creator.to_string(),
  32. is_public=True,
  33. room_version=RoomVersions.V1,
  34. )
  35. )
  36. def test_get_room(self) -> None:
  37. room = self.get_success(self.store.get_room(self.room.to_string()))
  38. assert room is not None
  39. self.assertTrue(room[0])
  40. def test_get_room_unknown_room(self) -> None:
  41. self.assertIsNone(self.get_success(self.store.get_room("!uknown:test")))
  42. def test_get_room_with_stats(self) -> None:
  43. res = self.get_success(self.store.get_room_with_stats(self.room.to_string()))
  44. assert res is not None
  45. self.assertEqual(res.room_id, self.room.to_string())
  46. self.assertEqual(res.creator, self.u_creator.to_string())
  47. self.assertTrue(res.public)
  48. def test_get_room_with_stats_unknown_room(self) -> None:
  49. self.assertIsNone(
  50. self.get_success(self.store.get_room_with_stats("!uknown:test"))
  51. )