test_types.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014 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 synapse.server import BaseHomeServer
  17. from synapse.types import UserID, RoomAlias
  18. mock_homeserver = BaseHomeServer(hostname="my.domain")
  19. class UserIDTestCase(unittest.TestCase):
  20. def test_parse(self):
  21. user = UserID.from_string("@1234abcd:my.domain")
  22. self.assertEquals("1234abcd", user.localpart)
  23. self.assertEquals("my.domain", user.domain)
  24. self.assertEquals(True, mock_homeserver.is_mine(user))
  25. def test_build(self):
  26. user = UserID("5678efgh", "my.domain")
  27. self.assertEquals(user.to_string(), "@5678efgh:my.domain")
  28. def test_compare(self):
  29. userA = UserID.from_string("@userA:my.domain")
  30. userAagain = UserID.from_string("@userA:my.domain")
  31. userB = UserID.from_string("@userB:my.domain")
  32. self.assertTrue(userA == userAagain)
  33. self.assertTrue(userA != userB)
  34. class RoomAliasTestCase(unittest.TestCase):
  35. def test_parse(self):
  36. room = RoomAlias.from_string("#channel:my.domain")
  37. self.assertEquals("channel", room.localpart)
  38. self.assertEquals("my.domain", room.domain)
  39. self.assertEquals(True, mock_homeserver.is_mine(room))
  40. def test_build(self):
  41. room = RoomAlias("channel", "my.domain")
  42. self.assertEquals(room.to_string(), "#channel:my.domain")