<s> import os <EOL> import shimehari <EOL> import unittest <EOL> from werkzeug . routing import Rule <EOL> from shimehari . testsuite import ShimehariTestCase <EOL> from shimehari . configuration import ConfigManager , Config <EOL> from shimehari . routing import Router , Resource <EOL> from shimehari . controllers import ApplicationController <EOL> testConfig = Config ( '<STR_LIT>' , { '<STR_LIT>' : False , '<STR_LIT>' : '<STR_LIT:localhost>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> class TestController ( ApplicationController ) : <EOL> def index ( self , * args , ** kwargs ) : <EOL> return '<STR_LIT>' <EOL> class ShimehariAppTestCase ( ShimehariTestCase ) : <EOL> def testGotFirstRequest ( self ) : <EOL> ConfigManager . addConfig ( testConfig ) <EOL> app = shimehari . Shimehari ( __name__ ) <EOL> self . assertEqual ( app . gotFirstRequest , False ) <EOL> def returnHello ( * args , ** kwargs ) : <EOL> return '<STR_LIT>' <EOL> app . router = shimehari . Router ( [ Rule ( '<STR_LIT>' , endpoint = '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) ] ) <EOL> app . controllers [ '<STR_LIT>' ] = returnHello <EOL> c = app . testClient ( ) <EOL> c . get ( '<STR_LIT>' , content_type = '<STR_LIT>' ) <EOL> self . assert_ ( app . gotFirstRequest ) <EOL> def testLogger ( self ) : <EOL> ConfigManager . addConfig ( testConfig ) <EOL> app = shimehari . Shimehari ( __name__ ) <EOL> self . assert_ ( type ( app . logger ) ) <EOL> def testGetConfig ( self ) : <EOL> ConfigManager . addConfig ( testConfig ) <EOL> app = shimehari . Shimehari ( __name__ ) <EOL> self . assertEqual ( app . getConfig ( ) , testConfig ) <EOL> def testSetControllerFromRouter ( self ) : <EOL> ConfigManager . addConfig ( testConfig ) <EOL> app = shimehari . Shimehari ( __name__ ) <EOL> self . assertEqual ( app . controllers , { } ) <EOL> router = Router ( [ Resource ( TestController , root = True ) ] ) <EOL> app . setControllerFromRouter ( router ) <EOL> self . assertNotEqual ( app . controllers , { } ) <EOL> def testAddController ( self ) : <EOL> ConfigManager . addConfig ( testConfig ) <EOL> app = shimehari . Shimehari ( __name__ ) <EOL> self . assertEqual ( app . controllers , { } ) <EOL> app . addController ( TestController ) <EOL> self . assertNotEqual ( app . controllers , { } ) <EOL> def testAddRoute ( self ) : <EOL> ConfigManager . addConfig ( testConfig ) <EOL> app = shimehari . Shimehari ( __name__ ) <EOL> self . assertEqual ( app . controllers , { } ) <EOL> self . assertEqual ( app . router . _rules , [ ] ) <EOL> def index ( * args , ** kwargs ) : <EOL> return '<STR_LIT>' <EOL> app . addRoute ( '<STR_LIT:/>' , index ) <EOL> c = app . testClient ( ) <EOL> rv = c . get ( '<STR_LIT:/>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( rv . status_code , <NUM_LIT:200> ) <EOL> self . assert_ ( '<STR_LIT>' in rv . data ) <EOL> def testSetup ( self ) : <EOL> ConfigManager . removeConfig ( '<STR_LIT>' ) <EOL> ConfigManager . addConfig ( Config ( '<STR_LIT>' , { '<STR_LIT>' : False , '<STR_LIT>' : '<STR_LIT:localhost>' , '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> app = shimehari . Shimehari ( __name__ ) <EOL> app . appPath = os . path . join ( app . rootPath , '<STR_LIT>' ) <EOL> app . appFolder = '<STR_LIT>' <EOL> app . setupTemplater ( ) <EOL> app . setupBindController ( ) <EOL> app . setupBindRouter ( ) <EOL> self . assertNotEqual ( app . controllers , { } ) <EOL> self . assertNotEqual ( app . router . _rules , { } ) <EOL> pass <EOL> def testTryTriggerBeforeFirstRequest ( self ) : <EOL> ConfigManager . removeConfig ( '<STR_LIT>' ) <EOL> ConfigManager . addConfig ( testConfig ) <EOL> app = shimehari . Shimehari ( __name__ ) <EOL> app . testCnt = <NUM_LIT:0> <EOL> @ app . beforeFirstRequest <EOL> def doFirst ( ) : <EOL> app . testCnt = app . testCnt + <NUM_LIT:1> <EOL> return app . testCnt <EOL> def returnHello ( * args , ** kwargs ) : <EOL> return '<STR_LIT>' <EOL> app . router = shimehari . Router ( [ Rule ( '<STR_LIT>' , endpoint = '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) ] ) <EOL> app . controllers [ '<STR_LIT>' ] = returnHello <EOL> c = app . testClient ( ) <EOL> self . assertEqual ( app . testCnt , <NUM_LIT:0> ) <EOL> c . get ( '<STR_LIT>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( app . testCnt , <NUM_LIT:1> ) <EOL> c . get ( '<STR_LIT>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( app . testCnt , <NUM_LIT:1> ) <EOL> def testPreprocessRequest ( self ) : <EOL> ConfigManager . removeConfig ( '<STR_LIT>' ) <EOL> ConfigManager . addConfig ( testConfig ) <EOL> app = shimehari . Shimehari ( __name__ ) <EOL> app . testCnt = <NUM_LIT:0> <EOL> @ app . beforeRequest <EOL> def doRequest ( ) : <EOL> app . testCnt = app . testCnt + <NUM_LIT:1> <EOL> return app . testCnt <EOL> def returnHello ( * args , ** kwargs ) : <EOL> return '<STR_LIT>' <EOL> app . router = shimehari . Router ( [ Rule ( '<STR_LIT>' , endpoint = '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) ] ) <EOL> app . controllers [ '<STR_LIT>' ] = returnHello <EOL> c = app . testClient ( ) <EOL> self . assertEqual ( app . testCnt , <NUM_LIT:0> ) <EOL> c . get ( '<STR_LIT>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( app . testCnt , <NUM_LIT:1> ) <EOL> c . get ( '<STR_LIT>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( app . testCnt , <NUM_LIT:2> ) <EOL> def testProcessResponse ( self ) : <EOL> ConfigManager . removeConfig ( '<STR_LIT>' ) <EOL> ConfigManager . addConfig ( testConfig ) <EOL> app = shimehari . Shimehari ( __name__ ) <EOL> app . testCnt = <NUM_LIT:0> <EOL> @ app . afterRequest <EOL> def doRequest ( res ) : <EOL> app . testCnt = app . testCnt + <NUM_LIT:1> <EOL> return res <EOL> def returnHello ( * args , ** kwargs ) : <EOL> return '<STR_LIT>' <EOL> app . router = shimehari . Router ( [ Rule ( '<STR_LIT>' , endpoint = '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) ] ) <EOL> app . controllers [ '<STR_LIT>' ] = returnHello <EOL> c = app . testClient ( ) <EOL> self . assertEqual ( app . testCnt , <NUM_LIT:0> ) <EOL> c . get ( '<STR_LIT>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( app . testCnt , <NUM_LIT:1> ) <EOL> c . get ( '<STR_LIT>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( app . testCnt , <NUM_LIT:2> ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . makeSuite ( ShimehariAppTestCase ) ) <EOL> return suite </s>
