本文整理汇总了Python中twisted.web.test.requesthelper.DummyRequest.content方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.content方法的具体用法?Python DummyRequest.content怎么用?Python DummyRequest.content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.test.requesthelper.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.content方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_contemporaneous_requests
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_contemporaneous_requests(self):
'''
We're going to create two request-response cycles here:
Cycle 1 will begin.
Cycle 2 will begin.
Cycle 2 will return.
Cycle 1 will return.
This way, we can prove that the crosstown_traffic created
by cycle 1 is not resolved by the return of cycle 2.
'''
tp = ThreadPool(maxthreads=20)
tp.start()
self.addCleanup(tp.stop)
log.debug("\n\nStarting the two stream stuff.")
request1 = DummyRequest('r1')
request1.isSecure = lambda: False
request1.content = "Nothing really here."
request1.headers['llamas'] = 'dingo'
nameSpace.test_case = self
hr = HendrixWSGIResource(reactor, tp, wsgi_application)
d1 = deferToThreadPool(reactor, tp, hr.render, request1)
request2 = DummyRequest('r2')
request2.isSecure = lambda: False
request2.content = "Nothing really here."
request2.headers['llamas'] = 'dingo'
d2 = deferToThreadPool(reactor, tp, hr.render, request2)
def woah_stop(failure):
nameSpace.async_task_was_done.put_nowait(False)
nameSpace.second_cycle_complete.put_nowait(False)
nameSpace.ready_to_proceed_with_second_cycle.put_nowait(False)
d1.addErrback(woah_stop)
d2.addErrback(woah_stop)
combo_deferred = gatherResults([d1, d2])
def wait_for_queue_resolution():
nameSpace.async_task_was_done.get(True, 3)
combo_deferred.addCallback(
lambda _: deferToThreadPool(reactor, tp, wait_for_queue_resolution)
)
combo_deferred.addCallback(
lambda _: self.assertTrue(nameSpace.async_task_was_run)
)
return combo_deferred
示例2: test_render_exceptions
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_render_exceptions(self):
"""
`SmsNotificationService.render_POST` logs any exceptions that occur
during processing and writes a SOAP fault back to the request.
"""
def process(*a, **kw):
raise ValueError('What is this')
service = SmsNotificationService(None, None)
service.process = process
request = DummyRequest([])
request.content = StringIO(tostring(soap_envelope('hello')))
d = request.notifyFinish()
service.render_POST(request)
self.successResultOf(d)
self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
failures = self.flushLoggedErrors(ValueError)
self.assertEqual(1, len(failures))
self.assertEqual(
{str(SOAP_ENV.Envelope): {
str(SOAP_ENV.Body): {
str(SOAP_ENV.Fault): {
'faultcode': 'soapenv:Server',
'faultstring': 'What is this'}}}},
element_to_dict(fromstring(''.join(request.written))))
示例3: test_render_soap_fault
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_render_soap_fault(self):
"""
`SmsNotificationService.render_POST` logs any exceptions that occur
during processing and writes a SOAP fault back to the request. If the
logged exception is a `SoapFault` its ``to_element`` method is invoked
to serialize the fault.
"""
service = SmsNotificationService(None, None)
service.process = lambda *a, **kw: L.done()
request = DummyRequest([])
request.content = StringIO(tostring(L.hello()))
d = request.notifyFinish()
service.render_POST(request)
self.successResultOf(d)
self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
failures = self.flushLoggedErrors(SoapFault)
self.assertEqual(1, len(failures))
self.assertEqual(
{str(SOAP_ENV.Envelope): {
str(SOAP_ENV.Body): {
str(SOAP_ENV.Fault): {
'faultcode': 'soapenv:Client',
'faultstring': 'Malformed SOAP request'}}}},
element_to_dict(fromstring(''.join(request.written))))
示例4: request_same_or_different_thread_thread
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def request_same_or_different_thread_thread(self):
hr = HendrixWSGIResource(reactor, self.tp, self.wsgi_thing)
request1 = DummyRequest('r1')
request1.isSecure = lambda: False
request1.content = "llamas"
d = deferToThreadPool(reactor, self.tp, hr.render, request1)
return d
示例5: request_same_or_different_thread_thread
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def request_same_or_different_thread_thread(self):
hr = HendrixWSGIResource(reactor, self.tp, self.wsgi_thing)
request1 = DummyRequest([b'r1'])
request1.isSecure = lambda: False
request1.content = b"llamas"
request1.client = IPv4Address("TCP", b"50.0.50.0", 5000)
d = deferToThreadPool(reactor, self.tp, hr.render, request1)
d.addCallback(lambda _: request1.notifyFinish())
return d
示例6: test_success
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_success(self):
def on_rendered(_):
self.assertEqual(['backend reply'], self.request.written)
d = _render(self.resource, self.request).addCallback(on_rendered)
callback_request = DummyRequest([''])
callback_request.content = StringIO('backend reply')
self.resource.factory.requests.values()[0].notify(callback_request)
return d
示例7: test_post_returns_internal_server_error
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_post_returns_internal_server_error(self, mock_update_recovery_code):
mock_update_recovery_code.return_value = defer.fail(Exception)
request = DummyRequest(['/backup-account'])
request.method = 'POST'
request.content = MagicMock()
request.content.getvalue.return_value = '{"email": "[email protected]"}'
d = self.web.get(request)
def assert_successful_response(_):
self.assertEqual(500, request.responseCode)
d.addCallback(assert_successful_response)
return d
示例8: test_post_returns_successfully
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_post_returns_successfully(self, mock_update_recovery_code):
mock_update_recovery_code.return_value = defer.succeed("Success")
request = DummyRequest(['/backup-account'])
request.method = 'POST'
request.content = MagicMock()
request.content.getvalue.return_value = '{"email": "[email protected]"}'
d = self.web.get(request)
def assert_successful_response(_):
self.assertEqual(204, request.responseCode)
d.addCallback(assert_successful_response)
return d
示例9: test_sends_feedback_to_leap_web
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_sends_feedback_to_leap_web(self):
request = DummyRequest(['/feedback'])
request.method = 'POST'
content = mock()
when(content).read().thenReturn(json.dumps({'feedback': 'Pixelated is awesome!'}))
request.content = content
d = self.web.get(request)
def assert_posted_feedback_to_leap_web(_):
verify(self.feedback_service).open_ticket('Pixelated is awesome!')
d.addCallback(assert_posted_feedback_to_leap_web)
return d
示例10: test_render_invalid_xml
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_render_invalid_xml(self):
"""
`SmsNotificationService.render_POST` does not accept invalid XML body
content.
"""
service = SmsNotificationService(None, None)
request = DummyRequest([])
request.content = StringIO('sup')
d = request.notifyFinish()
service.render_POST(request)
self.successResultOf(d)
self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
failures = self.flushLoggedErrors(ParseError)
self.assertEqual(1, len(failures))
示例11: test_render_PUT_should_store_draft_with_attachments
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_render_PUT_should_store_draft_with_attachments(self, mock_register):
request = DummyRequest([])
request.method = 'PUT'
request.content = mock()
when(request.content).read().thenReturn('{"attachments": [{"ident": "some fake attachment id"}]}')
when(self.mail_service).attachment('some fake attachment id').thenReturn(defer.succeed({'content': mock()}))
mails_resource = MailsResource(self.services_factory)
web = DummySite(mails_resource)
d = web.get(request)
def assert_response(_):
verify(self.mail_service).attachment('some fake attachment id')
d.addCallback(assert_response)
return d
示例12: test_bad_status_codes_cause_no_go_in_wsgi_response
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_bad_status_codes_cause_no_go_in_wsgi_response(self):
self.no_go_status_codes = [404, '6xx']
request = DummyRequest('r1')
request.isSecure = lambda: False
request.content = "llamas"
finished = request.notifyFinish()
self.resource.render(request)
# This must wait until the WSGI response is closed.
finished.addCallback(
lambda _: self.assertFalse(
self.nameSpace.async_task_was_run
)
)
示例13: test_should_unauthorize_child_resource_non_ajax_POST_requests_when_csrf_input_mismatch
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_should_unauthorize_child_resource_non_ajax_POST_requests_when_csrf_input_mismatch(self):
request = DummyRequest(['mails'])
request.method = 'POST'
request.addArg('csrftoken', 'some csrf token')
mock_content = MagicMock()
mock_content.read = MagicMock(return_value={})
request.content = mock_content
request.getCookie = MagicMock(return_value='mismatched csrf token')
d = self.web.get(request)
def assert_unauthorized(_):
self.assertEqual(401, request.responseCode)
self.assertEqual("Unauthorized!", request.written[0])
d.addCallback(assert_unauthorized)
return d
示例14: test_render_POST_should_archive_mails
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_render_POST_should_archive_mails(self):
request = DummyRequest(["/mails/archive"])
request.method = "POST"
content = mock()
when(content).read().thenReturn(json.dumps({"idents": ["1", "2"]}))
when(self.mail_service).archive_mail("1").thenReturn(defer.Deferred())
when(self.mail_service).archive_mail("2").thenReturn(defer.Deferred())
request.content = content
d = self.web.get(request)
def assert_response(_):
verify(self.mail_service).archive_mail("1")
verify(self.mail_service).archive_mail("2")
d.addCallback(assert_response)
return d
示例15: test_render
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import content [as 别名]
def test_render(self):
"""
`SmsNotificationService.render_POST` parses a SOAP request and
dispatches it to `SmsNotificationService.process` for processing.
"""
service = SmsNotificationService(None, None)
service.process = lambda *a, **kw: L.done()
request = DummyRequest([])
request.content = StringIO(tostring(soap_envelope('hello')))
d = request.notifyFinish()
service.render_POST(request)
self.successResultOf(d)
self.assertEqual(http.OK, request.responseCode)
self.assertEqual(
{str(SOAP_ENV.Envelope): {
str(SOAP_ENV.Body): {
'done': None}}},
element_to_dict(fromstring(''.join(request.written))))