Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
serve_multiple,
)
from sanic.static import register as static_register
from sanic.testing import SanicASGITestClient, SanicTestClient
from sanic.views import CompositionView
from sanic.websocket import ConnectionClosed, WebSocketProtocol

Expand Down Expand Up @@ -87,6 +86,8 @@ def __init__(
self.websocket_tasks: Set[Future] = set()
self.named_request_middleware: Dict[str, MiddlewareType] = {}
self.named_response_middleware: Dict[str, MiddlewareType] = {}
self._test_client = None
self._asgi_client = None
# Register alternative method names
self.go_fast = self.run

Expand Down Expand Up @@ -1032,11 +1033,21 @@ async def handle_request(self, request):

@property
def test_client(self):
return SanicTestClient(self)
if self._test_client:
return self._test_client
from sanic_testing.testing import SanicTestClient # type: ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from sanic_testing.testing import SanicTestClient # type: ignore
elif hasattr(self, "_test_manager"):
return self._test_manager.test_client # type: ignore
from sanic_testing.testing import SanicTestClient # type: ignore

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add that in another PR. I want to get this one merged.


self._test_client = SanicTestClient(self)
return self._test_client

@property
def asgi_client(self):
return SanicASGITestClient(self)
if self._asgi_client:
return self._asgi_client
from sanic_testing.testing import SanicASGITestClient # type: ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from sanic_testing.testing import SanicASGITestClient # type: ignore
elif hasattr(self, "_test_manager"):
return self._test_manager.asgi_client # type: ignore
from sanic_testing.testing import SanicASGITestClient # type: ignore


self._asgi_client = SanicASGITestClient(self)
return self._asgi_client

# -------------------------------------------------------------------- #
# Execution
Expand Down Expand Up @@ -1439,7 +1450,7 @@ async def _websocket_handler(
pass
finally:
self.websocket_tasks.remove(fut)
await ws.close()
await ws.close()

# -------------------------------------------------------------------- #
# ASGI
Expand Down
284 changes: 0 additions & 284 deletions sanic/testing.py

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ def open_local(paths, mode="r", encoding="utf8"):
"aiofiles>=0.6.0",
"websockets>=8.1,<9.0",
"multidict>=5.0,<6.0",
"httpx==0.15.4",
]

tests_require = [
"sanic-testing",
"pytest==5.2.1",
"multidict>=5.0,<6.0",
"gunicorn==20.0.4",
"pytest-cov",
"httpcore==0.11.*",
"beautifulsoup4",
uvloop,
ujson,
Expand Down
13 changes: 11 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import pytest

from sanic_testing import TestManager

from sanic import Sanic
from sanic.router import RouteExists, Router

Expand All @@ -17,6 +19,11 @@
collect_ignore = ["test_worker.py"]


@pytest.fixture
def caplog(caplog):
yield caplog


async def _handler(request):
"""
Dummy placeholder method used for route resolver when creating a new
Expand Down Expand Up @@ -127,6 +134,8 @@ def url_param_generator():
return TYPE_TO_GENERATOR_MAP


@pytest.fixture
@pytest.fixture(scope="function")
def app(request):
return Sanic(request.node.name)
app = Sanic(request.node.name)
# TestManager(app)
return app
3 changes: 1 addition & 2 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def transport(message_stack, receive, send):


@pytest.fixture
# @pytest.mark.asyncio
def protocol(transport, loop):
def protocol(transport):
return transport.get_protocol()


Expand Down
5 changes: 0 additions & 5 deletions tests/test_asgi_client.py

This file was deleted.

Loading