@@ -157,6 +157,20 @@ class HomeserverTestCase(TestCase):
157
157
"""
158
158
A base TestCase that reduces boilerplate for HomeServer-using test cases.
159
159
160
+ Defines a setUp method which creates a mock reactor, and instantiates a homeserver
161
+ running on that reactor.
162
+
163
+ There are various hooks for modifying the way that the homeserver is instantiated:
164
+
165
+ * override make_homeserver, for example by making it pass different parameters into
166
+ setup_test_homeserver.
167
+
168
+ * override default_config, to return a modified configuration dictionary for use
169
+ by setup_test_homeserver.
170
+
171
+ * On a per-test basis, you can attach an 'extra_config' attribute, with a dictionary
172
+ containing additional configuration settings to be added to the basic config dict.
173
+
160
174
Attributes:
161
175
servlets (list[function]): List of servlet registration function.
162
176
user_id (str): The user ID to assume if auth is hijacked.
@@ -168,6 +182,13 @@ class HomeserverTestCase(TestCase):
168
182
hijack_auth = True
169
183
needs_threadpool = False
170
184
185
+ def __init__ (self , methodName , * args , ** kwargs ):
186
+ super ().__init__ (methodName , * args , ** kwargs )
187
+
188
+ # see if we have a custom config method for this test
189
+ method = getattr (self , methodName )
190
+ self ._extra_config = getattr (method , "extra_config" , None )
191
+
171
192
def setUp (self ):
172
193
"""
173
194
Set up the TestCase by calling the homeserver constructor, optionally
@@ -276,7 +297,14 @@ def default_config(self, name="test"):
276
297
Args:
277
298
name (str): The homeserver name/domain.
278
299
"""
279
- return default_config (name )
300
+ config = default_config (name )
301
+
302
+ # apply any additional config which was specified as an extra_config attribute
303
+ # on the test method..
304
+ if self ._extra_config is not None :
305
+ config .update (self ._extra_config )
306
+
307
+ return config
280
308
281
309
def prepare (self , reactor , clock , homeserver ):
282
310
"""
0 commit comments