1
0

test_room.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from twisted.internet import defer
  16. from synapse.api.constants import EventTypes
  17. from synapse.api.room_versions import RoomVersions
  18. from synapse.types import RoomAlias, RoomID, UserID
  19. from tests import unittest
  20. from tests.utils import setup_test_homeserver
  21. class RoomStoreTestCase(unittest.TestCase):
  22. @defer.inlineCallbacks
  23. def setUp(self):
  24. hs = yield setup_test_homeserver(self.addCleanup)
  25. # We can't test RoomStore on its own without the DirectoryStore, for
  26. # management of the 'room_aliases' table
  27. self.store = hs.get_datastore()
  28. self.room = RoomID.from_string("!abcde:test")
  29. self.alias = RoomAlias.from_string("#a-room-name:test")
  30. self.u_creator = UserID.from_string("@creator:test")
  31. yield self.store.store_room(
  32. self.room.to_string(),
  33. room_creator_user_id=self.u_creator.to_string(),
  34. is_public=True,
  35. room_version=RoomVersions.V1,
  36. )
  37. @defer.inlineCallbacks
  38. def test_get_room(self):
  39. self.assertDictContainsSubset(
  40. {
  41. "room_id": self.room.to_string(),
  42. "creator": self.u_creator.to_string(),
  43. "is_public": True,
  44. },
  45. (yield self.store.get_room(self.room.to_string())),
  46. )
  47. class RoomEventsStoreTestCase(unittest.TestCase):
  48. @defer.inlineCallbacks
  49. def setUp(self):
  50. hs = setup_test_homeserver(self.addCleanup)
  51. # Room events need the full datastore, for persist_event() and
  52. # get_room_state()
  53. self.store = hs.get_datastore()
  54. self.storage = hs.get_storage()
  55. self.event_factory = hs.get_event_factory()
  56. self.room = RoomID.from_string("!abcde:test")
  57. yield self.store.store_room(
  58. self.room.to_string(),
  59. room_creator_user_id="@creator:text",
  60. is_public=True,
  61. room_version=RoomVersions.V1,
  62. )
  63. @defer.inlineCallbacks
  64. def inject_room_event(self, **kwargs):
  65. yield self.storage.persistence.persist_event(
  66. self.event_factory.create_event(room_id=self.room.to_string(), **kwargs)
  67. )
  68. @defer.inlineCallbacks
  69. def STALE_test_room_name(self):
  70. name = "A-Room-Name"
  71. yield self.inject_room_event(
  72. etype=EventTypes.Name, name=name, content={"name": name}, depth=1
  73. )
  74. state = yield self.store.get_current_state(room_id=self.room.to_string())
  75. self.assertEquals(1, len(state))
  76. self.assertObjectHasAttributes(
  77. {"type": "m.room.name", "room_id": self.room.to_string(), "name": name},
  78. state[0],
  79. )
  80. @defer.inlineCallbacks
  81. def STALE_test_room_topic(self):
  82. topic = "A place for things"
  83. yield self.inject_room_event(
  84. etype=EventTypes.Topic, topic=topic, content={"topic": topic}, depth=1
  85. )
  86. state = yield self.store.get_current_state(room_id=self.room.to_string())
  87. self.assertEquals(1, len(state))
  88. self.assertObjectHasAttributes(
  89. {"type": "m.room.topic", "room_id": self.room.to_string(), "topic": topic},
  90. state[0],
  91. )
  92. # Not testing the various 'level' methods for now because there's lots
  93. # of them and need coalescing; see JIRA SPEC-11