mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-13 21:41:30 +01:00
Update unit tests to use new format.
This commit is contained in:
parent
40c9896705
commit
127efeeb68
2 changed files with 32 additions and 19 deletions
|
@ -18,6 +18,13 @@ from mock import Mock, PropertyMock
|
||||||
from tests import unittest
|
from tests import unittest
|
||||||
|
|
||||||
|
|
||||||
|
def _regex(regex, exclusive=True):
|
||||||
|
return {
|
||||||
|
"regex": regex,
|
||||||
|
exclusive: exclusive
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ApplicationServiceTestCase(unittest.TestCase):
|
class ApplicationServiceTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -36,21 +43,21 @@ class ApplicationServiceTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_regex_user_id_prefix_match(self):
|
def test_regex_user_id_prefix_match(self):
|
||||||
self.service.namespaces[ApplicationService.NS_USERS].append(
|
self.service.namespaces[ApplicationService.NS_USERS].append(
|
||||||
"@irc_.*"
|
_regex("@irc_.*")
|
||||||
)
|
)
|
||||||
self.event.sender = "@irc_foobar:matrix.org"
|
self.event.sender = "@irc_foobar:matrix.org"
|
||||||
self.assertTrue(self.service.is_interested(self.event))
|
self.assertTrue(self.service.is_interested(self.event))
|
||||||
|
|
||||||
def test_regex_user_id_prefix_no_match(self):
|
def test_regex_user_id_prefix_no_match(self):
|
||||||
self.service.namespaces[ApplicationService.NS_USERS].append(
|
self.service.namespaces[ApplicationService.NS_USERS].append(
|
||||||
"@irc_.*"
|
_regex("@irc_.*")
|
||||||
)
|
)
|
||||||
self.event.sender = "@someone_else:matrix.org"
|
self.event.sender = "@someone_else:matrix.org"
|
||||||
self.assertFalse(self.service.is_interested(self.event))
|
self.assertFalse(self.service.is_interested(self.event))
|
||||||
|
|
||||||
def test_regex_room_member_is_checked(self):
|
def test_regex_room_member_is_checked(self):
|
||||||
self.service.namespaces[ApplicationService.NS_USERS].append(
|
self.service.namespaces[ApplicationService.NS_USERS].append(
|
||||||
"@irc_.*"
|
_regex("@irc_.*")
|
||||||
)
|
)
|
||||||
self.event.sender = "@someone_else:matrix.org"
|
self.event.sender = "@someone_else:matrix.org"
|
||||||
self.event.type = "m.room.member"
|
self.event.type = "m.room.member"
|
||||||
|
@ -59,21 +66,21 @@ class ApplicationServiceTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_regex_room_id_match(self):
|
def test_regex_room_id_match(self):
|
||||||
self.service.namespaces[ApplicationService.NS_ROOMS].append(
|
self.service.namespaces[ApplicationService.NS_ROOMS].append(
|
||||||
"!some_prefix.*some_suffix:matrix.org"
|
_regex("!some_prefix.*some_suffix:matrix.org")
|
||||||
)
|
)
|
||||||
self.event.room_id = "!some_prefixs0m3th1nGsome_suffix:matrix.org"
|
self.event.room_id = "!some_prefixs0m3th1nGsome_suffix:matrix.org"
|
||||||
self.assertTrue(self.service.is_interested(self.event))
|
self.assertTrue(self.service.is_interested(self.event))
|
||||||
|
|
||||||
def test_regex_room_id_no_match(self):
|
def test_regex_room_id_no_match(self):
|
||||||
self.service.namespaces[ApplicationService.NS_ROOMS].append(
|
self.service.namespaces[ApplicationService.NS_ROOMS].append(
|
||||||
"!some_prefix.*some_suffix:matrix.org"
|
_regex("!some_prefix.*some_suffix:matrix.org")
|
||||||
)
|
)
|
||||||
self.event.room_id = "!XqBunHwQIXUiqCaoxq:matrix.org"
|
self.event.room_id = "!XqBunHwQIXUiqCaoxq:matrix.org"
|
||||||
self.assertFalse(self.service.is_interested(self.event))
|
self.assertFalse(self.service.is_interested(self.event))
|
||||||
|
|
||||||
def test_regex_alias_match(self):
|
def test_regex_alias_match(self):
|
||||||
self.service.namespaces[ApplicationService.NS_ALIASES].append(
|
self.service.namespaces[ApplicationService.NS_ALIASES].append(
|
||||||
"#irc_.*:matrix.org"
|
_regex("#irc_.*:matrix.org")
|
||||||
)
|
)
|
||||||
self.assertTrue(self.service.is_interested(
|
self.assertTrue(self.service.is_interested(
|
||||||
self.event,
|
self.event,
|
||||||
|
@ -82,7 +89,7 @@ class ApplicationServiceTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_regex_alias_no_match(self):
|
def test_regex_alias_no_match(self):
|
||||||
self.service.namespaces[ApplicationService.NS_ALIASES].append(
|
self.service.namespaces[ApplicationService.NS_ALIASES].append(
|
||||||
"#irc_.*:matrix.org"
|
_regex("#irc_.*:matrix.org")
|
||||||
)
|
)
|
||||||
self.assertFalse(self.service.is_interested(
|
self.assertFalse(self.service.is_interested(
|
||||||
self.event,
|
self.event,
|
||||||
|
@ -91,10 +98,10 @@ class ApplicationServiceTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_regex_multiple_matches(self):
|
def test_regex_multiple_matches(self):
|
||||||
self.service.namespaces[ApplicationService.NS_ALIASES].append(
|
self.service.namespaces[ApplicationService.NS_ALIASES].append(
|
||||||
"#irc_.*:matrix.org"
|
_regex("#irc_.*:matrix.org")
|
||||||
)
|
)
|
||||||
self.service.namespaces[ApplicationService.NS_USERS].append(
|
self.service.namespaces[ApplicationService.NS_USERS].append(
|
||||||
"@irc_.*"
|
_regex("@irc_.*")
|
||||||
)
|
)
|
||||||
self.event.sender = "@irc_foobar:matrix.org"
|
self.event.sender = "@irc_foobar:matrix.org"
|
||||||
self.assertTrue(self.service.is_interested(
|
self.assertTrue(self.service.is_interested(
|
||||||
|
@ -104,10 +111,10 @@ class ApplicationServiceTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_restrict_to_rooms(self):
|
def test_restrict_to_rooms(self):
|
||||||
self.service.namespaces[ApplicationService.NS_ROOMS].append(
|
self.service.namespaces[ApplicationService.NS_ROOMS].append(
|
||||||
"!flibble_.*:matrix.org"
|
_regex("!flibble_.*:matrix.org")
|
||||||
)
|
)
|
||||||
self.service.namespaces[ApplicationService.NS_USERS].append(
|
self.service.namespaces[ApplicationService.NS_USERS].append(
|
||||||
"@irc_.*"
|
_regex("@irc_.*")
|
||||||
)
|
)
|
||||||
self.event.sender = "@irc_foobar:matrix.org"
|
self.event.sender = "@irc_foobar:matrix.org"
|
||||||
self.event.room_id = "!wibblewoo:matrix.org"
|
self.event.room_id = "!wibblewoo:matrix.org"
|
||||||
|
@ -118,10 +125,10 @@ class ApplicationServiceTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_restrict_to_aliases(self):
|
def test_restrict_to_aliases(self):
|
||||||
self.service.namespaces[ApplicationService.NS_ALIASES].append(
|
self.service.namespaces[ApplicationService.NS_ALIASES].append(
|
||||||
"#xmpp_.*:matrix.org"
|
_regex("#xmpp_.*:matrix.org")
|
||||||
)
|
)
|
||||||
self.service.namespaces[ApplicationService.NS_USERS].append(
|
self.service.namespaces[ApplicationService.NS_USERS].append(
|
||||||
"@irc_.*"
|
_regex("@irc_.*")
|
||||||
)
|
)
|
||||||
self.event.sender = "@irc_foobar:matrix.org"
|
self.event.sender = "@irc_foobar:matrix.org"
|
||||||
self.assertFalse(self.service.is_interested(
|
self.assertFalse(self.service.is_interested(
|
||||||
|
@ -132,10 +139,10 @@ class ApplicationServiceTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_restrict_to_senders(self):
|
def test_restrict_to_senders(self):
|
||||||
self.service.namespaces[ApplicationService.NS_ALIASES].append(
|
self.service.namespaces[ApplicationService.NS_ALIASES].append(
|
||||||
"#xmpp_.*:matrix.org"
|
_regex("#xmpp_.*:matrix.org")
|
||||||
)
|
)
|
||||||
self.service.namespaces[ApplicationService.NS_USERS].append(
|
self.service.namespaces[ApplicationService.NS_USERS].append(
|
||||||
"@irc_.*"
|
_regex("@irc_.*")
|
||||||
)
|
)
|
||||||
self.event.sender = "@xmpp_foobar:matrix.org"
|
self.event.sender = "@xmpp_foobar:matrix.org"
|
||||||
self.assertFalse(self.service.is_interested(
|
self.assertFalse(self.service.is_interested(
|
||||||
|
@ -146,7 +153,7 @@ class ApplicationServiceTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_member_list_match(self):
|
def test_member_list_match(self):
|
||||||
self.service.namespaces[ApplicationService.NS_USERS].append(
|
self.service.namespaces[ApplicationService.NS_USERS].append(
|
||||||
"@irc_.*"
|
_regex("@irc_.*")
|
||||||
)
|
)
|
||||||
join_list = [
|
join_list = [
|
||||||
Mock(
|
Mock(
|
||||||
|
|
|
@ -50,9 +50,15 @@ class ApplicationServiceStoreTestCase(unittest.TestCase):
|
||||||
def test_update_and_retrieval_of_service(self):
|
def test_update_and_retrieval_of_service(self):
|
||||||
url = "https://matrix.org/appservices/foobar"
|
url = "https://matrix.org/appservices/foobar"
|
||||||
hs_token = "hstok"
|
hs_token = "hstok"
|
||||||
user_regex = ["@foobar_.*:matrix.org"]
|
user_regex = [
|
||||||
alias_regex = ["#foobar_.*:matrix.org"]
|
{"regex": "@foobar_.*:matrix.org", "exclusive": True}
|
||||||
room_regex = []
|
]
|
||||||
|
alias_regex = [
|
||||||
|
{"regex": "#foobar_.*:matrix.org", "exclusive": True}
|
||||||
|
]
|
||||||
|
room_regex = [
|
||||||
|
|
||||||
|
]
|
||||||
service = ApplicationService(
|
service = ApplicationService(
|
||||||
url=url, hs_token=hs_token, token=self.as_token, namespaces={
|
url=url, hs_token=hs_token, token=self.as_token, namespaces={
|
||||||
ApplicationService.NS_USERS: user_regex,
|
ApplicationService.NS_USERS: user_regex,
|
||||||
|
|
Loading…
Reference in a new issue