summary refs log tree commit diff
path: root/tests/test_utils
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2020-12-15 20:56:10 +0000
committerGitHub <noreply@github.com>2020-12-15 20:56:10 +0000
commit01333681bc3db22541b49c194f5121a5415731c6 (patch)
tree981ef761d171545ec4d31f078bce355d819a4085 /tests/test_utils
parentFix handling of stream tokens for push. (#8943) (diff)
downloadsynapse-01333681bc3db22541b49c194f5121a5415731c6.tar.xz
Preparatory refactoring of the SamlHandlerTestCase (#8938)
* move simple_async_mock to test_utils

... so that it can be re-used

* Remove references to `SamlHandler._map_saml_response_to_user` from tests

This method is going away, so we can no longer use it as a test point. Instead,
factor out a higher-level method which takes a SAML object, and verify correct
behaviour by mocking out `AuthHandler.complete_sso_login`.

* changelog
Diffstat (limited to 'tests/test_utils')
-rw-r--r--tests/test_utils/__init__.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/test_utils/__init__.py b/tests/test_utils/__init__.py
index 6873d45eb6..43898d8142 100644
--- a/tests/test_utils/__init__.py
+++ b/tests/test_utils/__init__.py
@@ -22,6 +22,8 @@ import warnings
 from asyncio import Future
 from typing import Any, Awaitable, Callable, TypeVar
 
+from mock import Mock
+
 import attr
 
 from twisted.python.failure import Failure
@@ -87,6 +89,16 @@ def setup_awaitable_errors() -> Callable[[], None]:
     return cleanup
 
 
+def simple_async_mock(return_value=None, raises=None) -> Mock:
+    # AsyncMock is not available in python3.5, this mimics part of its behaviour
+    async def cb(*args, **kwargs):
+        if raises:
+            raise raises
+        return return_value
+
+    return Mock(side_effect=cb)
+
+
 @attr.s
 class FakeResponse:
     """A fake twisted.web.IResponse object