Revert "Remove utils.py"
This commit is contained in:
parent
7cf3d49f00
commit
32ddae943c
|
@ -57,3 +57,17 @@ def test_post_json_request_includes_data():
|
||||||
More information about
|
More information about
|
||||||
the available arguments to aiohttp can be found
|
the available arguments to aiohttp can be found
|
||||||
[in the documentation for ClientSession](https://aiohttp.readthedocs.io/en/stable/client_reference.html#client-session).
|
[in the documentation for ClientSession](https://aiohttp.readthedocs.io/en/stable/client_reference.html#client-session).
|
||||||
|
|
||||||
|
|
||||||
|
### Deprecated: `sanic_endpoint_test`
|
||||||
|
|
||||||
|
Prior to version 0.3.2, testing was provided through the `sanic_endpoint_test` method. This method will be deprecated in the next major version after 0.4.0; please use the `test_client` instead.
|
||||||
|
|
||||||
|
```
|
||||||
|
from sanic.utils import sanic_endpoint_test
|
||||||
|
|
||||||
|
def test_index_returns_200():
|
||||||
|
request, response = sanic_endpoint_test(app)
|
||||||
|
assert response.status == 200
|
||||||
|
```
|
||||||
|
|
||||||
|
|
17
sanic/utils.py
Normal file
17
sanic/utils.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
from sanic.testing import SanicTestClient
|
||||||
|
|
||||||
|
|
||||||
|
def sanic_endpoint_test(app, method='get', uri='/', gather_request=True,
|
||||||
|
debug=False, server_kwargs={},
|
||||||
|
*request_args, **request_kwargs):
|
||||||
|
warnings.warn(
|
||||||
|
"Use of sanic_endpoint_test will be deprecated in"
|
||||||
|
"the next major version after 0.4.0. Please use the `test_client` "
|
||||||
|
"available on the app object.", DeprecationWarning)
|
||||||
|
|
||||||
|
test_client = SanicTestClient(app)
|
||||||
|
return test_client._sanic_endpoint_test(
|
||||||
|
method, uri, gather_request, debug, server_kwargs,
|
||||||
|
*request_args, **request_kwargs)
|
|
@ -1,17 +1,16 @@
|
||||||
from sanic import Sanic
|
import sanic
|
||||||
|
from sanic.utils import sanic_endpoint_test
|
||||||
from sanic.response import text
|
from sanic.response import text
|
||||||
from threading import Event
|
from threading import Event
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
def test_create_task():
|
def test_create_task():
|
||||||
e = Event()
|
e = Event()
|
||||||
|
|
||||||
async def coro():
|
async def coro():
|
||||||
await asyncio.sleep(0.05)
|
await asyncio.sleep(0.05)
|
||||||
e.set()
|
e.set()
|
||||||
|
|
||||||
app = Sanic('test_create_task')
|
app = sanic.Sanic()
|
||||||
app.add_task(coro)
|
app.add_task(coro)
|
||||||
|
|
||||||
@app.route('/early')
|
@app.route('/early')
|
||||||
|
@ -23,8 +22,9 @@ def test_create_task():
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
return text(e.is_set())
|
return text(e.is_set())
|
||||||
|
|
||||||
request, response = app.test_client.get('/early')
|
|
||||||
|
request, response = sanic_endpoint_test(app, uri='/early')
|
||||||
assert response.body == b'False'
|
assert response.body == b'False'
|
||||||
|
|
||||||
request, response = app.test_client.get('/late')
|
request, response = sanic_endpoint_test(app, uri='/late')
|
||||||
assert response.body == b'True'
|
assert response.body == b'True'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user