1
0

test_directory.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright 2014-2021 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from twisted.test.proto_helpers import MemoryReactor
  15. from synapse.server import HomeServer
  16. from synapse.types import RoomAlias, RoomID
  17. from synapse.util import Clock
  18. from tests.unittest import HomeserverTestCase
  19. class DirectoryStoreTestCase(HomeserverTestCase):
  20. def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
  21. self.store = hs.get_datastores().main
  22. self.room = RoomID.from_string("!abcde:test")
  23. self.alias = RoomAlias.from_string("#my-room:test")
  24. def test_room_to_alias(self) -> None:
  25. self.get_success(
  26. self.store.create_room_alias_association(
  27. room_alias=self.alias, room_id=self.room.to_string(), servers=["test"]
  28. )
  29. )
  30. self.assertEqual(
  31. ["#my-room:test"],
  32. (self.get_success(self.store.get_aliases_for_room(self.room.to_string()))),
  33. )
  34. def test_alias_to_room(self) -> None:
  35. self.get_success(
  36. self.store.create_room_alias_association(
  37. room_alias=self.alias, room_id=self.room.to_string(), servers=["test"]
  38. )
  39. )
  40. self.assertObjectHasAttributes(
  41. {"room_id": self.room.to_string(), "servers": ["test"]},
  42. (self.get_success(self.store.get_association_from_room_alias(self.alias))),
  43. )
  44. def test_delete_alias(self) -> None:
  45. self.get_success(
  46. self.store.create_room_alias_association(
  47. room_alias=self.alias, room_id=self.room.to_string(), servers=["test"]
  48. )
  49. )
  50. room_id = self.get_success(self.store.delete_room_alias(self.alias))
  51. self.assertEqual(self.room.to_string(), room_id)
  52. self.assertIsNone(
  53. self.get_success(self.store.get_association_from_room_alias(self.alias))
  54. )