From 3a6396f754796282af231c22feeea09a33e4ae08 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Fri, 1 Jul 2022 00:27:27 +0300 Subject: [PATCH] Add ApplicationServerInfo to ReusableClient (#43) --- sanic_testing/reusable.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sanic_testing/reusable.py b/sanic_testing/reusable.py index 85cc367..12d10c5 100644 --- a/sanic_testing/reusable.py +++ b/sanic_testing/reusable.py @@ -1,10 +1,12 @@ import asyncio from functools import partial +from random import randint from types import SimpleNamespace from typing import Any, Dict, List, Optional, Tuple import httpx from sanic import Sanic +from sanic.application.state import ApplicationServerInfo from sanic.log import logger from sanic.request import Request from websockets.legacy.client import connect @@ -31,10 +33,22 @@ def __init__( Sanic.test_mode = True self.app = app self.host = host - self.port = port + self.port = port or randint(5000, 65000) self._loop = loop self.debug = False self._server = None + self.app.state.server_info.append( + ApplicationServerInfo( + settings={ + "version": "1.1", + "ssl": None, + "unix": None, + "sock": None, + "host": self.host, + "port": self.port, + } + ) + ) self._session = httpx.AsyncClient(verify=False, **client_kwargs) self._server_co = self.app.create_server(