コード例 #1
0
    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)
コード例 #2
0
 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
コード例 #3
0
ファイル: test_routing.py プロジェクト: Epictetus/Shimehari
    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")
コード例 #4
0
ファイル: test_helpers.py プロジェクト: Epictetus/Shimehari
    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)
コード例 #5
0
ファイル: test_routing.py プロジェクト: Epictetus/Shimehari
    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")
コード例 #6
0
    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)