本文整理汇总了Python中pyramid.testing.DummyRequest.json_body方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.json_body方法的具体用法?Python DummyRequest.json_body怎么用?Python DummyRequest.json_body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.json_body方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bool_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [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_missing_param
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [as 别名]
def test_missing_param(self):
""" Raise HTTPBadRequest if param is missing """
request = DummyRequest()
request.params = {}
request.json_body = {}
myvar = object()
field = param(request, 'field', default=myvar)
self.assertTrue(field is myvar)
示例3: test_set_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [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']))
示例4: test_dict_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [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'})
示例5: test_list_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [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])
示例6: test_unicode_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [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))
示例7: test_datetime_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [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)
示例8: test_str_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [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))
示例9: test_default
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [as 别名]
def test_default(self):
""" Don't raise exception if keyword arg is missing """
@argify
def req(request, field='myfield'):
self.assertEquals(field, 'myfield')
context = object()
request = DummyRequest()
request.params = {}
request.json_body = {}
req(context, request)
示例10: test_missing
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [as 别名]
def test_missing(self):
""" Raise exception if positional arg is missing """
@argify
def req(request, field): # pragma: no cover
pass
context = object()
request = DummyRequest()
request.params = {}
request.json_body = {}
self.assertRaises(HTTPBadRequest, req, context, request)
示例11: test_kwargs_json_body
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [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)
示例12: test_pattern_clearer_JSON
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [as 别名]
def test_pattern_clearer_JSON(self):
"""
This method tests the JSON clearer view linked to the pattern input page. The expected result of this test
is for the correct JSON response to be retrieved.
"""
# Setup
request = DummyRequest(route='/pattern_clearer.json')
input = create_input_pattern()
request.body = json.dumps(input)
request.content_type = "application/json"
request.json_body = input
request.session["pattern"] = input
response = pattern_input_clearer_JSON(request)
# Assert that the pattern has been removed from the session
assert "pattern" not in response.keys()
示例13: test_pattern_input_receiver_JSON
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [as 别名]
def test_pattern_input_receiver_JSON(self):
"""
This method tests the JSON receiver view linked to the pattern input page. The expected result of this test
is for the correct JSON response to be retrieved.
"""
# Setup
request = DummyRequest(route='/pattern_receiver.json')
input = create_input_pattern()
request.body = json.dumps(input)
request.content_type = "application/json"
request.json_body = input
response = pattern_input_receiver_JSON(request)
# Assert that there is a pattern in the session.
assert request.session["pattern"] == input
responseDict = response
# Assert that the correct number of turns has been calculated and stored.
assert responseDict["turns"] == 53
# Assert that the correct run time has been calculated and stored.
assert responseDict["runtime"] == SLEEP_TIME * 53
示例14: test_default_param
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import json_body [as 别名]
def test_default_param(self):
""" Return default value if param is missing """
request = DummyRequest()
request.params = {}
request.json_body = {}
self.assertRaises(HTTPBadRequest, param, request, 'field')