1
0

test_room.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. res = self.get_success(self.store.get_room(self.room.to_string()))
  38. assert res is not None
  39. self.assertDictContainsSubset(
  40. {
  41. "room_id": self.room.to_string(),
  42. "creator": self.u_creator.to_string(),
  43. "is_public": True,
  44. },
  45. res,
  46. )
  47. def test_get_room_unknown_room(self) -> None:
  48. self.assertIsNone(self.get_success(self.store.get_room("!uknown:test")))
  49. def test_get_room_with_stats(self) -> None:
  50. res = self.get_success(self.store.get_room_with_stats(self.room.to_string()))
  51. assert res is not None
  52. self.assertDictContainsSubset(
  53. {
  54. "room_id": self.room.to_string(),
  55. "creator": self.u_creator.to_string(),
  56. "public": True,
  57. },
  58. res,
  59. )
  60. def test_get_room_with_stats_unknown_room(self) -> None:
  61. self.assertIsNone(
  62. self.get_success(self.store.get_room_with_stats("!uknown:test"))
  63. )