@@ -14,127 +14,130 @@ async def on_load(config, recipes):
1414 config .LOAD = True
1515
1616
17- def test_on_before_load (req , config ):
17+ def test_on_before_load (client , config ):
1818 assert config .BEFORE_LOAD
1919
2020
21- def test_on_load (req , config ):
21+ def test_on_load (client , config ):
2222 assert config .LOAD
2323
2424
2525@pytest .mark .asyncio
26- async def test_on_request_can_return_content_only (app , req ):
26+ async def test_on_request_can_return_content_only (app , client ):
2727
2828 @app .listen ('request' )
29- async def on_request (request ):
29+ async def on_request (request , response ):
3030 assert request is not None
3131 assert request .path == '/default/mylayer/0/0/0/pbf'
32- return b'on_request'
32+ response .body = b'on_request'
33+ return True # Shortcut request processing pipeline.
3334
34- resp = await req ('/default/mylayer/0/0/0/pbf' )
35+ resp = await client . get ('/default/mylayer/0/0/0/pbf' )
3536 assert resp .status == b'200 OK'
3637 assert resp .body == b'on_request'
3738
3839
3940@pytest .mark .asyncio
40- async def test_on_request_can_return_tuple (app , req ):
41+ async def test_on_request_can_return_tuple (app , client ):
4142
4243 @app .listen ('request' )
43- async def on_request (request ):
44- return '' , 302 , {'Location' : 'http://somewhere-else.org' }
44+ async def on_request (request , response ):
45+ response .status = 302
46+ response .headers ['Location' ] = 'http://somewhere-else.org'
47+ return True # Shortcut request processing pipeline.
4548
46- resp = await req ('/default/mylayer/0/0/0/pbf' )
49+ resp = await client . get ('/default/mylayer/0/0/0/pbf' )
4750 assert resp .status == b'302 Found'
4851 assert resp .headers ['Location' ] == 'http://somewhere-else.org'
4952
5053
5154@pytest .mark .asyncio
52- async def test_on_response_can_override_response_body (app , req , fetchall ):
55+ async def test_on_response_can_override_response_body (app , client , fetchall ):
5356
5457 @app .listen ('response' )
5558 async def on_response (response , request ):
56- return b'on_response'
59+ response . body = b'on_response'
5760
5861 fetchall ([])
5962
60- resp = await req ('/default/mylayer/0/0/0/pbf' )
63+ resp = await client . get ('/default/mylayer/0/0/0/pbf' )
6164 assert resp .status == b'200 OK'
6265 assert resp .body == b'on_response'
6366
6467
6568@pytest .mark .asyncio
66- async def test_on_response_can_override_response_headers (app , req , fetchall ):
69+ async def test_on_response_can_override_headers (app , client , fetchall ):
6770
6871 @app .listen ('response' )
6972 async def on_response (response , request , ** kwargs ):
7073 response .headers ['Custom' ] = 'OK'
7174
7275 fetchall ([])
7376
74- resp = await req ('/default/mylayer/0/0/0/pbf' )
77+ resp = await client . get ('/default/mylayer/0/0/0/pbf' )
7578 assert resp .status == b'200 OK'
7679 assert resp .headers ['Custom' ] == 'OK'
7780
7881
7982@pytest .mark .asyncio
80- async def test_cors_add_cors_headers (req , fetchall ):
83+ async def test_cors_add_cors_headers (client , fetchall ):
8184 fetchall ([])
82- resp = await req ('/default/mylayer/0/0/0/pbf' )
85+ resp = await client . get ('/default/mylayer/0/0/0/pbf' )
8386 assert resp .status == b'200 OK'
8487 assert resp .headers ['Access-Control-Allow-Origin' ] == '*'
8588
8689
8790@pytest .mark .asyncio
88- async def test_cors_can_be_changed_in_config (app , req , fetchall , config ):
91+ async def test_cors_can_be_changed_in_config (app , client , fetchall , config ):
8992 config .CORS = 'http://mydomain.org'
9093 await app .startup ()
9194 fetchall ([])
92- resp = await req ('/default/mylayer/0/0/0/pbf' )
95+ resp = await client . get ('/default/mylayer/0/0/0/pbf' )
9396 assert resp .status == b'200 OK'
9497 assert resp .headers ['Access-Control-Allow-Origin' ] == 'http://mydomain.org'
9598
9699
97100@pytest .mark .asyncio
98- async def test_cors_can_be_cancelled_in_config (app , req , fetchall , config ):
101+ async def test_cors_can_be_cancelled_in_config (app , client , fetchall , config ):
99102 # cors has already been registered during app startup when loaded as
100103 # fixture. Reset this.
101104 app .hooks ['response' ] = []
102105 config .CORS = False
103106 config .LOADED = False
104107 await app .startup ()
105108 fetchall ([])
106- resp = await req ('/default/mylayer/0/0/0/pbf' )
109+ resp = await client . get ('/default/mylayer/0/0/0/pbf' )
107110 assert resp .status == b'200 OK'
108111 assert 'Access-Control-Allow-Origin' not in resp .headers
109112
110113
111114@pytest .mark .asyncio
112- async def test_cache_add_cache_control_headers (req , fetchall ):
115+ async def test_cache_add_cache_control_headers (client , fetchall ):
113116 fetchall ([])
114- resp = await req ('/default/mylayer/0/0/0/pbf' )
117+ resp = await client . get ('/default/mylayer/0/0/0/pbf' )
115118 assert resp .status == b'200 OK'
116- assert resp .headers ['Cache-Control' ] == 'max-age=3600'
119+ assert resp .headers ['Cache-Control' ] == 'public, max-age=3600'
117120
118121
119122@pytest .mark .asyncio
120- async def test_max_age_can_be_changed_in_config (app , req , fetchall , config ):
123+ async def test_max_age_can_be_changed_in_config (app , client , fetchall , config ):
121124 config .MAX_AGE = 86400
122125 await app .startup ()
123126 fetchall ([])
124- resp = await req ('/default/mylayer/0/0/0/pbf' )
127+ resp = await client . get ('/default/mylayer/0/0/0/pbf' )
125128 assert resp .status == b'200 OK'
126- assert resp .headers ['Cache-Control' ] == 'max-age=86400'
129+ assert resp .headers ['Cache-Control' ] == 'public, max-age=86400'
127130
128131
129132@pytest .mark .asyncio
130- async def test_cache_can_be_cancelled_in_config (app , req , fetchall , config ):
133+ async def test_cache_can_be_cancelled_in_config (app , client , fetchall , config ):
131134 # cors has already been registered during app startup when loaded as
132135 # fixture. Reset this.
133136 app .hooks ['response' ] = []
134137 config .MAX_AGE = False
135138 config .LOADED = False
136139 await app .startup ()
137140 fetchall ([])
138- resp = await req ('/default/mylayer/0/0/0/pbf' )
141+ resp = await client . get ('/default/mylayer/0/0/0/pbf' )
139142 assert resp .status == b'200 OK'
140143 assert 'Cache-Control' not in resp .headers
0 commit comments