<s> from __future__ import unicode_literals <EOL> from nose . tools import eq_ , raises <EOL> from werkzeug . test import Client <EOL> from werkzeug . wrappers import BaseResponse <EOL> from clastic import Application <EOL> from clastic . middleware import Middleware , GetParamMiddleware <EOL> from common import hello_world , hello_world_ctx , RequestProvidesName <EOL> class RenderRaisesMiddleware ( Middleware ) : <EOL> def render ( self , next , context ) : <EOL> raise RuntimeError ( ) <EOL> def test_blank_req_provides ( ) : <EOL> req_provides_blank = RequestProvidesName ( ) <EOL> app = Application ( [ ( '<STR_LIT:/>' , hello_world ) ] , <EOL> middlewares = [ req_provides_blank ] ) <EOL> c = Client ( app , BaseResponse ) <EOL> resp = c . get ( '<STR_LIT:/>' ) <EOL> yield eq_ , resp . data , '<STR_LIT>' <EOL> resp = c . get ( '<STR_LIT>' ) <EOL> yield eq_ , resp . data , '<STR_LIT>' <EOL> def test_req_provides ( ) : <EOL> req_provides = RequestProvidesName ( '<STR_LIT>' ) <EOL> app = Application ( [ ( '<STR_LIT:/>' , hello_world ) ] , <EOL> middlewares = [ req_provides ] ) <EOL> c = Client ( app , BaseResponse ) <EOL> resp = c . get ( '<STR_LIT:/>' ) <EOL> yield eq_ , resp . data , '<STR_LIT>' <EOL> resp = c . get ( '<STR_LIT>' ) <EOL> yield eq_ , resp . data , '<STR_LIT>' <EOL> def test_get_param_mw ( ) : <EOL> get_name_mw = GetParamMiddleware ( [ '<STR_LIT:name>' , '<STR_LIT:date>' ] ) <EOL> app = Application ( [ ( '<STR_LIT:/>' , hello_world ) ] , <EOL> middlewares = [ get_name_mw ] ) <EOL> c = Client ( app , BaseResponse ) <EOL> resp = c . get ( '<STR_LIT:/>' ) <EOL> yield eq_ , resp . data , '<STR_LIT>' <EOL> resp = c . get ( '<STR_LIT>' ) <EOL> yield eq_ , resp . data , '<STR_LIT>' <EOL> def test_direct_no_render ( ) : <EOL> render_raises_mw = RenderRaisesMiddleware ( ) <EOL> app = Application ( [ ( '<STR_LIT:/>' , hello_world ) ] , <EOL> middlewares = [ render_raises_mw ] ) <EOL> c = Client ( app , BaseResponse ) <EOL> resp = c . get ( '<STR_LIT:/>' ) <EOL> yield eq_ , resp . data , '<STR_LIT>' <EOL> def test_render_raises ( ) : <EOL> render_raises_mw = RenderRaisesMiddleware ( ) <EOL> app = Application ( [ ( '<STR_LIT:/>' , hello_world_ctx ) ] , <EOL> middlewares = [ render_raises_mw ] ) <EOL> resp = Client ( app , BaseResponse ) . get ( '<STR_LIT:/>' ) <EOL> assert resp . status_code , <NUM_LIT> <EOL> @ raises ( NameError ) <EOL> def test_next_in_endpoint ( ) : <EOL> def nexter ( next , request ) : <EOL> return '<STR_LIT>' <EOL> Application ( [ ( '<STR_LIT:/>' , nexter ) ] ) </s>
