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


Python werkzeug.test方法代码示例

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


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

示例1: test_dispatching

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_dispatching():
    tests = [
        ("/_app-metrics", 'GET', werkzeug.exceptions.NotFound),
        ("/_app-metrics/metrics", 'GET', wsgi.handle_metrics_list),
        ("/_app-metrics/metrics", 'POST', werkzeug.exceptions.MethodNotAllowed),
        ("/_app-metrics/metrics/test", 'GET', wsgi.handle_metric_show),
        ("/_app-metrics/metrics/test", 'PUT', wsgi.handle_metric_new),
        ("/_app-metrics/metrics/test", 'POST', wsgi.handle_metric_update),
        ("/_app-metrics/metrics/test", 'DELETE', wsgi.handle_metric_delete),
        ("/_app-metrics/metrics/test", 'OPTIONS', werkzeug.exceptions.MethodNotAllowed),
        ("/_app-metrics/metrics/test/sub", 'GET', werkzeug.routing.NotFound),
    ]

    mw = wsgi.AppMetricsMiddleware(None)

    for url, method, expected in tests:
        yield lambda url, method: check_dispatching(mw, url, method, expected), url, method 
开发者ID:avalente,项目名称:appmetrics,代码行数:19,代码来源:test_wsgi.py

示例2: test_dispatching_root

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_dispatching_root():
    tests = [
        ("/metrics", 'GET', wsgi.handle_metrics_list),
        ("/metrics", 'POST', werkzeug.exceptions.MethodNotAllowed),
        ("/metrics/test", 'GET', wsgi.handle_metric_show),
        ("/metrics/test", 'PUT', wsgi.handle_metric_new),
        ("/metrics/test", 'POST', wsgi.handle_metric_update),
        ("/metrics/test", 'DELETE', wsgi.handle_metric_delete),
        ("/metrics/test", 'OPTIONS', werkzeug.exceptions.MethodNotAllowed),
        ("/metrics/test/sub", 'GET', werkzeug.routing.NotFound),
        ]

    mw = wsgi.AppMetricsMiddleware(None, "")

    for url, method, expected in tests:
        yield lambda url, method: check_dispatching(mw, url, method, expected), url, method 
开发者ID:avalente,项目名称:appmetrics,代码行数:18,代码来源:test_wsgi.py

示例3: env

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def env(path, **kwargs):
    data = werkzeug.test.EnvironBuilder(path, environ_overrides=kwargs)
    return data.get_environ() 
开发者ID:avalente,项目名称:appmetrics,代码行数:5,代码来源:test_wsgi.py

示例4: req

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def req(body):
    data = werkzeug.test.EnvironBuilder(data=json.dumps(body), content_type="application/json")
    return data.get_request(cls=werkzeug.wrappers.Request) 
开发者ID:avalente,项目名称:appmetrics,代码行数:5,代码来源:test_wsgi.py

示例5: test_call_not_matching_2

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_call_not_matching_2(self):
        res = self.mw(env("/test"), self.start_response)
        assert_equal(res, self.app.return_value)
        assert_false(self.start_response.called)
        assert_equal(
            self.app.call_args_list,
            [mock.call(env("/test"), self.start_response)]) 
开发者ID:avalente,项目名称:appmetrics,代码行数:9,代码来源:test_wsgi.py

示例6: test_handle_metric_show

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_handle_metric_show(self, metric):
        metric().get.return_value = "this is a test"

        assert_equal(wsgi.handle_metric_show(mock.Mock(), "test"), '"this is a test"') 
开发者ID:avalente,项目名称:appmetrics,代码行数:6,代码来源:test_wsgi.py

示例7: test_handle_metric_show_not_found

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_handle_metric_show_not_found(self, metric):
        metric.side_effect = KeyError("key")

        with assert_raises(werkzeug.exceptions.NotFound) as exc:
            wsgi.handle_metric_show(mock.Mock(), "test")

        assert_equal(exc.exception.description, "No such metric: 'test'") 
