test_directory.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.storage.directory import DirectoryStore
  17. from synapse.types import RoomAlias, RoomID
  18. from tests import unittest
  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(self.addCleanup)
  24. self.store = DirectoryStore(None, 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, room_id=self.room.to_string(), servers=["test"]
  31. )
  32. self.assertEquals(
  33. ["#my-room:test"],
  34. (yield self.store.get_aliases_for_room(self.room.to_string())),
  35. )
  36. @defer.inlineCallbacks
  37. def test_alias_to_room(self):
  38. yield self.store.create_room_alias_association(
  39. room_alias=self.alias, room_id=self.room.to_string(), servers=["test"]
  40. )
  41. self.assertObjectHasAttributes(
  42. {"room_id": self.room.to_string(), "servers": ["test"]},
  43. (yield self.store.get_association_from_room_alias(self.alias)),
  44. )
  45. @defer.inlineCallbacks
  46. def test_delete_alias(self):
  47. yield self.store.create_room_alias_association(
  48. room_alias=self.alias, room_id=self.room.to_string(), servers=["test"]
  49. )
  50. room_id = yield self.store.delete_room_alias(self.alias)
  51. self.assertEqual(self.room.to_string(), room_id)
  52. self.assertIsNone(
  53. (yield self.store.get_association_from_room_alias(self.alias))
  54. )