From 410f86c960d4794c34ed79c211332484959587dc Mon Sep 17 00:00:00 2001 From: Anton Zhyrnyi Date: Tue, 14 Mar 2017 20:53:58 +0200 Subject: [PATCH] fix for docs&tests --- docs/sanic/class_based_views.md | 20 +++++++++++++++++++- tests/test_views.py | 6 +++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/sanic/class_based_views.md b/docs/sanic/class_based_views.md index 02b02140..ace8bf9c 100644 --- a/docs/sanic/class_based_views.md +++ b/docs/sanic/class_based_views.md @@ -48,6 +48,24 @@ app.add_route(SimpleView.as_view(), '/') ``` +You can also use `async` syntax. + +```python +from sanic import Sanic +from sanic.views import HTTPMethodView +from sanic.response import text + +app = Sanic('some_name') + +class SimpleAsyncView(HTTPMethodView): + + async def get(self, request): + return text('I am async get method') + +app.add_route(SimpleAsyncView.as_view(), '/') + +``` + ## URL parameters If you need any URL parameters, as discussed in the routing guide, include them @@ -128,4 +146,4 @@ view.add(['POST', 'PUT'], lambda request: text('I am a post/put method')) app.add_route(view, '/') ``` -Note: currently you cannot build a URL for a CompositionView using `url_for`. +Note: currently you cannot build a URL for a CompositionView using `url_for`. diff --git a/tests/test_views.py b/tests/test_views.py index 627a3b6c..40fc1adf 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -15,13 +15,13 @@ def test_methods(method): class DummyView(HTTPMethodView): - def get(self, request): + async def get(self, request): return text('', headers={'method': 'GET'}) def post(self, request): return text('', headers={'method': 'POST'}) - def put(self, request): + async def put(self, request): return text('', headers={'method': 'PUT'}) def head(self, request): @@ -30,7 +30,7 @@ def test_methods(method): def options(self, request): return text('', headers={'method': 'OPTIONS'}) - def patch(self, request): + async def patch(self, request): return text('', headers={'method': 'PATCH'}) def delete(self, request):