mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 22:14:55 -04:00
Test fixes for Python 3 (#3647)
This commit is contained in:
parent
bb89c84614
commit
2511f3f8a0
14 changed files with 71 additions and 52 deletions
|
@ -11,6 +11,7 @@ from twisted.python.failure import Failure
|
|||
from twisted.test.proto_helpers import MemoryReactorClock
|
||||
|
||||
from synapse.http.site import SynapseRequest
|
||||
from synapse.util import Clock
|
||||
|
||||
from tests.utils import setup_test_homeserver as _sth
|
||||
|
||||
|
@ -28,7 +29,13 @@ class FakeChannel(object):
|
|||
def json_body(self):
|
||||
if not self.result:
|
||||
raise Exception("No result yet.")
|
||||
return json.loads(self.result["body"])
|
||||
return json.loads(self.result["body"].decode('utf8'))
|
||||
|
||||
@property
|
||||
def code(self):
|
||||
if not self.result:
|
||||
raise Exception("No result yet.")
|
||||
return int(self.result["code"])
|
||||
|
||||
def writeHeaders(self, version, code, reason, headers):
|
||||
self.result["version"] = version
|
||||
|
@ -79,11 +86,16 @@ def make_request(method, path, content=b""):
|
|||
Make a web request using the given method and path, feed it the
|
||||
content, and return the Request and the Channel underneath.
|
||||
"""
|
||||
if not isinstance(method, bytes):
|
||||
method = method.encode('ascii')
|
||||
|
||||
if not isinstance(path, bytes):
|
||||
path = path.encode('ascii')
|
||||
|
||||
# Decorate it to be the full path
|
||||
if not path.startswith(b"/_matrix"):
|
||||
path = b"/_matrix/client/r0/" + path
|
||||
path = path.replace("//", "/")
|
||||
path = path.replace(b"//", b"/")
|
||||
|
||||
if isinstance(content, text_type):
|
||||
content = content.encode('utf8')
|
||||
|
@ -191,3 +203,9 @@ def setup_test_homeserver(*args, **kwargs):
|
|||
clock.threadpool = ThreadPool()
|
||||
pool.threadpool = ThreadPool()
|
||||
return d
|
||||
|
||||
|
||||
def get_clock():
|
||||
clock = ThreadedMemoryReactorClock()
|
||||
hs_clock = Clock(clock)
|
||||
return (clock, hs_clock)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue