test_directory.py 2.2 KB

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