MatrixSynapse/tests/test_types.py

63 lines
2.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2016-01-07 05:26:29 +01:00
# Copyright 2014-2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from tests import unittest
2014-08-12 16:10:52 +02:00
from synapse.api.errors import SynapseError
2016-01-26 14:52:29 +01:00
from synapse.server import HomeServer
2014-08-12 16:10:52 +02:00
from synapse.types import UserID, RoomAlias
2016-01-26 14:52:29 +01:00
mock_homeserver = HomeServer(hostname="my.domain")
2014-08-12 16:10:52 +02:00
class UserIDTestCase(unittest.TestCase):
2014-08-12 16:10:52 +02:00
def test_parse(self):
2014-12-10 19:00:57 +01:00
user = UserID.from_string("@1234abcd:my.domain")
2014-08-12 16:10:52 +02:00
self.assertEquals("1234abcd", user.localpart)
self.assertEquals("my.domain", user.domain)
2014-12-10 19:00:57 +01:00
self.assertEquals(True, mock_homeserver.is_mine(user))
2014-08-12 16:10:52 +02:00
def test_pase_empty(self):
with self.assertRaises(SynapseError):
UserID.from_string("")
2014-08-12 16:10:52 +02:00
def test_build(self):
2014-12-10 19:00:57 +01:00
user = UserID("5678efgh", "my.domain")
2014-08-12 16:10:52 +02:00
self.assertEquals(user.to_string(), "@5678efgh:my.domain")
def test_compare(self):
2014-12-10 19:00:57 +01:00
userA = UserID.from_string("@userA:my.domain")
userAagain = UserID.from_string("@userA:my.domain")
userB = UserID.from_string("@userB:my.domain")
2014-08-12 16:10:52 +02:00
self.assertTrue(userA == userAagain)
self.assertTrue(userA != userB)
class RoomAliasTestCase(unittest.TestCase):
def test_parse(self):
2014-12-10 19:00:57 +01:00
room = RoomAlias.from_string("#channel:my.domain")
2014-08-12 16:10:52 +02:00
self.assertEquals("channel", room.localpart)
self.assertEquals("my.domain", room.domain)
2014-12-10 19:00:57 +01:00
self.assertEquals(True, mock_homeserver.is_mine(room))
2014-08-12 16:10:52 +02:00
def test_build(self):
2014-12-10 19:00:57 +01:00
room = RoomAlias("channel", "my.domain")
2014-08-12 16:10:52 +02:00
self.assertEquals(room.to_string(), "#channel:my.domain")