You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

113 lines
3.6 KiB

  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.types import RoomAlias, RoomID, UserID
  18. from tests import unittest
  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(self.addCleanup)
  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(self.addCleanup)
  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(), room_creator_user_id="@creator:text", is_public=True
  56. )
  57. @defer.inlineCallbacks
  58. def inject_room_event(self, **kwargs):
  59. yield self.store.persist_event(
  60. self.event_factory.create_event(room_id=self.room.to_string(), **kwargs)
  61. )
  62. @defer.inlineCallbacks
  63. def STALE_test_room_name(self):
  64. name = u"A-Room-Name"
  65. yield self.inject_room_event(
  66. etype=EventTypes.Name, name=name, content={"name": name}, depth=1
  67. )
  68. state = yield self.store.get_current_state(room_id=self.room.to_string())
  69. self.assertEquals(1, len(state))
  70. self.assertObjectHasAttributes(
  71. {"type": "m.room.name", "room_id": self.room.to_string(), "name": name},
  72. state[0],
  73. )
  74. @defer.inlineCallbacks
  75. def STALE_test_room_topic(self):
  76. topic = u"A place for things"
  77. yield self.inject_room_event(
  78. etype=EventTypes.Topic, topic=topic, content={"topic": topic}, depth=1
  79. )
  80. state = yield self.store.get_current_state(room_id=self.room.to_string())
  81. self.assertEquals(1, len(state))
  82. self.assertObjectHasAttributes(
  83. {"type": "m.room.topic", "room_id": self.room.to_string(), "topic": topic},
  84. state[0],
  85. )
  86. # Not testing the various 'level' methods for now because there's lots
  87. # of them and need coalescing; see JIRA SPEC-11