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


Python TestApp.do_request方法代码示例

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


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

示例1: test_content_type_with_no_body_should_pass

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import do_request [as 别名]
    def test_content_type_with_no_body_should_pass(self):
        app = TestApp(main({}))

        request = app.RequestClass.blank("/newsletter", method="POST", headers={"Content-Type": "application/json"})
        response = app.do_request(request, 200, True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json["body"], {})
开发者ID:mozilla-services,项目名称:cornice,代码行数:9,代码来源:test_validation.py

示例2: test_metrics_capture

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import do_request [as 别名]
    def test_metrics_capture(self):
        app = TestApp(self.config.make_wsgi_app())

        # Monkey-patch the app to make legitimate hawk-signed requests.
        user_id = 42
        auth_policy = self.config.registry.getUtility(IAuthenticationPolicy)
        req = Request.blank("http://localhost/")
        auth_token, auth_secret = auth_policy.encode_hawk_id(req, user_id)

        def new_do_request(req, *args, **kwds):
            hawkauthlib.sign_request(req, auth_token, auth_secret)
            return orig_do_request(req, *args, **kwds)

        orig_do_request = app.do_request
        app.do_request = new_do_request

        # Make a request that hits the database, capturing its logs.
        with testfixtures.LogCapture() as logs:
            app.get("/1.5/42/info/collections")

        # DB usage metrics should have been generated in a log message.
        for r in logs.records:
            if "syncstorage.storage.sql.db.execute" in r.__dict__:
                break
        else:
            assert False, "metrics were not collected"
开发者ID:jrconlin,项目名称:server-syncstorage,代码行数:28,代码来源:test_wsgiapp.py

示例3: test_content_type_missing_with_no_body_should_pass

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import do_request [as 别名]
    def test_content_type_missing_with_no_body_should_pass(self):
        app = TestApp(main({}))

        # requesting without a Content-Type header nor a body should
        # return a 200.
        request = app.RequestClass.blank('/newsletter', method='POST')
        response = app.do_request(request, 200, True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json['body'], {})
开发者ID:openprocurement,项目名称:cornice,代码行数:11,代码来源:test_validation.py

示例4: test_content_type_with_no_body_should_pass

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import do_request [as 别名]
    def test_content_type_with_no_body_should_pass(self):
        app = TestApp(main({}))

        request = app.RequestClass.blank('/newsletter', method='POST',
                                         headers={'Content-Type':
                                                  'application/json'})
        response = app.do_request(request, 200, True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json['body'], {})
开发者ID:openprocurement,项目名称:cornice,代码行数:11,代码来源:test_validation.py

示例5: test_content_type_missing

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import do_request [as 别名]
    def test_content_type_missing(self):
        # test that a Content-Type request headers is present
        app = TestApp(main({}))

        # requesting without a Content-Type header should return a 415 ...
        request = app.RequestClass.blank('/service5', method='POST')
        response = app.do_request(request, 415, True)

        # ... with an appropriate json error structure
        error_location = response.json['errors'][0]['location']
        error_name = response.json['errors'][0]['name']
        error_description = response.json['errors'][0]['description']
        self.assertEqual('header', error_location)
        self.assertEqual('Content-Type', error_name)
        self.assertTrue('application/json' in error_description)
开发者ID:alex-python,项目名称:cornice,代码行数:17,代码来源:test_validation.py

示例6: _make_test_app

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import do_request [as 别名]
    def _make_test_app(self):
        app = TestApp(self.config.make_wsgi_app())

        # Monkey-patch the app to make legitimate hawk-signed requests.
        user_id = 42
        auth_policy = self.config.registry.getUtility(IAuthenticationPolicy)
        req = Request.blank("http://localhost/")
        auth_token, auth_secret = auth_policy.encode_hawk_id(req, user_id)

        def new_do_request(req, *args, **kwds):
            hawkauthlib.sign_request(req, auth_token, auth_secret)
            return orig_do_request(req, *args, **kwds)

        orig_do_request = app.do_request
        app.do_request = new_do_request

        return app
