12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
import re
15
+ from typing import Generator
15
16
from unittest .mock import Mock
16
17
17
18
from twisted .internet import defer
@@ -27,7 +28,7 @@ def _regex(regex: str, exclusive: bool = True) -> Namespace:
27
28
28
29
29
30
class ApplicationServiceTestCase (unittest .TestCase ):
30
- def setUp (self ):
31
+ def setUp (self ) -> None :
31
32
self .service = ApplicationService (
32
33
id = "unique_identifier" ,
33
34
sender = "@as:test" ,
@@ -46,7 +47,9 @@ def setUp(self):
46
47
self .store .get_local_users_in_room = simple_async_mock ([])
47
48
48
49
@defer .inlineCallbacks
49
- def test_regex_user_id_prefix_match (self ):
50
+ def test_regex_user_id_prefix_match (
51
+ self ,
52
+ ) -> Generator ["defer.Deferred[object]" , object , None ]:
50
53
self .service .namespaces [ApplicationService .NS_USERS ].append (_regex ("@irc_.*" ))
51
54
self .event .sender = "@irc_foobar:matrix.org"
52
55
self .assertTrue (
@@ -60,7 +63,9 @@ def test_regex_user_id_prefix_match(self):
60
63
)
61
64
62
65
@defer .inlineCallbacks
63
- def test_regex_user_id_prefix_no_match (self ):
66
+ def test_regex_user_id_prefix_no_match (
67
+ self ,
68
+ ) -> Generator ["defer.Deferred[object]" , object , None ]:
64
69
self .service .namespaces [ApplicationService .NS_USERS ].append (_regex ("@irc_.*" ))
65
70
self .event .sender = "@someone_else:matrix.org"
66
71
self .assertFalse (
@@ -74,7 +79,9 @@ def test_regex_user_id_prefix_no_match(self):
74
79
)
75
80
76
81
@defer .inlineCallbacks
77
- def test_regex_room_member_is_checked (self ):
82
+ def test_regex_room_member_is_checked (
83
+ self ,
84
+ ) -> Generator ["defer.Deferred[object]" , object , None ]:
78
85
self .service .namespaces [ApplicationService .NS_USERS ].append (_regex ("@irc_.*" ))
79
86
self .event .sender = "@someone_else:matrix.org"
80
87
self .event .type = "m.room.member"
@@ -90,7 +97,9 @@ def test_regex_room_member_is_checked(self):
90
97
)
91
98
92
99
@defer .inlineCallbacks
93
- def test_regex_room_id_match (self ):
100
+ def test_regex_room_id_match (
101
+ self ,
102
+ ) -> Generator ["defer.Deferred[object]" , object , None ]:
94
103
self .service .namespaces [ApplicationService .NS_ROOMS ].append (
95
104
_regex ("!some_prefix.*some_suffix:matrix.org" )
96
105
)
@@ -106,7 +115,9 @@ def test_regex_room_id_match(self):
106
115
)
107
116
108
117
@defer .inlineCallbacks
109
- def test_regex_room_id_no_match (self ):
118
+ def test_regex_room_id_no_match (
119
+ self ,
120
+ ) -> Generator ["defer.Deferred[object]" , object , None ]:
110
121
self .service .namespaces [ApplicationService .NS_ROOMS ].append (
111
122
_regex ("!some_prefix.*some_suffix:matrix.org" )
112
123
)
@@ -122,7 +133,9 @@ def test_regex_room_id_no_match(self):
122
133
)
123
134
124
135
@defer .inlineCallbacks
125
- def test_regex_alias_match (self ):
136
+ def test_regex_alias_match (
137
+ self ,
138
+ ) -> Generator ["defer.Deferred[object]" , object , None ]:
126
139
self .service .namespaces [ApplicationService .NS_ALIASES ].append (
127
140
_regex ("#irc_.*:matrix.org" )
128
141
)
@@ -140,44 +153,46 @@ def test_regex_alias_match(self):
140
153
)
141
154
)
142
155
143
- def test_non_exclusive_alias (self ):
156
+ def test_non_exclusive_alias (self ) -> None :
144
157
self .service .namespaces [ApplicationService .NS_ALIASES ].append (
145
158
_regex ("#irc_.*:matrix.org" , exclusive = False )
146
159
)
147
160
self .assertFalse (self .service .is_exclusive_alias ("#irc_foobar:matrix.org" ))
148
161
149
- def test_non_exclusive_room (self ):
162
+ def test_non_exclusive_room (self ) -> None :
150
163
self .service .namespaces [ApplicationService .NS_ROOMS ].append (
151
164
_regex ("!irc_.*:matrix.org" , exclusive = False )
152
165
)
153
166
self .assertFalse (self .service .is_exclusive_room ("!irc_foobar:matrix.org" ))
154
167
155
- def test_non_exclusive_user (self ):
168
+ def test_non_exclusive_user (self ) -> None :
156
169
self .service .namespaces [ApplicationService .NS_USERS ].append (
157
170
_regex ("@irc_.*:matrix.org" , exclusive = False )
158
171
)
159
172
self .assertFalse (self .service .is_exclusive_user ("@irc_foobar:matrix.org" ))
160
173
161
- def test_exclusive_alias (self ):
174
+ def test_exclusive_alias (self ) -> None :
162
175
self .service .namespaces [ApplicationService .NS_ALIASES ].append (
163
176
_regex ("#irc_.*:matrix.org" , exclusive = True )
164
177
)
165
178
self .assertTrue (self .service .is_exclusive_alias ("#irc_foobar:matrix.org" ))
166
179
167
- def test_exclusive_user (self ):
180
+ def test_exclusive_user (self ) -> None :
168
181
self .service .namespaces [ApplicationService .NS_USERS ].append (
169
182
_regex ("@irc_.*:matrix.org" , exclusive = True )
170
183
)
171
184
self .assertTrue (self .service .is_exclusive_user ("@irc_foobar:matrix.org" ))
172
185
173
- def test_exclusive_room (self ):
186
+ def test_exclusive_room (self ) -> None :
174
187
self .service .namespaces [ApplicationService .NS_ROOMS ].append (
175
188
_regex ("!irc_.*:matrix.org" , exclusive = True )
176
189
)
177
190
self .assertTrue (self .service .is_exclusive_room ("!irc_foobar:matrix.org" ))
178
191
179
192
@defer .inlineCallbacks
180
- def test_regex_alias_no_match (self ):
193
+ def test_regex_alias_no_match (
194
+ self ,
195
+ ) -> Generator ["defer.Deferred[object]" , object , None ]:
181
196
self .service .namespaces [ApplicationService .NS_ALIASES ].append (
182
197
_regex ("#irc_.*:matrix.org" )
183
198
)
@@ -196,7 +211,9 @@ def test_regex_alias_no_match(self):
196
211
)
197
212
198
213
@defer .inlineCallbacks
199
- def test_regex_multiple_matches (self ):
214
+ def test_regex_multiple_matches (
215
+ self ,
216
+ ) -> Generator ["defer.Deferred[object]" , object , None ]:
200
217
self .service .namespaces [ApplicationService .NS_ALIASES ].append (
201
218
_regex ("#irc_.*:matrix.org" )
202
219
)
@@ -215,7 +232,9 @@ def test_regex_multiple_matches(self):
215
232
)
216
233
217
234
@defer .inlineCallbacks
218
- def test_interested_in_self (self ):
235
+ def test_interested_in_self (
236
+ self ,
237
+ ) -> Generator ["defer.Deferred[object]" , object , None ]:
219
238
# make sure invites get through
220
239
self .service .sender = "@appservice:name"
221
240
self .service .namespaces [ApplicationService .NS_USERS ].append (_regex ("@irc_.*" ))
@@ -233,7 +252,9 @@ def test_interested_in_self(self):
233
252
)
234
253
235
254
@defer .inlineCallbacks
236
- def test_member_list_match (self ):
255
+ def test_member_list_match (
256
+ self ,
257
+ ) -> Generator ["defer.Deferred[object]" , object , None ]:
237
258
self .service .namespaces [ApplicationService .NS_USERS ].append (_regex ("@irc_.*" ))
238
259
# Note that @irc_fo:here is the AS user.
239
260
self .store .get_local_users_in_room = simple_async_mock (
0 commit comments