开发者ID:avalente,项目名称:appmetrics,代码行数:9,代码来源:test_wsgi.py

示例8: test_handle_metric_delete

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_handle_metric_delete(self):
        with mock.patch.dict('appmetrics.metrics.REGISTRY', dict(test=mock.Mock())):
            res = wsgi.handle_metric_delete(mock.Mock(), "test")

            assert_equal(res, "deleted")
            assert_equal(metrics.REGISTRY, dict()) 
开发者ID:avalente,项目名称:appmetrics,代码行数:8,代码来源:test_wsgi.py

示例9: test_handle_metric_delete_not_found

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_handle_metric_delete_not_found(self):
        with mock.patch.dict('appmetrics.metrics.REGISTRY', dict(none="test")):
            res = wsgi.handle_metric_delete(mock.Mock(), "test")

            assert_equal(res, "not deleted")
            assert_equal(metrics.REGISTRY, dict(none="test")) 
开发者ID:avalente,项目名称:appmetrics,代码行数:8,代码来源:test_wsgi.py

示例10: test_handle_tag_show_no_expand

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_handle_tag_show_no_expand(self, mbt):
        mbt.return_value = "this is a test"
        metrics.new_histogram("test1")
        metrics.tag("test1", "tag1")

        res = wsgi.handle_tag_show(mock.Mock(args={"expand": 'true'}), "tag1")
        assert_equal(res, '"this is a test"') 
开发者ID:avalente,项目名称:appmetrics,代码行数:9,代码来源:test_wsgi.py

示例11: test_get_body

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_get_body(self):
        env = {'CONTENT_LENGTH': 6, 'CONTENT_TYPE': "application/json", 'wsgi.input': io.StringIO(u'"test" with garbage')}
        request = werkzeug.wrappers.Request(env)

        assert_equal(wsgi.get_body(request), 'test') 
开发者ID:avalente,项目名称:appmetrics,代码行数:7,代码来源:test_wsgi.py

示例12: test_handle_metric_new_missing_type

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_handle_metric_new_missing_type(self):
        with assert_raises(werkzeug.exceptions.BadRequest) as exc:
            wsgi.handle_metric_new(req(dict()), "test")
        assert_equal(exc.exception.description, "metric type not provided") 
开发者ID:avalente,项目名称:appmetrics,代码行数:6,代码来源:test_wsgi.py

示例13: test_handle_metric_new_invalid_type

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_handle_metric_new_invalid_type(self):
        with assert_raises(werkzeug.exceptions.BadRequest) as exc:
            wsgi.handle_metric_new(req(dict(type="xxx")), "test")
        assert_regexp_matches(exc.exception.description, "invalid metric type: .*'xxx'") 
开发者ID:avalente,项目名称:appmetrics,代码行数:6,代码来源:test_wsgi.py

示例14: test_handle_metric_new_app_error

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_handle_metric_new_app_error(self):
        wsgi.handle_metric_new(req(dict(type="gauge")), "test")

        with assert_raises(werkzeug.exceptions.BadRequest) as exc:
            wsgi.handle_metric_new(req(dict(type="gauge")), "test")
        assert_equal(exc.exception.description, "can't create metric gauge('test'): Metric test already exists of type Gauge") 
开发者ID:avalente,项目名称:appmetrics,代码行数:8,代码来源:test_wsgi.py

示例15: test_handle_metric_new_generic_error

# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import test [as 别名]
def test_handle_metric_new_generic_error(self):
        new_gauge = mock.Mock(side_effect=ValueError("an error"))

        with mock.patch.dict('appmetrics.wsgi.metrics.METRIC_TYPES', gauge=new_gauge):
            with assert_raises(werkzeug.exceptions.BadRequest) as exc:
                wsgi.handle_metric_new(req(dict(type="gauge")), "test")
            assert_equal(exc.exception.description, "can't create metric gauge('test')") 
开发者ID:avalente,项目名称:appmetrics,代码行数:9,代码来源:test_wsgi.py


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