开发者ID:return42,项目名称:server-syncstorage,代码行数:19,代码来源:test_wsgiapp.py

示例7: test_content_type_missing

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import do_request [as 别名]
    def test_content_type_missing(self):
        # test that a Content-Type request headers is present
        app = TestApp(main({}))

        # Requesting without a Content-Type header should
        # return "415 Unsupported Media Type" ...
        request = app.RequestClass.blank("/service5", method="POST", POST="some data")
        response = app.do_request(request, 415, True)
        self.assertEqual(response.status_code, 415)

        # ... with an appropriate json error structure.
        error_location = response.json["errors"][0]["location"]
        error_name = response.json["errors"][0]["name"]
        error_description = response.json["errors"][0]["description"]
        self.assertEqual("header", error_location)
        self.assertEqual("Content-Type", error_name)
        self.assertIn("application/json", error_description)
开发者ID:mozilla-services,项目名称:cornice,代码行数:19,代码来源:test_validation.py

示例8: test_content_type_missing

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import do_request [as 别名]
    def test_content_type_missing(self):
        # test that a Content-Type request headers is present
        app = TestApp(main({}))

        # Requesting without a Content-Type header should
        # return "415 Unsupported Media Type" ...
        request = app.RequestClass.blank('/service5', method='POST',
                                         POST="some data")
        response = app.do_request(request, 415, True)
        self.assertEqual(response.status_code, 415)

        # ... with an appropriate json error structure.
        error_location = response.json['errors'][0]['location']
        error_name = response.json['errors'][0]['name']
        error_description = response.json['errors'][0]['description']
        self.assertEqual('header', error_location)
        self.assertEqual('Content-Type', error_name)
        self.assertIn('application/json', error_description)
开发者ID:openprocurement,项目名称:cornice,代码行数:20,代码来源:test_validation.py

示例9: test_metrics_capture_for_batch_uploads

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import do_request [as 别名]
    def test_metrics_capture_for_batch_uploads(self):
        app = TestApp(self.config.make_wsgi_app())

        # Monkey-patch the app to make legitimate hawk-signed requests.
        user_id = 42
        auth_policy = self.config.registry.getUtility(IAuthenticationPolicy)
        req = Request.blank("http://localhost/")
        auth_token, auth_secret = auth_policy.encode_hawk_id(req, user_id)

        def new_do_request(req, *args, **kwds):
            hawkauthlib.sign_request(req, auth_token, auth_secret)
            return orig_do_request(req, *args, **kwds)

        orig_do_request = app.do_request
        app.do_request = new_do_request

        collection = "/1.5/42/storage/col1"

        with testfixtures.LogCapture() as logs:
            bso = {"id": "1", "payload": "x"}
            res = app.post_json(collection + "?batch=true", [bso])
            batch = res.json["batch"]

        for r in logs.records:
            if "syncstorage.storage.sql.append_items_to_batch" in r.__dict__:
                break
        else:
            assert False, "timer metrics were not emitted"

        with testfixtures.LogCapture() as logs:
            endpoint = collection + "?batch={0}&commit=true".format(batch)
            app.post_json(endpoint, [])

        # DB timing metrics should have been generated in a log message.
        for r in logs.records:
            if "syncstorage.storage.sql.apply_batch" in r.__dict__:
                break
        else:
            assert False, "timer metrics were not emitted"
开发者ID:return42,项目名称:server-syncstorage,代码行数:41,代码来源:test_wsgiapp.py

示例10: do_request

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import do_request [as 别名]
 def do_request(self, req, status, expect_errors):
     ret = TestApp.do_request(self, req, status, expect_errors)
     self.prune_empty_cookies()
     return ret
开发者ID:storborg,项目名称:maitai,代码行数:6,代码来源:utils.py


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