2
2
3
3
import random
4
4
import asyncio
5
+ from unittest .mock import Mock
5
6
6
7
import pytest
7
8
10
11
11
12
from sanic import Sanic , request , response , __version__ as SANIC_VERSION_RAW
12
13
from sanic .response import HTTPResponse
13
- from sanic .exceptions import abort
14
+ from sanic .exceptions import SanicException
14
15
15
16
SANIC_VERSION = tuple (map (int , SANIC_VERSION_RAW .split ("." )))
16
17
@@ -20,9 +21,9 @@ def app():
20
21
if SANIC_VERSION >= (20 , 12 ):
21
22
# Build (20.12.0) adds a feature where the instance is stored in an internal class
22
23
# registry for later retrieval, and so add register=False to disable that
23
- app = Sanic (__name__ , register = False )
24
+ app = Sanic ("Test" , register = False )
24
25
else :
25
- app = Sanic (__name__ )
26
+ app = Sanic ("Test" )
26
27
27
28
@app .route ("/message" )
28
29
def hi (request ):
@@ -90,7 +91,7 @@ def test_bad_request_not_captured(sentry_init, app, capture_events):
90
91
91
92
@app .route ("/" )
92
93
def index (request ):
93
- abort ( 400 )
94
+ raise SanicException ( "..." , status_code = 400 )
94
95
95
96
request , response = app .test_client .get ("/" )
96
97
assert response .status == 400
@@ -178,7 +179,12 @@ class MockAsyncStreamer:
178
179
def __init__ (self , request_body ):
179
180
self .request_body = request_body
180
181
self .iter = iter (self .request_body )
181
- self .response = b"success"
182
+
183
+ if SANIC_VERSION >= (21 , 12 ):
184
+ self .response = None
185
+ self .stage = Mock ()
186
+ else :
187
+ self .response = b"success"
182
188
183
189
def respond (self , response ):
184
190
responses .append (response )
0 commit comments