summary refs log tree commit diff
path: root/tests/test_utils/__init__.py
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2020-12-02 20:06:53 +0000
committerGitHub <noreply@github.com>2020-12-02 20:06:53 +0000
commited5172852ae79dec341a81feeb1b8b99bb1875d6 (patch)
treedffeceef18b5dbfd0ed07755200ae06c297512a5 /tests/test_utils/__init__.py
parentremove unused FakeResponse (#8864) (diff)
parentnewsfile (diff)
downloadsynapse-ed5172852ae79dec341a81feeb1b8b99bb1875d6.tar.xz
Merge pull request #8858 from matrix-org/rav/sso_uia
UIA: offer only available auth flows
Diffstat (limited to 'tests/test_utils/__init__.py')
-rw-r--r--tests/test_utils/__init__.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_utils/__init__.py b/tests/test_utils/__init__.py

index d232b72264..6873d45eb6 100644 --- a/tests/test_utils/__init__.py +++ b/tests/test_utils/__init__.py
@@ -22,6 +22,11 @@ import warnings from asyncio import Future from typing import Any, Awaitable, Callable, TypeVar +import attr + +from twisted.python.failure import Failure +from twisted.web.client import ResponseDone + TV = TypeVar("TV") @@ -80,3 +85,25 @@ def setup_awaitable_errors() -> Callable[[], None]: sys.unraisablehook = unraisablehook # type: ignore return cleanup + + +@attr.s +class FakeResponse: + """A fake twisted.web.IResponse object + + there is a similar class at treq.test.test_response, but it lacks a `phrase` + attribute, and didn't support deliverBody until recently. + """ + + # HTTP response code + code = attr.ib(type=int) + + # HTTP response phrase (eg b'OK' for a 200) + phrase = attr.ib(type=bytes) + + # body of the response + body = attr.ib(type=bytes) + + def deliverBody(self, protocol): + protocol.dataReceived(self.body) + protocol.connectionLost(Failure(ResponseDone()))