当前位置: 首页>>代码示例>>Python>>正文


Python ConfigManager.addConfig方法代码示例

本文整理汇总了Python中shimehari.configuration.ConfigManager.addConfig方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigManager.addConfig方法的具体用法?Python ConfigManager.addConfig怎么用?Python ConfigManager.addConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shimehari.configuration.ConfigManager的用法示例。


在下文中一共展示了ConfigManager.addConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testStaticFile

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    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)
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:35,代码来源:test_helpers.py

示例2: testSetControllerFromRouter

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
 def testSetControllerFromRouter(self):
     ConfigManager.addConfig(testConfig)
     app = shimehari.Shimehari(__name__)
     self.assertEqual(app.controllers, {})
     router = Router([Resource(TestController, root=True)])
     app.setControllerFromRouter(router)
     self.assertNotEqual(app.controllers, {})
开发者ID:Epictetus,项目名称:Shimehari,代码行数:9,代码来源:test_app.py

示例3: testJsoniFy

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    def testJsoniFy(self):
        d = dict(a=23, b=42, c=[1, 2, 3])
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        #hum
        def returnKwargs():
            return shimehari.jsonify(**d)

        def returnDict():
            return shimehari.jsonify(d)

        app.router = shimehari.Router([
            Rule('/kw', endpoint='returnKwargs', methods=['GET']),
            Rule('/dict', endpoint='returnDict', methods=['GET'])
        ])
        app.controllers['returnKwargs'] = returnKwargs
        app.controllers['returnDict'] = returnDict

        c = app.testClient()
        for url in '/kw', '/dict':
            rv = c.get(url)
            print rv.mimetype
            self.assertEqual(rv.mimetype, 'application/json')
            self.assertEqual(shimehari.json.loads(rv.data), d)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:27,代码来源:test_helpers.py

示例4: testTemplateEscaping

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
 def testTemplateEscaping(self):
     ConfigManager.addConfig(testConfig)
     app = shimehari.Shimehari(__name__)
     app.setupTemplater()
     render = shimehari.renderTemplateString
     with app.testRequestContext():
         rv = render('{{"</script>"|tojson|safe }}')
         self.assertEqual(rv, '"</script>"')
         rv = render('{{"<\0/script>"|tojson|safe }}')
         self.assertEqual(rv, '"<\\u0000/script>"')
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:12,代码来源:test_helpers.py

示例5: testGenerateURL

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    def testGenerateURL(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        def index(*args, **kwargs):
            return 'index'
        app.router = shimehari.Router([Rule('/', endpoint='index', methods=['GET'])])

        with app.appContext():
            rv = shimehari.urlFor('index')
            self.assertEqual(rv, 'https://localhost/')
开发者ID:Epictetus,项目名称:Shimehari,代码行数:13,代码来源:test_context.py

示例6: testJSONBadRequests

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    def testJSONBadRequests(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        def returnJSON(*args, **kwargs):
            return unicode(shimehari.request.json)
        app.router = shimehari.Router([Rule('/json', endpoint='returnJSON', methods=['POST'])])
        app.controllers['returnJSON'] = returnJSON
        c = app.testClient()
        rv = c.post('/json', data='malformed', content_type='application/json')
        self.assertEqual(rv.status_code, 400)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:13,代码来源:test_helpers.py

示例7: testGotFirstRequest

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    def testGotFirstRequest(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)
        self.assertEqual(app.gotFirstRequest, False)

        def returnHello(*args, **kwargs):
            return 'Hello'
        app.router = shimehari.Router([Rule('/hell', endpoint='returnHello', methods=['POST'])])
        app.controllers['returnHello'] = returnHello
        c = app.testClient()
        c.get('/hell', content_type='text/planetext')
        self.assert_(app.gotFirstRequest)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:14,代码来源:test_app.py

示例8: testJSONAttr

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    def testJSONAttr(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        def returnJSON(*args, **kwargs):
            return unicode(shimehari.request.json['a'] + shimehari.request.json['b'])
        app.router = shimehari.Router([Rule('/add', endpoint='returnJSON', methods=['POST'])])
        app.controllers['returnJSON'] = returnJSON

        c = app.testClient()
        rv = c.post('/add', data=shimehari.json.dumps({'a': 1, 'b': 2}), content_type='application/json')
        self.assertEqual(rv.data, '3')
开发者ID:Epictetus,项目名称:Shimehari,代码行数:14,代码来源:test_helpers.py

示例9: testSetup

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
 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
开发者ID:Epictetus,项目名称:Shimehari,代码行数:15,代码来源:test_app.py

示例10: testAddRoute

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    def testAddRoute(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)
        self.assertEqual(app.controllers, {})
        self.assertEqual(app.router._rules, [])

        def index(*args, **kwargs):
            return 'Sake nomitai.'
        app.addRoute('/', index)
        c = app.testClient()
        rv = c.get('/', content_type='text/html')
        self.assertEqual(rv.status_code, 200)
        self.assert_('Sake nomitai.' in rv.data)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:15,代码来源:test_app.py

示例11: jsonBodyEncoding

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    def jsonBodyEncoding(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        app.testing = True

        def returnJSON(*args, **kwargs):
            return shimehari.request.json
        app.router = shimehari.Router([Rule('/json', endpoint='returnJSON', methods=['GET'])])
        app.controllers['returnJSON'] = returnJSON
        c = app.testClient()
        resp = c.get('/', data=u"はひ".encode('iso-8859-15'), content_type='application/json; charset=iso-8859-15')
        self.assertEqual(resp.data, u'はひ'.encode('utf-8'))
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:15,代码来源:test_helpers.py

示例12: getConfig

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
 def getConfig(self):
     u"""現在アプリケーションに適用されているコンフィグを返します。"""
     configs = ConfigManager.getConfigs()
     try:
         # from .config import config
         configs = ConfigManager.getConfigs()
     except ImportError:
         pass
     if not configs:
         cfg = Config(self.currentEnv, self.defaultConfig)
         ConfigManager.addConfig(cfg)
         return cfg
     else:
         return configs[self.currentEnv]
开发者ID:Epictetus,项目名称:Shimehari,代码行数:16,代码来源:app.py

示例13: testJSONBadRequestsContentType

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    def testJSONBadRequestsContentType(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        @csrfExempt
        def returnJSON(*args, **kwargs):
            return unicode(shimehari.request.json)
        app.router = shimehari.Router([Rule('/json', endpoint='returnJSON', methods=['POST'])])
        app.controllers['returnJSON'] = returnJSON
        c = app.testClient()
        rv = c.post('/json', data='malformed', content_type='application/json')
        self.assertEqual(rv.status_code, 400)
        self.assertEqual(rv.mimetype, 'application/json')
        self.assert_('description' in shimehari.json.loads(rv.data))
        self.assert_('<p>' not in shimehari.json.loads(rv.data)['description'])
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:17,代码来源:test_helpers.py

示例14: testHasChild

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    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")
开发者ID:Epictetus,项目名称:Shimehari,代码行数:23,代码来源:test_routing.py

示例15: testTryTriggerBeforeFirstRequest

# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import addConfig [as 别名]
    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)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:24,代码来源:test_app.py


注:本文中的shimehari.configuration.ConfigManager.addConfig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。