diff options
author | David Baker <dave@matrix.org> | 2018-11-09 18:35:02 +0000 |
---|---|---|
committer | David Baker <dave@matrix.org> | 2018-11-09 18:35:02 +0000 |
commit | bca3b91c2dfeb63b43c3bfbb6700a38d4903f1eb (patch) | |
tree | ec18566349f9e3cae83699cffd2a714ae9dce932 /tests/unittest.py | |
parent | pep8 (diff) | |
parent | Merge pull request #4168 from matrix-org/babolivier/federation-client-content... (diff) | |
download | synapse-bca3b91c2dfeb63b43c3bfbb6700a38d4903f1eb.tar.xz |
Merge remote-tracking branch 'origin/develop' into dbkr/e2e_backup_versions_are_numbers
Diffstat (limited to 'tests/unittest.py')
-rw-r--r-- | tests/unittest.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/tests/unittest.py b/tests/unittest.py index a59291cc60..a9ce57da9a 100644 --- a/tests/unittest.py +++ b/tests/unittest.py @@ -146,6 +146,13 @@ def DEBUG(target): return target +def INFO(target): + """A decorator to set the .loglevel attribute to logging.INFO. + Can apply to either a TestCase or an individual test method.""" + target.loglevel = logging.INFO + return target + + class HomeserverTestCase(TestCase): """ A base TestCase that reduces boilerplate for HomeServer-using test cases. @@ -182,11 +189,11 @@ class HomeserverTestCase(TestCase): for servlet in self.servlets: servlet(self.hs, self.resource) - if hasattr(self, "user_id"): - from tests.rest.client.v1.utils import RestHelper + from tests.rest.client.v1.utils import RestHelper - self.helper = RestHelper(self.hs, self.resource, self.user_id) + self.helper = RestHelper(self.hs, self.resource, getattr(self, "user_id", None)) + if hasattr(self, "user_id"): if self.hijack_auth: def get_user_by_access_token(token=None, allow_guest=False): @@ -251,7 +258,13 @@ class HomeserverTestCase(TestCase): """ def make_request( - self, method, path, content=b"", access_token=None, request=SynapseRequest + self, + method, + path, + content=b"", + access_token=None, + request=SynapseRequest, + shorthand=True, ): """ Create a SynapseRequest at the path using the method and containing the @@ -263,6 +276,8 @@ class HomeserverTestCase(TestCase): escaped UTF-8 & spaces and such). content (bytes or dict): The body of the request. JSON-encoded, if a dict. + shorthand: Whether to try and be helpful and prefix the given URL + with the usual REST API path, if it doesn't contain it. Returns: A synapse.http.site.SynapseRequest. @@ -270,7 +285,9 @@ class HomeserverTestCase(TestCase): if isinstance(content, dict): content = json.dumps(content).encode('utf8') - return make_request(method, path, content, access_token, request) + return make_request( + self.reactor, method, path, content, access_token, request, shorthand + ) def render(self, request): """ @@ -373,5 +390,5 @@ class HomeserverTestCase(TestCase): self.render(request) self.assertEqual(channel.code, 200) - access_token = channel.json_body["access_token"].encode('ascii') + access_token = channel.json_body["access_token"] return access_token |