mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Rename create_test_json_resource
to create_test_resource
(#8759)
The root resource isn't necessarily a JsonResource, so rename this method accordingly, and update a couple of test classes to use the method rather than directly manipulating self.resource.
This commit is contained in:
parent
ebc405446e
commit
791d7cd6f0
1
changelog.d/8759.misc
Normal file
1
changelog.d/8759.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Refactor test utilities for injecting HTTP requests.
|
@ -240,8 +240,8 @@ class BaseMultiWorkerStreamTestCase(unittest.HomeserverTestCase):
|
|||||||
lambda: self._handle_http_replication_attempt(self.hs, 8765),
|
lambda: self._handle_http_replication_attempt(self.hs, 8765),
|
||||||
)
|
)
|
||||||
|
|
||||||
def create_test_json_resource(self):
|
def create_test_resource(self):
|
||||||
"""Overrides `HomeserverTestCase.create_test_json_resource`.
|
"""Overrides `HomeserverTestCase.create_test_resource`.
|
||||||
"""
|
"""
|
||||||
# We override this so that it automatically registers all the HTTP
|
# We override this so that it automatically registers all the HTTP
|
||||||
# replication servlets, without having to explicitly do that in all
|
# replication servlets, without having to explicitly do that in all
|
||||||
|
@ -35,7 +35,7 @@ from tests import unittest
|
|||||||
class VersionTestCase(unittest.HomeserverTestCase):
|
class VersionTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_synapse/admin/v1/server_version"
|
url = "/_synapse/admin/v1/server_version"
|
||||||
|
|
||||||
def create_test_json_resource(self):
|
def create_test_resource(self):
|
||||||
resource = JsonResource(self.hs)
|
resource = JsonResource(self.hs)
|
||||||
VersionServlet(self.hs).register(resource)
|
VersionServlet(self.hs).register(resource)
|
||||||
return resource
|
return resource
|
||||||
|
@ -41,7 +41,7 @@ class BaseRemoteKeyResourceTestCase(unittest.HomeserverTestCase):
|
|||||||
self.http_client = Mock()
|
self.http_client = Mock()
|
||||||
return self.setup_test_homeserver(http_client=self.http_client)
|
return self.setup_test_homeserver(http_client=self.http_client)
|
||||||
|
|
||||||
def create_test_json_resource(self):
|
def create_test_resource(self):
|
||||||
return create_resource_tree(
|
return create_resource_tree(
|
||||||
{"/_matrix/key/v2": KeyApiV2Resource(self.hs)}, root_resource=NoResource()
|
{"/_matrix/key/v2": KeyApiV2Resource(self.hs)}, root_resource=NoResource()
|
||||||
)
|
)
|
||||||
|
@ -20,11 +20,9 @@ from tests import unittest
|
|||||||
|
|
||||||
|
|
||||||
class HealthCheckTests(unittest.HomeserverTestCase):
|
class HealthCheckTests(unittest.HomeserverTestCase):
|
||||||
def setUp(self):
|
def create_test_resource(self):
|
||||||
super().setUp()
|
|
||||||
|
|
||||||
# replace the JsonResource with a HealthResource.
|
# replace the JsonResource with a HealthResource.
|
||||||
self.resource = HealthResource()
|
return HealthResource()
|
||||||
|
|
||||||
def test_health(self):
|
def test_health(self):
|
||||||
request, channel = self.make_request("GET", "/health", shorthand=False)
|
request, channel = self.make_request("GET", "/health", shorthand=False)
|
||||||
|
@ -20,11 +20,9 @@ from tests import unittest
|
|||||||
|
|
||||||
|
|
||||||
class WellKnownTests(unittest.HomeserverTestCase):
|
class WellKnownTests(unittest.HomeserverTestCase):
|
||||||
def setUp(self):
|
def create_test_resource(self):
|
||||||
super().setUp()
|
|
||||||
|
|
||||||
# replace the JsonResource with a WellKnownResource
|
# replace the JsonResource with a WellKnownResource
|
||||||
self.resource = WellKnownResource(self.hs)
|
return WellKnownResource(self.hs)
|
||||||
|
|
||||||
def test_well_known(self):
|
def test_well_known(self):
|
||||||
self.hs.config.public_baseurl = "https://tesths"
|
self.hs.config.public_baseurl = "https://tesths"
|
||||||
|
@ -30,6 +30,7 @@ from twisted.internet.defer import Deferred, ensureDeferred, succeed
|
|||||||
from twisted.python.failure import Failure
|
from twisted.python.failure import Failure
|
||||||
from twisted.python.threadpool import ThreadPool
|
from twisted.python.threadpool import ThreadPool
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
from twisted.web.resource import Resource
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes, Membership
|
from synapse.api.constants import EventTypes, Membership
|
||||||
from synapse.config.homeserver import HomeServerConfig
|
from synapse.config.homeserver import HomeServerConfig
|
||||||
@ -239,10 +240,8 @@ class HomeserverTestCase(TestCase):
|
|||||||
if not isinstance(self.hs, HomeServer):
|
if not isinstance(self.hs, HomeServer):
|
||||||
raise Exception("A homeserver wasn't returned, but %r" % (self.hs,))
|
raise Exception("A homeserver wasn't returned, but %r" % (self.hs,))
|
||||||
|
|
||||||
# Register the resources
|
# create the root resource, and a site to wrap it.
|
||||||
self.resource = self.create_test_json_resource()
|
self.resource = self.create_test_resource()
|
||||||
|
|
||||||
# create a site to wrap the resource.
|
|
||||||
self.site = SynapseSite(
|
self.site = SynapseSite(
|
||||||
logger_name="synapse.access.http.fake",
|
logger_name="synapse.access.http.fake",
|
||||||
site_tag=self.hs.config.server.server_name,
|
site_tag=self.hs.config.server.server_name,
|
||||||
@ -323,15 +322,12 @@ class HomeserverTestCase(TestCase):
|
|||||||
hs = self.setup_test_homeserver()
|
hs = self.setup_test_homeserver()
|
||||||
return hs
|
return hs
|
||||||
|
|
||||||
def create_test_json_resource(self):
|
def create_test_resource(self) -> Resource:
|
||||||
"""
|
"""
|
||||||
Create a test JsonResource, with the relevant servlets registerd to it
|
Create a the root resource for the test server.
|
||||||
|
|
||||||
The default implementation calls each function in `servlets` to do the
|
The default implementation creates a JsonResource and calls each function in
|
||||||
registration.
|
`servlets` to register servletes against it
|
||||||
|
|
||||||
Returns:
|
|
||||||
JsonResource:
|
|
||||||
"""
|
"""
|
||||||
resource = JsonResource(self.hs)
|
resource = JsonResource(self.hs)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user