1
0

test_room.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 tests import unittest
  16. from twisted.internet import defer
  17. from synapse.api.constants import EventTypes
  18. from synapse.types import UserID, RoomID, RoomAlias
  19. from tests.utils import setup_test_homeserver
  20. class RoomStoreTestCase(unittest.TestCase):
  21. @defer.inlineCallbacks
  22. def setUp(self):
  23. hs = yield setup_test_homeserver()
  24. # We can't test RoomStore on its own without the DirectoryStore, for
  25. # management of the 'room_aliases' table
  26. self.store = hs.get_datastore()
  27. self.room = RoomID.from_string("!abcde:test")
  28. self.alias = RoomAlias.from_string("#a-room-name:test")
  29. self.u_creator = UserID.from_string("@creator:test")
  30. yield self.store.store_room(
  31. self.room.to_string(),
  32. room_creator_user_id=self.u_creator.to_string(),
  33. is_public=True
  34. )
  35. @defer.inlineCallbacks
  36. def test_get_room(self):
  37. self.assertDictContainsSubset(
  38. {
  39. "room_id": self.room.to_string(),
  40. "creator": self.u_creator.to_string(),
  41. "is_public": True
  42. },
  43. (yield self.store.get_room(self.room.to_string()))
  44. )
  45. class RoomEventsStoreTestCase(unittest.TestCase):
  46. @defer.inlineCallbacks
  47. def setUp(self):
  48. hs = setup_test_homeserver()
  49. # Room events need the full datastore, for persist_event() and
  50. # get_room_state()
  51. self.store = hs.get_datastore()
  52. self.event_factory = hs.get_event_factory()
  53. self.room = RoomID.from_string("!abcde:test")
  54. yield self.store.store_room(
  55. self.room.to_string(),
  56. room_creator_user_id="@creator:text",
  57. is_public=True
  58. )
  59. @defer.inlineCallbacks
  60. def inject_room_event(self, **kwargs):
  61. yield self.store.persist_event(
  62. self.event_factory.create_event(
  63. room_id=self.room.to_string(),
  64. **kwargs
  65. )
  66. )
  67. @defer.inlineCallbacks
  68. def STALE_test_room_name(self):
  69. name = u"A-Room-Name"
  70. yield self.inject_room_event(
  71. etype=EventTypes.Name,
  72. name=name,
  73. content={"name": name},
  74. depth=1,
  75. )
  76. state = yield self.store.get_current_state(
  77. room_id=self.room.to_string()
  78. )
  79. self.assertEquals(1, len(state))
  80. self.assertObjectHasAttributes(
  81. {"type": "m.room.name",
  82. "room_id": self.room.to_string(),
  83. "name": name},
  84. state[0]
  85. )
  86. @defer.inlineCallbacks
  87. def STALE_test_room_topic(self):
  88. topic = u"A place for things"
  89. yield self.inject_room_event(
  90. etype=EventTypes.Topic,
  91. topic=topic,
  92. content={"topic": topic},
  93. depth=1,
  94. )
  95. state = yield self.store.get_current_state(
  96. room_id=self.room.to_string()
  97. )
  98. self.assertEquals(1, len(state))
  99. self.assertObjectHasAttributes(
  100. {"type": "m.room.topic",
  101. "room_id": self.room.to_string(),
  102. "topic": topic},
  103. state[0]
  104. )
  105. # Not testing the various 'level' methods for now because there's lots
  106. # of them and need coalescing; see JIRA SPEC-11