本文整理汇总了Python中werkzeug.wrappers.Request.from_values方法的典型用法代码示例。如果您正苦于以下问题:Python Request.from_values方法的具体用法?Python Request.from_values怎么用?Python Request.from_values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.wrappers.Request
的用法示例。
在下文中一共展示了Request.from_values方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_wrapper_support
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_wrapper_support(self):
req = Request.from_values()
resp = Response()
c = EncryptedCookie.load_cookie(req, crypter_or_keys_location=KEYS_DIR)
assert c.new
c['foo'] = 42
assert c.crypter is not None
c.save_cookie(resp)
req = Request.from_values(headers={
'Cookie': 'session="%s"' % parse_cookie(resp.headers['set-cookie'])['session']
})
c2 = EncryptedCookie.load_cookie(req, crypter_or_keys_location=KEYS_DIR)
assert not c2.new
assert c2 == c
示例2: test_wrapper_support
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_wrapper_support():
req = Request.from_values()
resp = Response()
c = SecureCookie.load_cookie(req, secret_key=b'foo')
assert c.new
c['foo'] = 42
assert c.secret_key == b'foo'
c.save_cookie(resp)
req = Request.from_values(headers={
'Cookie': 'session="%s"' % parse_cookie(resp.headers['set-cookie'])['session']
})
c2 = SecureCookie.load_cookie(req, secret_key=b'foo')
assert not c2.new
assert c2 == c
示例3: test_wrapper_support
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_wrapper_support(self):
req = Request.from_values()
resp = Response()
c = SecureCookie.load_cookie(req, secret_key="foo")
assert c.new
c["foo"] = 42
assert c.secret_key == "foo"
c.save_cookie(resp)
req = Request.from_values(
headers={"Cookie": 'session="%s"' % parse_cookie(resp.headers["set-cookie"])["session"]}
)
c2 = SecureCookie.load_cookie(req, secret_key="foo")
assert not c2.new
assert c2 == c
示例4: test_large_file
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_large_file(self):
data = 'x' * (1024 * 600)
req = Request.from_values(data={'foo': (StringIO(data), 'test.txt')},
method='POST')
# make sure we have a real file here, because we expect to be
# on the disk. > 1024 * 500
self.assert_(isinstance(req.files['foo'].stream, file))
示例5: test_parse_unicode
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_parse_unicode(self):
req = Request.from_values('/bubble?foo=barß')
parser = RequestParser()
parser.add_argument('foo')
args = parser.parse_args(req)
self.assertEqual(args['foo'], 'barß')
示例6: test_passing_arguments_object
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_passing_arguments_object(self):
req = Request.from_values('/bubble?foo=bar')
parser = RequestParser()
parser.add_argument(Argument('foo'))
args = parser.parse_args(req)
self.assertEqual(args['foo'], 'bar')
示例7: test_parse_required
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_parse_required(self):
with self.app.app_context():
req = Request.from_values('/bubble')
parser = RequestParser()
parser.add_argument('foo', required=True, location='values')
expected = {
'foo': 'Missing required parameter in the post body or the query string'
}
try:
parser.parse_args(req)
except BadRequest as e:
self.assertEqual(e.data['message'], 'Input payload validation failed')
self.assertEqual(e.data['errors'], expected)
parser = RequestParser()
parser.add_argument('bar', required=True, location=['values', 'cookies'])
expected = {
'bar': ("Missing required parameter in the post body or the query "
"string or the request's cookies")
}
try:
parser.parse_args(req)
except BadRequest as e:
self.assertEqual(e.data['message'], 'Input payload validation failed')
self.assertEqual(e.data['errors'], expected)
示例8: test_parse_lte
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_parse_lte(self):
req = Request.from_values('/bubble?foo<=bar')
parser = RequestParser()
parser.add_argument('foo', operators=['<='])
args = parser.parse_args(req)
self.assertEqual(args['foo'], 'bar')
示例9: test_parse_required
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_parse_required(self):
req = Request.from_values("/bubble")
parser = RequestParser()
parser.add_argument("foo", required=True)
self.assertRaises(exceptions.BadRequest, lambda: parser.parse_args(req))
示例10: test_parse_required
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_parse_required(self):
app = Flask(__name__)
with app.app_context():
req = Request.from_values("/bubble")
parser = RequestParser()
parser.add_argument("foo", required=True, location='values')
message = ''
try:
parser.parse_args(req)
except exceptions.BadRequest as e:
message = e.data['message']
self.assertEquals(message, ({'foo': 'Missing required parameter in '
'the post body or the query '
'string'}))
parser = RequestParser()
parser.add_argument("bar", required=True, location=['values', 'cookies'])
try:
parser.parse_args(req)
except exceptions.BadRequest as e:
message = e.data['message']
self.assertEquals(message, ({'bar': 'Missing required parameter in '
'the post body or the query '
'string or the request\'s '
'cookies'}))
示例11: test_parse_foo_operators_four_hunderd
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_parse_foo_operators_four_hunderd(self):
app = Flask(__name__)
with app.app_context():
parser = RequestParser()
parser.add_argument("foo", type=int),
self.assertRaises(exceptions.BadRequest, lambda: parser.parse_args(Request.from_values("/bubble?foo=bar")))
示例12: test_parse_unicode
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_parse_unicode(self):
req = Request.from_values("/bubble?foo=barß")
parser = RequestParser()
parser.add_argument("foo")
args = parser.parse_args(req)
self.assertEquals(args['foo'], u"barß")
示例13: test_passing_arguments_object
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_passing_arguments_object(self):
req = Request.from_values("/bubble?foo=bar")
parser = RequestParser()
parser.add_argument(Argument("foo", type=str))
args = parser.parse_args(req)
self.assertEquals(args['foo'], u"bar")
示例14: test_passing_arguments_object
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_passing_arguments_object(self, app):
req = Request.from_values('/bubble?foo=bar')
parser = RequestParser()
parser.add_argument(Argument('foo'))
args = parser.parse_args(req)
assert args['foo'] == 'bar'
示例15: test_parse_choices_sensitive
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import from_values [as 别名]
def test_parse_choices_sensitive(self):
req = Request.from_values("/bubble?foo=BAT")
parser = RequestParser()
parser.add_argument("foo", choices=["bat"], case_sensitive=True),
self.assertRaises(exceptions.BadRequest, lambda: parser.parse_args(req))