本文整理汇总了Python中pyramid.testing.DummyRequest.headers方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.headers方法的具体用法?Python DummyRequest.headers怎么用?Python DummyRequest.headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.headers方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bool_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers [as 别名]
def test_bool_json_body(self):
""" Pull bool params out of json body """
request = DummyRequest()
request.params = {}
request.headers = {'Content-Type': 'application/json'}
request.json_body = {'field': True}
field = param(request, 'field', type=bool)
self.assertTrue(field is True)
示例2: test_set_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers [as 别名]
def test_set_json_body(self):
""" Pull set params out of json body """
request = DummyRequest()
request.params = {}
request.json_body = {'field': set(['a', 'b'])}
request.headers = {'Content-Type': 'application/json'}
field = param(request, 'field', type=set)
self.assertEquals(field, set(['a', 'b']))
示例3: test_dict_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers [as 别名]
def test_dict_json_body(self):
""" Pull dict params out of json body """
request = DummyRequest()
request.params = {}
request.json_body = {'field': {'a': 'b'}}
request.headers = {'Content-Type': 'application/json'}
field = param(request, 'field', type=dict)
self.assertEquals(field, {'a': 'b'})
示例4: test_list_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers [as 别名]
def test_list_json_body(self):
""" Pull list params out of json body """
request = DummyRequest()
request.params = {}
request.json_body = {'field': [1, 2, 3]}
request.headers = {'Content-Type': 'application/json'}
field = param(request, 'field', type=list)
self.assertEquals(field, [1, 2, 3])
示例5: test_unicode_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers [as 别名]
def test_unicode_json_body(self):
""" Pull unicode params out of json body """
request = DummyRequest()
request.params = {}
request.json_body = {'field': 'myfield'}
request.headers = {'Content-Type': 'application/json'}
field = param(request, 'field')
self.assertEquals(field, 'myfield')
self.assertTrue(isinstance(field, six.text_type))
示例6: test_datetime_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers [as 别名]
def test_datetime_json_body(self):
""" Pull datetime params out of json body """
request = DummyRequest()
request.params = {}
now = int(time.time())
request.json_body = {'field': now}
request.headers = {'Content-Type': 'application/json'}
field = param(request, 'field', type=datetime)
self.assertEquals(calendar.timegm(field.utctimetuple()), now)
示例7: test_str_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers [as 别名]
def test_str_json_body(self):
""" Pull str params out of json body """
request = DummyRequest()
request.params = {}
request.json_body = {'field': 'myfield'}
request.headers = {'Content-Type': 'application/json'}
field = param(request, 'field', type=bytes)
self.assertEquals(field, b'myfield')
self.assertTrue(isinstance(field, six.binary_type))
示例8: test_kwargs_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers [as 别名]
def test_kwargs_json_body(self):
""" argify will pass extra kwargs in **kwargs in json body """
@argify
def req(request, f1, f2=None, **kwargs):
self.assertEquals(f1, 'bar')
self.assertEquals(kwargs, {'foobar': 'baz'})
context = object()
request = DummyRequest()
request.params = {}
request.headers = {'Content-Type': 'application/json'}
request.json_body = {
'f1': 'bar',
'foobar': 'baz',
}
req(context, request)