From 693f2a501490fb393f4a0f6fcc3f30cb6edb2370 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Thu, 28 Jan 2021 09:33:49 +0200 Subject: [PATCH 1/3] Adds testing manager to testing client property --- sanic/app.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sanic/app.py b/sanic/app.py index fe6d2708..992d8bcf 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -86,6 +86,7 @@ class Sanic: self.websocket_tasks: Set[Future] = set() self.named_request_middleware: Dict[str, MiddlewareType] = {} self.named_response_middleware: Dict[str, MiddlewareType] = {} + self._test_manager = None self._test_client = None self._asgi_client = None # Register alternative method names @@ -1035,6 +1036,8 @@ class Sanic: def test_client(self): if self._test_client: return self._test_client + elif self._test_manager: + return self._test_manager.test_client from sanic_testing.testing import SanicTestClient # type: ignore self._test_client = SanicTestClient(self) @@ -1044,6 +1047,8 @@ class Sanic: def asgi_client(self): if self._asgi_client: return self._asgi_client + elif self._test_manager: + return self._test_manager.test_client from sanic_testing.testing import SanicASGITestClient # type: ignore self._asgi_client = SanicASGITestClient(self) From 5abeae8f46f627f43e7c3864e594c8dbba867626 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Thu, 28 Jan 2021 09:34:13 +0200 Subject: [PATCH 2/3] squash --- sanic/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index 992d8bcf..753f477b 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -1033,7 +1033,7 @@ class Sanic: # -------------------------------------------------------------------- # @property - def test_client(self): + def test_client(self): # noqa if self._test_client: return self._test_client elif self._test_manager: @@ -1044,7 +1044,7 @@ class Sanic: return self._test_client @property - def asgi_client(self): + def asgi_client(self): # noqa if self._asgi_client: return self._asgi_client elif self._test_manager: From 83705b91c2fe59b5fdad2f6d040d3c382e26251d Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Thu, 28 Jan 2021 09:34:51 +0200 Subject: [PATCH 3/3] squash --- tests/test_static.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_static.py b/tests/test_static.py index 23ba05d7..78c114b9 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -1,5 +1,6 @@ import inspect import os + from pathlib import Path from time import gmtime, strftime @@ -93,8 +94,8 @@ def test_static_file_pathlib(app, static_file_directory, file_name): [b"test.file", b"decode me.txt", b"python.png"], ) def test_static_file_bytes(app, static_file_directory, file_name): - bsep = os.path.sep.encode('utf-8') - file_path = static_file_directory.encode('utf-8') + bsep + file_name + bsep = os.path.sep.encode("utf-8") + file_path = static_file_directory.encode("utf-8") + bsep + file_name app.static("/testing.file", file_path) request, response = app.test_client.get("/testing.file") assert response.status == 200