test_room.py 2.4 KB

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