本文整理汇总了Python中twisted.web.test.test_web.DummyRequest.content方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.content方法的具体用法?Python DummyRequest.content怎么用?Python DummyRequest.content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.test.test_web.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.content方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_receipt_processing
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_receipt_processing(self):
"""it should be able to process an incoming XML receipt via HTTP"""
publisher = TestPublisher()
resource = transport.OperaReceiptResource(publisher)
request = DummyRequest('/api/v1/sms/opera/receipt.xml')
request.content = StringIO("""
<?xml version="1.0"?>
<!DOCTYPE receipts>
<receipts>
<receipt>
<msgid>26567958</msgid>
<reference>001efc31</reference>
<msisdn>+27123456789</msisdn>
<status>D</status>
<timestamp>20080831T15:59:24</timestamp>
<billed>NO</billed>
</receipt>
</receipts>
""".strip())
resource.render_POST(request)
self.assertEquals(publisher.queue.pop(), (Message(**{
'transport_name': 'Opera',
'transport_msg_id': '001efc31',
'transport_status': 'D', # OK / delivered, opera specific
'transport_delivered_at': datetime(2008, 8, 31, 15, 59, 24),
}), {
'routing_key': 'sms.receipt.opera'
})
)
示例2: request_generator
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def request_generator(url, method='GET', content=True, headers=True):
request = DummyRequest(url)
request.method = method
if content:
request.content = StringIO()
if headers:
request.requestHeaders = Headers()
return request
示例3: test_noSuchMethodNoId
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_noSuchMethodNoId(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "aaaa"}')
d = _render(self.srv, request)
def rendered(_):
self.assertEquals(request.written, [])
d.addCallback(rendered)
return d
示例4: test_notificationV2
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_notificationV2(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "sql", "jsonrpc": "2.0"}')
d = _render(self.srv, request)
def rendered(_):
self.assertEquals(request.written, [])
d.addCallback(rendered)
return d
示例5: test_sqlOkV1
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_sqlOkV1(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "sql", "id": 1}')
d = _render(self.srv, request)
def rendered(_):
expected = '{"error": null, "id": 1, "result": ['
self.assertTrue(request.written[0].startswith(expected))
d.addCallback(rendered)
return d
示例6: test_invalidIdCaseSensitive
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_invalidIdCaseSensitive(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "echo", "ID": "ABCD", ' +
'"params": ["AB"]}')
d = _render(self.srv, request)
def rendered(_):
self.assertEquals(request.written, [])
d.addCallback(rendered)
return d
示例7: test_malformed
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_malformed(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "sql", "id')
d = _render(self.srv, request)
def rendered(_):
expected = '{"jsonrpc": "2.0", "id": null, "error": ' + \
'{"message": "Parse error", "code": -32700}}'
self.assertEquals(request.written[0], expected)
d.addCallback(rendered)
return d
示例8: test_batchSingle
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_batchSingle(self):
json = '[{"method": "echo", "id": 1, "params": ["arg"]}]'
request = DummyRequest([''])
request.content = StringIO(json)
d = _render(self.srv, request)
def rendered(_):
expected = '[{"error": null, "id": 1, "result": "arg"}]'
self.assertEquals(request.written[0], expected)
d.addCallback(rendered)
return d
示例9: test_batchNotificationOnly
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_batchNotificationOnly(self):
json = '[{"method": "echo", "params": {"data": "arg"}}, ' + \
'{"method": "echo", "params": {"data": "arg"}}]'
request = DummyRequest([''])
request.content = StringIO(json)
d = _render(self.srv, request)
def rendered(_):
self.assertEquals(request.written, [])
d.addCallback(rendered)
return d
示例10: test_keywordsOkV2
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_keywordsOkV2(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "echo", "id": 1, "params": ' +
'{"data": "arg"}, "jsonrpc": "2.0"}')
d = _render(self.srv, request)
def rendered(_):
expected = '{"jsonrpc": "2.0", "id": 1, "result": "arg"}'
self.assertEquals(request.written[0], expected)
d.addCallback(rendered)
return d
示例11: test_caseSensitiveParamsV2
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_caseSensitiveParamsV2(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "echo", "id": "ABCD", ' +
'"params": ["AB"], "jsonrpc": "2.0"}')
d = _render(self.srv, request)
def rendered(_):
expected = '{"jsonrpc": "2.0", "id": "ABCD", "result": "AB"}'
self.assertEquals(request.written[0], expected)
d.addCallback(rendered)
return d
示例12: test_returnNone
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_returnNone(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "returnNone", "id": 1}')
d = _render(self.srv, request)
def rendered(_):
expected = '{"error": null, "id": 1, "result": null}'
self.assertEquals(request.written[0], expected)
d.addCallback(rendered)
return d
示例13: test_contentLength
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_contentLength(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "echo", "id": 1, ' +
'"params": ["ab"]}')
d = _render(self.srv, request)
def rendered(_):
self.assertEquals(str(len(request.written[0])),
request.outgoingHeaders['content-length'])
d.addCallback(rendered)
return d
示例14: test_contentType
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_contentType(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "echo", "id": 1, ' +
'"params": ["ab"]}')
d = _render(self.srv, request)
def rendered(_):
self.assertEquals(request.outgoingHeaders['content-type'],
'application/json')
d.addCallback(rendered)
return d
示例15: test_idStrV1
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import content [as 别名]
def test_idStrV1(self):
request = DummyRequest([''])
request.content = StringIO('{"method": "echo", "id": "abcd", ' +
'"params": ["ab"]}')
d = _render(self.srv, request)
def rendered(_):
expected = '{"error": null, "id": "abcd", "result": "ab"}'
self.assertEquals(request.written[0], expected)
d.addCallback(rendered)
return d