test_directory.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.storage.directory import DirectoryStore
  18. from synapse.types import RoomID, RoomAlias
  19. from tests.utils import setup_test_homeserver
  20. class DirectoryStoreTestCase(unittest.TestCase):
  21. @defer.inlineCallbacks
  22. def setUp(self):
  23. hs = yield setup_test_homeserver()
  24. self.store = DirectoryStore(hs)
  25. self.room = RoomID.from_string("!abcde:test")
  26. self.alias = RoomAlias.from_string("#my-room:test")
  27. @defer.inlineCallbacks
  28. def test_room_to_alias(self):
  29. yield self.store.create_room_alias_association(
  30. room_alias=self.alias,
  31. room_id=self.room.to_string(),
  32. servers=["test"],
  33. )
  34. self.assertEquals(
  35. ["#my-room:test"],
  36. (yield self.store.get_aliases_for_room(self.room.to_string()))
  37. )
  38. @defer.inlineCallbacks
  39. def test_alias_to_room(self):
  40. yield self.store.create_room_alias_association(
  41. room_alias=self.alias,
  42. room_id=self.room.to_string(),
  43. servers=["test"],
  44. )
  45. self.assertObjectHasAttributes(
  46. {
  47. "room_id": self.room.to_string(),
  48. "servers": ["test"],
  49. },
  50. (yield self.store.get_association_from_room_alias(self.alias))
  51. )
  52. @defer.inlineCallbacks
  53. def test_delete_alias(self):
  54. yield self.store.create_room_alias_association(
  55. room_alias=self.alias,
  56. room_id=self.room.to_string(),
  57. servers=["test"],
  58. )
  59. room_id = yield self.store.delete_room_alias(self.alias)
  60. self.assertEqual(self.room.to_string(), room_id)
  61. self.assertIsNone(
  62. (yield self.store.get_association_from_room_alias(self.alias))
  63. )