當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。