def testStaticFile(self): ConfigManager.removeConfig('development') ConfigManager.addConfig(testConfig) app = shimehari.Shimehari(__name__) app.setStaticFolder('static') with app.testRequestContext(): rv = app.sendStaticFile('index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 12 * 60 * 60) rv = shimehari.sendFile(os.path.join(app.rootPath, 'static/index.html')) cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 12 * 60 * 60) app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600 with app.testRequestContext(): rv = app.sendStaticFile('index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 3600) rv = shimehari.sendFile(os.path.join(app.rootPath, 'static/index.html')) cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 3600) class StaticFileApp(shimehari.Shimehari): def getSendFileMaxAge(self, filename): return 10 app = StaticFileApp(__name__) app.setStaticFolder('static') with app.testRequestContext(): rv = app.sendStaticFile('index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 10) rv = shimehari.sendFile(os.path.join(app.rootPath, 'static/index.html')) cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 10)
def testSetup(self): # ConfigManager.addConfig(testConfig) ConfigManager.removeConfig('development') ConfigManager.addConfig(Config('development', {'AUTO_SETUP': False, 'SERVER_NAME': 'localhost', 'PREFERRED_URL_SCHEME': 'https'})) app = shimehari.Shimehari(__name__) app.appPath = os.path.join(app.rootPath, 'testApp') app.appFolder = 'shimehari.testsuite.testApp' app.setupTemplater() app.setupBindController() app.setupBindRouter() self.assertNotEqual(app.controllers, {}) self.assertNotEqual(app.router._rules, {}) pass
def testHasChild(self): ConfigManager.removeConfig("development") ConfigManager.addConfig(testConfig) def index(*args, **kwargs): return "index" def show(*args, **kwargs): return "show" router = RESTfulRouter( [Resource(IndexController, [Resource(ChildController)]), RESTfulRule("test", index, show)] ) app = shimehari.Shimehari(__name__) app.setupTemplater() app.router = router app.setControllerFromRouter(router) c = app.testClient() rv = c.get("/index/1", content_type="text/planetext") self.assertEqual(rv.data, "response show")
def testStaticFile(self): ConfigManager.removeConfig('development') ConfigManager.addConfig(testConfig) app = shimehari.Shimehari(__name__) app.staticFolder = 'static' with app.testRequestContext(): print app.appFolder print app.staticFolder rv = app.sendStaticFile('index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 12 * 60 * 60) rv = shimehari.sendFile( os.path.join(app.rootPath, 'static/index.html')) cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 12 * 60 * 60) app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600 with app.testRequestContext(): rv = app.sendStaticFile('index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 3600) rv = shimehari.sendFile( os.path.join(app.rootPath, 'static/index.html')) cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 3600) class StaticFileApp(shimehari.Shimehari): def getSendFileMaxAge(self, filename): return 10 app = StaticFileApp(__name__) app.staticFolder = 'static' with app.testRequestContext(): rv = app.sendStaticFile('index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 10) rv = shimehari.sendFile( os.path.join(app.rootPath, 'static/index.html')) cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assertEqual(cc.max_age, 10)
def testHasChild(self): ConfigManager.removeConfig('development') ConfigManager.addConfig(testConfig) def index(*args, **kwargs): return 'index' def show(*args, **kwargs): return 'show' router = RESTfulRouter([ Resource(IndexController, [Resource(ChildController)]), RESTfulRule('test', index, show), ]) app = shimehari.Shimehari(__name__) app.setupTemplater() app.router = router app.setControllerFromRouter(router) c = app.testClient() rv = c.get('/index/1', content_type='text/planetext') self.assertEqual(rv.data, "response show")
def testTryTriggerBeforeFirstRequest(self): ConfigManager.removeConfig('development') ConfigManager.addConfig(testConfig) app = shimehari.Shimehari(__name__) app.testCnt = 0 @app.beforeFirstRequest def doFirst(): app.testCnt = app.testCnt + 1 return app.testCnt def returnHello(*args, **kwargs): return 'Hello' app.router = shimehari.Router([Rule('/hell', endpoint='returnHello', methods=['POST'])]) app.controllers['returnHello'] = returnHello c = app.testClient() self.assertEqual(app.testCnt, 0) c.get('/hell', content_type='text/planetext') self.assertEqual(app.testCnt, 1) c.get('/hell', content_type='text/planetext') self.assertEqual(app.testCnt, 1)