Remove test client (#2009)
* Initial * remove testmanager * Resolve tests
This commit is contained in:
@@ -6,6 +6,8 @@ import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from sanic_testing import TestManager
|
||||
|
||||
from sanic import Sanic
|
||||
from sanic.router import RouteExists, Router
|
||||
|
||||
@@ -17,6 +19,11 @@ if sys.platform in ["win32", "cygwin"]:
|
||||
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
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
from sanic.testing import SanicASGITestClient
|
||||
|
||||
|
||||
def test_asgi_client_instantiation(app):
|
||||
assert isinstance(app.asgi_client, SanicASGITestClient)
|
||||
@@ -8,10 +8,11 @@ import httpcore
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from sanic_testing.testing import HOST, SanicTestClient
|
||||
|
||||
from sanic import Sanic, server
|
||||
from sanic.compat import OS_IS_WINDOWS
|
||||
from sanic.response import text
|
||||
from sanic.testing import HOST, SanicTestClient
|
||||
|
||||
|
||||
CONFIG_FOR_TESTS = {"KEEP_ALIVE_TIMEOUT": 2, "KEEP_ALIVE": True}
|
||||
|
||||
@@ -8,13 +8,14 @@ from io import StringIO
|
||||
|
||||
import pytest
|
||||
|
||||
from sanic_testing.testing import SanicTestClient
|
||||
|
||||
import sanic
|
||||
|
||||
from sanic import Sanic
|
||||
from sanic.compat import OS_IS_WINDOWS
|
||||
from sanic.log import LOGGING_CONFIG_DEFAULTS, logger
|
||||
from sanic.response import text
|
||||
from sanic.testing import SanicTestClient
|
||||
|
||||
|
||||
logging_format = """module: %(module)s; \
|
||||
@@ -34,6 +35,7 @@ def test_log(app):
|
||||
logging.basicConfig(
|
||||
format=logging_format, level=logging.DEBUG, stream=log_stream
|
||||
)
|
||||
logging.getLogger("asyncio").setLevel(logging.WARNING)
|
||||
log = logging.getLogger()
|
||||
rand_string = str(uuid.uuid4())
|
||||
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from sanic_testing.testing import PORT
|
||||
|
||||
from sanic.config import BASE_LOGO
|
||||
from sanic.testing import PORT
|
||||
|
||||
|
||||
try:
|
||||
import uvloop # noqa
|
||||
|
||||
ROW = 0
|
||||
except BaseException:
|
||||
ROW = 1
|
||||
|
||||
|
||||
def test_logo_base(app, caplog):
|
||||
@@ -28,8 +21,8 @@ def test_logo_base(app, caplog):
|
||||
loop.run_until_complete(_server.wait_closed())
|
||||
app.stop()
|
||||
|
||||
assert caplog.record_tuples[ROW][1] == logging.DEBUG
|
||||
assert caplog.record_tuples[ROW][2] == BASE_LOGO
|
||||
assert caplog.record_tuples[0][1] == logging.DEBUG
|
||||
assert caplog.record_tuples[0][2] == BASE_LOGO
|
||||
|
||||
|
||||
def test_logo_false(app, caplog):
|
||||
@@ -49,8 +42,8 @@ def test_logo_false(app, caplog):
|
||||
loop.run_until_complete(_server.wait_closed())
|
||||
app.stop()
|
||||
|
||||
banner, port = caplog.record_tuples[ROW][2].rsplit(":", 1)
|
||||
assert caplog.record_tuples[ROW][1] == logging.INFO
|
||||
banner, port = caplog.record_tuples[0][2].rsplit(":", 1)
|
||||
assert caplog.record_tuples[0][1] == logging.INFO
|
||||
assert banner == "Goin' Fast @ http://127.0.0.1"
|
||||
assert int(port) > 0
|
||||
|
||||
@@ -72,8 +65,8 @@ def test_logo_true(app, caplog):
|
||||
loop.run_until_complete(_server.wait_closed())
|
||||
app.stop()
|
||||
|
||||
assert caplog.record_tuples[ROW][1] == logging.DEBUG
|
||||
assert caplog.record_tuples[ROW][2] == BASE_LOGO
|
||||
assert caplog.record_tuples[0][1] == logging.DEBUG
|
||||
assert caplog.record_tuples[0][2] == BASE_LOGO
|
||||
|
||||
|
||||
def test_logo_custom(app, caplog):
|
||||
@@ -93,5 +86,5 @@ def test_logo_custom(app, caplog):
|
||||
loop.run_until_complete(_server.wait_closed())
|
||||
app.stop()
|
||||
|
||||
assert caplog.record_tuples[ROW][1] == logging.DEBUG
|
||||
assert caplog.record_tuples[ROW][2] == "My Custom Logo"
|
||||
assert caplog.record_tuples[0][1] == logging.DEBUG
|
||||
assert caplog.record_tuples[0][2] == "My Custom Logo"
|
||||
|
||||
@@ -5,9 +5,10 @@ import signal
|
||||
|
||||
import pytest
|
||||
|
||||
from sanic_testing.testing import HOST, PORT
|
||||
|
||||
from sanic import Blueprint
|
||||
from sanic.response import text
|
||||
from sanic.testing import HOST, PORT
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
|
||||
@@ -16,10 +16,10 @@ from httpcore._async.connection_pool import ResponseByteStream
|
||||
from httpcore._exceptions import LocalProtocolError, UnsupportedProtocol
|
||||
from httpcore._types import TimeoutDict
|
||||
from httpcore._utils import url_to_origin
|
||||
from sanic_testing.testing import SanicTestClient
|
||||
|
||||
from sanic import Sanic
|
||||
from sanic.response import text
|
||||
from sanic.testing import SanicTestClient
|
||||
|
||||
|
||||
class DelayableHTTPConnection(httpcore._async.connection.AsyncHTTPConnection):
|
||||
|
||||
@@ -8,11 +8,7 @@ from urllib.parse import urlparse
|
||||
|
||||
import pytest
|
||||
|
||||
from sanic import Blueprint, Sanic
|
||||
from sanic.exceptions import ServerError
|
||||
from sanic.request import DEFAULT_HTTP_CONTENT_TYPE, Request, RequestParameters
|
||||
from sanic.response import html, json, text
|
||||
from sanic.testing import (
|
||||
from sanic_testing.testing import (
|
||||
ASGI_BASE_URL,
|
||||
ASGI_HOST,
|
||||
ASGI_PORT,
|
||||
@@ -21,6 +17,11 @@ from sanic.testing import (
|
||||
SanicTestClient,
|
||||
)
|
||||
|
||||
from sanic import Blueprint, Sanic
|
||||
from sanic.exceptions import ServerError
|
||||
from sanic.request import DEFAULT_HTTP_CONTENT_TYPE, Request, RequestParameters
|
||||
from sanic.response import html, json, text
|
||||
|
||||
|
||||
# ------------------------------------------------------------ #
|
||||
# GET
|
||||
|
||||
@@ -12,6 +12,7 @@ from urllib.parse import unquote
|
||||
import pytest
|
||||
|
||||
from aiofiles import os as async_os
|
||||
from sanic_testing.testing import HOST, PORT
|
||||
|
||||
from sanic.response import (
|
||||
HTTPResponse,
|
||||
@@ -25,7 +26,6 @@ from sanic.response import (
|
||||
text,
|
||||
)
|
||||
from sanic.server import HttpProtocol
|
||||
from sanic.testing import HOST, PORT
|
||||
|
||||
|
||||
JSON_DATA = {"ok": True}
|
||||
|
||||
@@ -2,11 +2,12 @@ import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from sanic_testing.testing import SanicTestClient
|
||||
|
||||
from sanic import Sanic
|
||||
from sanic.constants import HTTP_METHODS
|
||||
from sanic.response import json, text
|
||||
from sanic.router import ParameterNameConflicts, RouteDoesNotExist, RouteExists
|
||||
from sanic.testing import SanicTestClient
|
||||
|
||||
|
||||
# ------------------------------------------------------------ #
|
||||
@@ -479,21 +480,21 @@ def test_websocket_route_with_subprotocols(app):
|
||||
results.append(ws.subprotocol)
|
||||
assert ws.subprotocol is not None
|
||||
|
||||
request, response = app.test_client.websocket("/ws", subprotocols=["bar"])
|
||||
_, response = SanicTestClient(app).websocket("/ws", subprotocols=["bar"])
|
||||
assert response.opened is True
|
||||
assert results == ["bar"]
|
||||
|
||||
request, response = app.test_client.websocket(
|
||||
_, response = SanicTestClient(app).websocket(
|
||||
"/ws", subprotocols=["bar", "foo"]
|
||||
)
|
||||
assert response.opened is True
|
||||
assert results == ["bar", "bar"]
|
||||
|
||||
request, response = app.test_client.websocket("/ws", subprotocols=["baz"])
|
||||
_, response = SanicTestClient(app).websocket("/ws", subprotocols=["baz"])
|
||||
assert response.opened is True
|
||||
assert results == ["bar", "bar", None]
|
||||
|
||||
request, response = app.test_client.websocket("/ws")
|
||||
_, response = SanicTestClient(app).websocket("/ws")
|
||||
assert response.opened is True
|
||||
assert results == ["bar", "bar", None, None]
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from socket import socket
|
||||
|
||||
import pytest
|
||||
|
||||
from sanic.testing import HOST, PORT
|
||||
from sanic_testing.testing import HOST, PORT
|
||||
|
||||
|
||||
AVAILABLE_LISTENERS = [
|
||||
|
||||
@@ -7,9 +7,10 @@ from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from sanic_testing.testing import HOST, PORT
|
||||
|
||||
from sanic.compat import ctrlc_workaround_for_windows
|
||||
from sanic.response import HTTPResponse
|
||||
from sanic.testing import HOST, PORT
|
||||
|
||||
|
||||
async def stop(app, loop):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from sanic_testing.testing import PORT, SanicTestClient
|
||||
|
||||
from sanic.response import json, text
|
||||
from sanic.testing import PORT, SanicTestClient
|
||||
|
||||
|
||||
# ------------------------------------------------------------ #
|
||||
|
||||
@@ -4,11 +4,12 @@ from urllib.parse import parse_qsl, urlsplit
|
||||
|
||||
import pytest as pytest
|
||||
|
||||
from sanic_testing.testing import HOST as test_host
|
||||
from sanic_testing.testing import PORT as test_port
|
||||
|
||||
from sanic.blueprints import Blueprint
|
||||
from sanic.exceptions import URLBuildError
|
||||
from sanic.response import text
|
||||
from sanic.testing import HOST as test_host
|
||||
from sanic.testing import PORT as test_port
|
||||
from sanic.views import HTTPMethodView
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import asyncio
|
||||
|
||||
from sanic_testing.testing import SanicTestClient
|
||||
|
||||
from sanic.blueprints import Blueprint
|
||||
|
||||
|
||||
@@ -48,14 +50,14 @@ def test_websocket_bp_route_name(app):
|
||||
|
||||
uri = app.url_for("test_bp.test_route")
|
||||
assert uri == "/bp/route"
|
||||
request, response = app.test_client.websocket(uri)
|
||||
request, response = SanicTestClient(app).websocket(uri)
|
||||
assert response.opened is True
|
||||
assert event.is_set()
|
||||
|
||||
event.clear()
|
||||
uri = app.url_for("test_bp.test_route2")
|
||||
assert uri == "/bp/route2"
|
||||
request, response = app.test_client.websocket(uri)
|
||||
request, response = SanicTestClient(app).websocket(uri)
|
||||
assert response.opened is True
|
||||
assert event.is_set()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user