本文整理汇总了Python中twisted.web.test.requesthelper.DummyRequest.method方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.method方法的具体用法?Python DummyRequest.method怎么用?Python DummyRequest.method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.test.requesthelper.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.method方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_request
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [as 别名]
def _create_request(self, number_of_commits):
body = {
"commits": [{"rev": i} for i in range(number_of_commits)]
}
request = DummyRequest([b"/"])
request.method = "POST"
request.args["payload"] = [json.dumps(body)]
return request
示例2: test_defaultHEAD
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [as 别名]
def test_defaultHEAD(self):
"""
When not otherwise overridden, L{Resource.render} treats a I{HEAD}
request as if it were a I{GET} request.
"""
expected = b"insert response here"
request = DummyRequest([])
request.method = b'HEAD'
resource = BytesReturnedRenderable(expected)
self.assertEqual(expected, resource.render(request))
示例3: test_get
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [as 别名]
def test_get(self):
request = DummyRequest(['/account-recovery'])
request.method = 'GET'
d = self.web.get(request)
def assert_200_when_user_logged_in(_):
self.assertEqual(200, request.responseCode)
self.assertIn("DOCTYPE html", request.written[0])
d.addCallback(assert_200_when_user_logged_in)
return d
示例4: test_post_returns_successfully
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [as 别名]
def test_post_returns_successfully(self):
request = DummyRequest(['/account-recovery'])
request.method = 'POST'
self.resource._handle_post = MagicMock(return_value=defer.succeed(None))
d = self.web.get(request)
def assert_successful_response(_):
self.assertEqual(200, request.responseCode)
d.addCallback(assert_successful_response)
return d
示例5: test_post_returns_failure
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [as 别名]
def test_post_returns_failure(self):
request = DummyRequest(['/account-recovery'])
request.method = 'POST'
self.resource._handle_post = MagicMock(return_value=defer.fail(InvalidPasswordError))
d = self.web.get(request)
def assert_error_response(_):
self.assertEqual(500, request.responseCode)
d.addCallback(assert_error_response)
return d
示例6: test_post_returns_internal_server_error
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [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
示例7: test_post_returns_successfully
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [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
示例8: test_explicitAllowedMethods
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [as 别名]
def test_explicitAllowedMethods(self):
"""
The L{UnsupportedMethod} raised by L{Resource.render} for an unsupported
request method has a C{allowedMethods} attribute set to the value of the
C{allowedMethods} attribute of the L{Resource}, if it has one.
"""
expected = [b'GET', b'HEAD', b'PUT']
resource = Resource()
resource.allowedMethods = expected
request = DummyRequest([])
request.method = b'FICTIONAL'
exc = self.assertRaises(UnsupportedMethod, resource.render, request)
self.assertEqual(set(expected), set(exc.allowedMethods))
示例9: test_sends_feedback_to_leap_web
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [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_implicitAllowedMethods
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [as 别名]
def test_implicitAllowedMethods(self):
"""
The L{UnsupportedMethod} raised by L{Resource.render} for an unsupported
request method has a C{allowedMethods} attribute set to a list of the
methods supported by the L{Resource}, as determined by the
I{render_}-prefixed methods which it defines, if C{allowedMethods} is
not explicitly defined by the L{Resource}.
"""
expected = set([b'GET', b'HEAD', b'PUT'])
resource = ImplicitAllowedMethods()
request = DummyRequest([])
request.method = b'FICTIONAL'
exc = self.assertRaises(UnsupportedMethod, resource.render, request)
self.assertEqual(expected, set(exc.allowedMethods))
示例11: test_should_unauthorize_child_resource_ajax_requests_when_csrf_mismatch
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [as 别名]
def test_should_unauthorize_child_resource_ajax_requests_when_csrf_mismatch(self):
request = DummyRequest(['/child'])
request.method = 'POST'
self._mock_ajax_csrf(request, 'stubbed csrf token')
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
示例12: test_should_404_non_existing_resource_with_valid_csrf
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [as 别名]
def test_should_404_non_existing_resource_with_valid_csrf(self):
request = DummyRequest(['/non-existing-child'])
request.method = 'POST'
self._mock_ajax_csrf(request, 'stubbed csrf token')
request.getCookie = MagicMock(return_value='stubbed csrf token')
d = self.web.get(request)
def assert_not_found(_):
self.assertEqual(404, request.responseCode)
self.assertIn("No Such Resource", request.written[0])
d.addCallback(assert_not_found)
return d
示例13: test_errback_is_called
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [as 别名]
def test_errback_is_called(self):
request = DummyRequest(['/logout'])
request.method = 'POST'
session = self.resource.get_session(request)
exception = Exception('')
session.expire = MagicMock(side_effect=exception)
d = self.web.get(request)
def assert_500_when_exception_is_thrown(_):
self.assertEqual(500, request.responseCode)
self.assertEqual('Something went wrong!', request.written[0])
d.addCallback(assert_500_when_exception_is_thrown)
return d
示例14: test_render_PUT_should_store_draft_with_attachments
# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import method [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
示例15: 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 method [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