<s> import six <EOL> import os <EOL> from gunstar . testing import TestCase <EOL> from gunstar . app import Application <EOL> from gunstar . http import RequestHandler <EOL> PROJECT_PATH = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> class Handler ( RequestHandler ) : <EOL> def get ( self ) : <EOL> self . response . write ( '<STR_LIT>' . format ( self . request . method ) ) <EOL> def post ( self ) : <EOL> self . response . write ( '<STR_LIT>' . format ( self . request . method ) ) <EOL> def put ( self ) : <EOL> self . response . write ( '<STR_LIT>' . format ( self . request . method ) ) <EOL> def delete ( self ) : <EOL> self . response . write ( '<STR_LIT>' . format ( self . request . method ) ) <EOL> def options ( self ) : <EOL> self . response . write ( '<STR_LIT>' . format ( self . request . method ) ) <EOL> def head ( self ) : <EOL> self . response . write ( '<STR_LIT>' . format ( self . request . method ) ) <EOL> class SessionHandler ( RequestHandler ) : <EOL> def get ( self ) : <EOL> if self . session . get ( '<STR_LIT:name>' ) : <EOL> self . response . write ( '<STR_LIT>' . format ( <EOL> self . session . get ( '<STR_LIT:name>' ) ) <EOL> ) <EOL> else : <EOL> self . session . set ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> self . session . save ( ) <EOL> self . response . write ( '<STR_LIT>' ) <EOL> class SessionHandler2 ( RequestHandler ) : <EOL> def get ( self ) : <EOL> self . session . clear ( ) <EOL> self . session . save ( ) <EOL> self . response . write ( '<STR_LIT>' ) <EOL> class SessionHandler3 ( RequestHandler ) : <EOL> def get ( self ) : <EOL> self . render_template ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> routes = ( <EOL> ( '<STR_LIT:/>' , Handler , '<STR_LIT:index>' ) , <EOL> ( '<STR_LIT>' , SessionHandler , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , SessionHandler2 , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , SessionHandler3 , '<STR_LIT>' ) , <EOL> ) <EOL> class Settings ( object ) : <EOL> SECRET_KEY = '<STR_LIT>' <EOL> TEMPLATE_PATH = os . path . join ( PROJECT_PATH , '<STR_LIT>' ) <EOL> class ClientTest ( TestCase ) : <EOL> def get_app ( self ) : <EOL> return Application ( routes = routes , config = Settings ) <EOL> def test_get ( self ) : <EOL> resp = self . client . get ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT:GET>' ) <EOL> self . assertEqual ( resp . request_started . path_qs , '<STR_LIT:/>' ) <EOL> resp = self . client . get ( '<STR_LIT:/>' , data = { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT:GET>' ) <EOL> self . assertEqual ( resp . request_started . path_qs , '<STR_LIT>' ) <EOL> resp = self . client . get ( '<STR_LIT:/>' , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT:GET>' ) <EOL> self . assertEqual ( resp . request_started . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_head ( self ) : <EOL> resp = self . client . head ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path_qs , '<STR_LIT:/>' ) <EOL> resp = self . client . head ( '<STR_LIT:/>' , data = { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path_qs , '<STR_LIT>' ) <EOL> resp = self . client . head ( '<STR_LIT:/>' , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_post ( self ) : <EOL> resp = self . client . post ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT:POST>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> resp = self . client . post ( '<STR_LIT:/>' , data = { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT:POST>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . request_started . body , six . b ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> resp = self . client . post ( '<STR_LIT:/>' , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT:POST>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . request_started . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> resp = self . client . post ( '<STR_LIT:/>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT:POST>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_put ( self ) : <EOL> resp = self . client . put ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> resp = self . client . put ( '<STR_LIT:/>' , data = { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . request_started . body , six . b ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> resp = self . client . put ( '<STR_LIT:/>' , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . request_started . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> resp = self . client . put ( '<STR_LIT:/>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_delete ( self ) : <EOL> resp = self . client . delete ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> resp = self . client . delete ( '<STR_LIT:/>' , data = { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . request_started . body , six . b ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> resp = self . client . delete ( '<STR_LIT:/>' , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . request_started . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> resp = self . client . delete ( '<STR_LIT:/>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_options ( self ) : <EOL> resp = self . client . options ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , '<STR_LIT>' <EOL> ) <EOL> resp = self . client . options ( '<STR_LIT:/>' , data = { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . request_started . body , six . b ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , '<STR_LIT>' <EOL> ) <EOL> resp = self . client . options ( '<STR_LIT:/>' , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( resp . request_started . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , '<STR_LIT>' <EOL> ) <EOL> resp = self . client . options ( '<STR_LIT:/>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . request_started . method , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . request_started . path , '<STR_LIT:/>' ) <EOL> self . assertEqual ( <EOL> resp . request_started . content_type , '<STR_LIT>' <EOL> ) <EOL> def test_load_and_store_cookies ( self ) : <EOL> self . assertFalse ( self . client . cookies ) <EOL> resp = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . body , six . b ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( self . client . cookies ) <EOL> self . assertTrue ( '<STR_LIT>' in self . client . cookies ) <EOL> resp = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . body , six . b ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( self . client . cookies ) <EOL> self . assertTrue ( '<STR_LIT>' in self . client . cookies ) <EOL> resp = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . body , six . b ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( self . client . cookies ) <EOL> def test_template_and_context_in_response ( self ) : <EOL> resp = self . client . get ( '<STR_LIT>' ) <EOL> self . assertTrue ( resp . template ) <EOL> self . assertTrue ( resp . context ) <EOL> self . assertEqual ( resp . template , resp . text ) <EOL> self . assertEqual ( resp . context [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> resp = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFalse ( resp . template ) <EOL> self . assertFalse ( resp . context ) </s>
