本文整理汇总了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"], {})
示例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"
示例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'], {})
示例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'], {})
示例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)
示例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
示例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)
示例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)
示例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"
示例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