summary refs log tree commit diff
path: root/tests/unittest.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2020-12-02 15:21:00 +0000
committerRichard van der Hoff <richard@matrix.org>2020-12-02 15:21:00 +0000
commit693516e7566fdde677f5d836d45c44fbd8722ba9 (patch)
treef7a6a385c4461cdc3481b37816f0ccaee10ec7ec /tests/unittest.py
parentFix a regression when grandfathering SAML users. (#8855) (diff)
downloadsynapse-693516e7566fdde677f5d836d45c44fbd8722ba9.tar.xz
Add `create_resource_dict` method to HomeserverTestCase
Rather than using a single JsonResource, construct a resource tree, as we do in
the prod code, and allow testcases to add extra resources by overriding
`create_resource_dict`.
Diffstat (limited to '')
-rw-r--r--tests/unittest.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/tests/unittest.py b/tests/unittest.py
index a9d59e31f7..425b39b1d1 100644
--- a/tests/unittest.py
+++ b/tests/unittest.py
@@ -20,7 +20,7 @@ import hmac
 import inspect
 import logging
 import time
-from typing import Optional, Tuple, Type, TypeVar, Union, overload
+from typing import Dict, Optional, Tuple, Type, TypeVar, Union, overload
 
 from mock import Mock, patch
 
@@ -46,6 +46,7 @@ from synapse.logging.context import (
 )
 from synapse.server import HomeServer
 from synapse.types import UserID, create_requester
+from synapse.util.httpresourcetree import create_resource_tree
 from synapse.util.ratelimitutils import FederationRateLimiter
 
 from tests.server import FakeChannel, get_clock, make_request, setup_test_homeserver
@@ -320,15 +321,28 @@ class HomeserverTestCase(TestCase):
         """
         Create a the root resource for the test server.
 
-        The default implementation creates a JsonResource and calls each function in
-        `servlets` to register servletes against it
+        The default calls `self.create_resource_dict` and builds the resultant dict
+        into a tree.
         """
-        resource = JsonResource(self.hs)
+        root_resource = Resource()
+        create_resource_tree(self.create_resource_dict(), root_resource)
+        return root_resource
 
-        for servlet in self.servlets:
-            servlet(self.hs, resource)
+    def create_resource_dict(self) -> Dict[str, Resource]:
+        """Create a resource tree for the test server
+
+        A resource tree is a mapping from path to twisted.web.resource.
 
-        return resource
+        The default implementation creates a JsonResource and calls each function in
+        `servlets` to register servlets against it.
+        """
+        servlet_resource = JsonResource(self.hs)
+        for servlet in self.servlets:
+            servlet(self.hs, servlet_resource)
+        return {
+            "/_matrix/client": servlet_resource,
+            "/_synapse/admin": servlet_resource,
+        }
 
     def default_config(self):
         """