Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Rename create_test_json_resource to create_test_resource (#8759)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
richvdh authored Nov 16, 2020
1 parent ebc4054 commit 791d7cd
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 23 deletions.
1 change: 1 addition & 0 deletions changelog.d/8759.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor test utilities for injecting HTTP requests.
4 changes: 2 additions & 2 deletions tests/replication/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ def setUp(self):
lambda: self._handle_http_replication_attempt(self.hs, 8765),
)

def create_test_json_resource(self):
"""Overrides `HomeserverTestCase.create_test_json_resource`.
def create_test_resource(self):
"""Overrides `HomeserverTestCase.create_test_resource`.
"""
# We override this so that it automatically registers all the HTTP
# replication servlets, without having to explicitly do that in all
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/admin/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class VersionTestCase(unittest.HomeserverTestCase):
url = "/_synapse/admin/v1/server_version"

def create_test_json_resource(self):
def create_test_resource(self):
resource = JsonResource(self.hs)
VersionServlet(self.hs).register(resource)
return resource
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/key/v2/test_remote_key_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def make_homeserver(self, reactor, clock):
self.http_client = Mock()
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(
{"/_matrix/key/v2": KeyApiV2Resource(self.hs)}, root_resource=NoResource()
)
Expand Down
6 changes: 2 additions & 4 deletions tests/rest/test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@


class HealthCheckTests(unittest.HomeserverTestCase):
def setUp(self):
super().setUp()

def create_test_resource(self):
# replace the JsonResource with a HealthResource.
self.resource = HealthResource()
return HealthResource()

def test_health(self):
request, channel = self.make_request("GET", "/health", shorthand=False)
Expand Down
6 changes: 2 additions & 4 deletions tests/rest/test_well_known.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@


class WellKnownTests(unittest.HomeserverTestCase):
def setUp(self):
super().setUp()

def create_test_resource(self):
# replace the JsonResource with a WellKnownResource
self.resource = WellKnownResource(self.hs)
return WellKnownResource(self.hs)

def test_well_known(self):
self.hs.config.public_baseurl = "https://tesths"
Expand Down
18 changes: 7 additions & 11 deletions tests/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from twisted.python.failure import Failure
from twisted.python.threadpool import ThreadPool
from twisted.trial import unittest
from twisted.web.resource import Resource

from synapse.api.constants import EventTypes, Membership
from synapse.config.homeserver import HomeServerConfig
Expand Down Expand Up @@ -239,10 +240,8 @@ def setUp(self):
if not isinstance(self.hs, HomeServer):
raise Exception("A homeserver wasn't returned, but %r" % (self.hs,))

# Register the resources
self.resource = self.create_test_json_resource()

# create a site to wrap the resource.
# create the root resource, and a site to wrap it.
self.resource = self.create_test_resource()
self.site = SynapseSite(
logger_name="synapse.access.http.fake",
site_tag=self.hs.config.server.server_name,
Expand Down Expand Up @@ -323,15 +322,12 @@ def make_homeserver(self, reactor, clock):
hs = self.setup_test_homeserver()
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
The default implementation calls each function in `servlets` to do the
registration.
Create a the root resource for the test server.
Returns:
JsonResource:
The default implementation creates a JsonResource and calls each function in
`servlets` to register servletes against it
"""
resource = JsonResource(self.hs)

Expand Down

0 comments on commit 791d7cd

Please sign in to comment.