mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
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`.
This commit is contained in:
parent
8388384a64
commit
693516e756
@ -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
|
||||
|
||||
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.
|
||||
|
||||
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, resource)
|
||||
|
||||
return resource
|
||||
servlet(self.hs, servlet_resource)
|
||||
return {
|
||||
"/_matrix/client": servlet_resource,
|
||||
"/_synapse/admin": servlet_resource,
|
||||
}
|
||||
|
||||
def default_config(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user