当前位置: 首页>>代码示例>>Python>>正文


Python DummyRequest.addArg方法代码示例

本文整理汇总了Python中twisted.web.test.requesthelper.DummyRequest.addArg方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.addArg方法的具体用法?Python DummyRequest.addArg怎么用?Python DummyRequest.addArg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.web.test.requesthelper.DummyRequest的用法示例。


在下文中一共展示了DummyRequest.addArg方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_returns_the_key_as_json_if_found

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
    def test_returns_the_key_as_json_if_found(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).fetch_key('[email protected]').thenReturn(defer.succeed(OpenPGPKey('[email protected]')))

        d = self.web.get(request)

        expected = {
            u'address': u'[email protected]',
            u'encr_used': False,
            u'fingerprint': u'',
            u'last_audited_at': 0,
            u'private': False,
            u'sign_used': False,
            u'tags': [u'keymanager-active'],
            u'type': u'OpenPGPKey-active',
            u'validation': u'Weak_Chain',
            u'version': 1,
        }

        def assert_response(_):
            actual = json.loads(ast.literal_eval(request.written[0]))
            self.assertEquals(expected, actual)

        d.addCallback(assert_response)
        return d
开发者ID:Meistache,项目名称:pixelated-user-agent,代码行数:28,代码来源:test_keys_resources.py

示例2: test_returns_the_key_as_json_if_found

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
    def test_returns_the_key_as_json_if_found(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).fetch_key('[email protected]').thenReturn(defer.succeed(OpenPGPKey('[email protected]')))

        d = self.web.get(request)

        expected = {
            "tags": ["keymanager-key"],
            "fingerprint": '',
            "private": False,
            'sign_used': False,
            'refreshed_at': 0,
            "expiry_date": 0,
            "address": '[email protected]',
            'encr_used': False,
            'last_audited_at': 0,
            'key_data': '',
            'length': 0,
            'key_id': '',
            'validation': 'Weak_Chain',
            'type': 'OpenPGPKey',
        }

        def assert_response(_):
            actual = json.loads(ast.literal_eval(request.written[0]))
            self.assertEquals(expected, actual)

        d.addCallback(assert_response)
        return d
开发者ID:sw00,项目名称:pixelated-user-agent,代码行数:32,代码来源:test_keys_resources.py

示例3: test_returns_the_key_as_json_if_found

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
    def test_returns_the_key_as_json_if_found(self):
        request = DummyRequest(["/keys"])
        request.addArg("search", "[email protected]")
        when(self.keymanager).fetch_key("[email protected]").thenReturn(defer.succeed(OpenPGPKey("[email protected]")))

        d = self.web.get(request)

        expected = {
            u"address": u"[email protected]",
            u"encr_used": False,
            u"fingerprint": u"",
            u"last_audited_at": 0,
            u"private": False,
            u"sign_used": False,
            u"tags": [u"keymanager-active"],
            u"type": u"OpenPGPKey-active",
            u"validation": u"Weak_Chain",
            u"version": 1,
        }

        def assert_response(_):
            actual = json.loads(ast.literal_eval(request.written[0]))
            self.assertEquals(expected, actual)

        d.addCallback(assert_response)
        return d
开发者ID:akjones,项目名称:pixelated-user-agent,代码行数:28,代码来源:test_keys_resources.py

示例4: CallbackResourceTest

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
class CallbackResourceTest(TestCase):
    def setUp(self):
        self.resource = CallbackResource()
        self.resource.factory = DecoupledRequestFactory()
        self.request = DummyRequest([''])
        self.request.method = 'POST'
        self.request.content = StringIO()

    def test_no_request_id(self):
        def on_rendered(_):
            self.assertEqual(self.request.responseCode, 503)
            self.assertEqual(['No request_id given'], self.request.written)

        return _render(self.resource, self.request).addCallback(on_rendered)

    def test_unknown_request_id(self):
        self.request.addArg('request_id', 'xxx')

        def on_rendered(_):
            self.assertEqual(self.request.responseCode, 503)
            self.assertEqual(['Request not found'], self.request.written)

        return _render(self.resource, self.request).addCallback(on_rendered)

    def test_success(self):
        self.request.addArg('request_id', 'xxx')
        self.resource.factory.requests['xxx'] = DecoupledRequest(
            self.resource.factory, 'xxx', DummyRequest(['']))

        def on_rendered(_):
            self.assertEqual(['ok'], self.request.written)

        return _render(self.resource, self.request).addCallback(on_rendered)
开发者ID:jaxer,项目名称:thinking-exercise,代码行数:35,代码来源:test_callback_resource.py

示例5: test_returns_unauthorized_if_key_is_private

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
    def test_returns_unauthorized_if_key_is_private(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).fetch_key('[email protected]').thenReturn(defer.succeed(OpenPGPKey('[email protected]', private=True)))

        d = self.web.get(request)

        def assert_response(_):
            self.assertEquals(401, request.code)

        d.addCallback(assert_response)
        return d
开发者ID:Meistache,项目名称:pixelated-user-agent,代码行数:14,代码来源:test_keys_resources.py

示例6: test_returns_404_if_key_not_found

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
    def test_returns_404_if_key_not_found(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).fetch_key('[email protected]').thenReturn(defer.fail(KeyNotFound()))

        d = self.web.get(request)

        def assert_404(_):
            self.assertEquals(404, request.code)

        d.addCallback(assert_404)
        return d
开发者ID:Meistache,项目名称:pixelated-user-agent,代码行数:14,代码来源:test_keys_resources.py

示例7: test_returns_404_if_key_not_found

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
    def test_returns_404_if_key_not_found(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).get_key_from_cache('[email protected]', OpenPGPKey).thenRaise(KeyNotFound())

        d = self.web.get(request)

        def assert_404(_):
            self.assertEquals(404, request.code)

        d.addCallback(assert_404)
        return d
开发者ID:EderRoger,项目名称:pixelated-user-agent,代码行数:14,代码来源:test_keys_resources.py

示例8: test_returns_the_key_as_json_if_found

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
    def test_returns_the_key_as_json_if_found(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).get_key_from_cache('[email protected]', OpenPGPKey).thenReturn(OpenPGPKey('[email protected]'))

        d = self.web.get(request)

        def assert_response(_):
            self.assertEquals('"{\\"tags\\": [\\"keymanager-key\\"], \\"fingerprint\\": null, '
                              '\\"private\\": null, \\"expiry_date\\": null, \\"address\\": '
                              '\\"[email protected]\\", \\"last_audited_at\\": null, \\"key_data\\": null, '
                              '\\"length\\": null, \\"key_id\\": null, \\"validation\\": null, '
                              '\\"type\\": \\"<class \'leap.keymanager.openpgp.OpenPGPKey\'>\\", '
                              '\\"first_seen_at\\": null}"', request.written[0])

        d.addCallback(assert_response)
        return d
开发者ID:EderRoger,项目名称:pixelated-user-agent,代码行数:19,代码来源:test_keys_resources.py

示例9: 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 addArg [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
开发者ID:pixelated,项目名称:pixelated-user-agent,代码行数:20,代码来源:test_root_resource.py

示例10: test_render_GET_should_unicode_mails_search_query

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
    def test_render_GET_should_unicode_mails_search_query(self, mock_register):
        request = DummyRequest([])
        non_unicode_search_term = 'coração'
        request.addArg('q', non_unicode_search_term)
        request.addArg('w', 25)
        request.addArg('p', 1)

        unicodified_search_term = u'coração'
        when(self.mail_service).mails(unicodified_search_term, 25, 1).thenReturn(defer.succeed(([], 0)))

        mails_resource = MailsResource(self.services_factory)
        web = DummySite(mails_resource)
        d = web.get(request)

        def assert_response(_):
            verify(self.mail_service).mails(unicodified_search_term, 25, 1)

        d.addCallback(assert_response)
        return d
开发者ID:bwagnerr,项目名称:pixelated-user-agent,代码行数:21,代码来源:test_mails_resource.py

示例11: TestLoginPOST

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
class TestLoginPOST(unittest.TestCase):
    def setUp(self):
        self.services_factory = mock()
        self.portal = mock()
        self.provider = mock()
        self.resource = LoginResource(self.services_factory, self.portal)
        self.web = DummySite(self.resource)

        self.request = DummyRequest([''])
        username = 'ayoyo'
        self.request.addArg('username', username)
        password = 'ayoyo_password'
        self.username = username
        self.password = password
        self.request.addArg('password', password)
        self.request.method = 'POST'
        leap_session = mock(LeapSession)
        user_auth = mock()
        user_auth.uuid = 'some_user_uuid'
        leap_session.user_auth = user_auth
        config = mock()
        config.leap_home = 'some_folder'
        leap_session.config = config
        leap_session.fresh_account = False
        self.leap_session = leap_session
        self.user_auth = user_auth

    def mock_user_has_services_setup(self):
        when(self.services_factory).is_logged_in('some_user_uuid').thenReturn(True)

    def test_login_responds_interstitial_and_add_corresponding_session_to_services_factory(self):
        irrelevant = None
        when(self.portal).login(ANY(), None, IResource).thenReturn((irrelevant, self.leap_session, irrelevant))
        when(self.services_factory).create_services_from(self.leap_session).thenAnswer(self.mock_user_has_services_setup)

        d = self.web.get(self.request)

        def assert_login_setup_service_for_user(_):
            verify(self.portal).login(ANY(), None, IResource)
            verify(self.services_factory).create_services_from(self.leap_session)
            interstitial_js_in_template = '<script src="startup-assets/Interstitial.js"></script>'
            self.assertIn(interstitial_js_in_template, self.request.written[0])
            self.assertTrue(self.resource.is_logged_in(self.request))

        d.addCallback(assert_login_setup_service_for_user)
        return d

    def test_login_does_not_reload_services_if_already_loaded(self):
        irrelevant = None
        when(self.portal).login(ANY(), None, IResource).thenReturn((irrelevant, self.leap_session, irrelevant))
        when(self.services_factory).is_logged_in('some_user_uuid').thenReturn(True)

        d = self.web.get(self.request)

        def assert_login_setup_service_for_user(_):
            verify(self.portal).login(ANY(), None, IResource)
            verify(self.services_factory).is_logged_in('some_user_uuid')
            verifyNoMoreInteractions(self.services_factory)
            interstitial_js_in_template = '<script src="startup-assets/Interstitial.js"></script>'
            self.assertIn(interstitial_js_in_template, self.request.written[0])
            self.assertTrue(self.resource.is_logged_in(self.request))

        d.addCallback(assert_login_setup_service_for_user)
        return d

    def test_should_return_form_back_with_error_message_when_login_fails(self):
        when(self.portal).login(ANY(), None, IResource).thenRaise(Exception())
        d = self.web.get(self.request)

        def assert_login_setup_service_for_user(_):
            verify(self.portal).login(ANY(), None, IResource)
            self.assertEqual(401, self.request.responseCode)
            written_response = ''.join(self.request.written)
            self.assertIn('Invalid credentials', written_response)
            self.assertFalse(self.resource.is_logged_in(self.request))

        d.addCallback(assert_login_setup_service_for_user)
        return d

    @patch('pixelated.bitmask_libraries.session.LeapSessionFactory.create')
    @patch('leap.auth.SRPAuth.authenticate')
    @patch('pixelated.config.services.Services.setup')
    def test_leap_session_is_not_created_when_leap_auth_fails(self, mock_service_setup, mock_leap_srp_auth, mock_leap_session_create):
        mock_leap_srp_auth.side_effect = SRPAuthenticationError()

        d = self.web.get(self.request)

        def assert_login_setup_service_for_user(_):
            verify(self.portal).login(ANY(), None, IResource)
            self.assertFalse(mock_leap_session_create.called)
            self.assertFalse(mock_service_setup.called)
            self.assertEqual(401, self.request.responseCode)
            self.assertFalse(self.resource.is_logged_in(self.request))

        d.addCallback(assert_login_setup_service_for_user)
        return d

    @patch('twisted.web.util.redirectTo')
    @patch('pixelated.resources.session.PixelatedSession.is_logged_in')
    def test_should_not_process_login_if_already_logged_in(self, mock_logged_in, mock_redirect):
#.........这里部分代码省略.........
开发者ID:phss,项目名称:pixelated-user-agent,代码行数:103,代码来源:test_login_resource.py

示例12: TestLoginPOST

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
class TestLoginPOST(unittest.TestCase):
    def setUp(self):
        self.services_factory = mock()
        self.provider = mock()
        self.resource = LoginResource(self.services_factory, self.provider)
        self.web = DummySite(self.resource)

        self.request = DummyRequest([''])
        username = 'ayoyo'
        self.request.addArg('username', username)
        password = 'ayoyo_password'
        self.username = username
        self.password = password
        self.request.addArg('password', password)
        self.request.method = 'POST'
        user_auth = mock()
        user_auth.uuid = 'some_user_uuid'
        self.user_auth = user_auth

    @patch('pixelated.authentication.Authenticator.authenticate')
    @patch('twisted.web.util.redirectTo')
    @patch('pixelated.resources.session.PixelatedSession.is_logged_in')
    def test_should_redirect_to_home_if_user_if_already_logged_in(self, mock_logged_in, mock_redirect, mock_authenticate):
        mock_logged_in.return_value = True
        when(self.services_factory).has_session(ANY()).thenReturn(True)
        mock_redirect.return_value = "mocked redirection"

        d = self.web.get(self.request)

        def assert_redirected_to_home(_):
            mock_redirect.assert_called_once_with('/', self.request)
            self.assertFalse(mock_authenticate.called)

        d.addCallback(assert_redirected_to_home)
        return d

    @patch('pixelated.config.leap.BootstrapUserServices.setup')
    @patch('pixelated.authentication.Authenticator.authenticate')
    def test_should_return_form_back_with_error_message_when_login_fails(self, mock_authenticate,
                                                                         mock_user_bootstrap_setup):
        mock_authenticate.side_effect = UnauthorizedLogin()

        d = self.web.get(self.request)

        def assert_error_response_and_user_services_not_setup(_):
            mock_authenticate.assert_called_once_with(self.username, self.password)
            self.assertEqual(401, self.request.responseCode)
            written_response = ''.join(self.request.written)
            self.assertIn('Invalid username or password', written_response)
            self.assertFalse(mock_user_bootstrap_setup.called)
            self.assertFalse(self.resource.get_session(self.request).is_logged_in())

        d.addCallback(assert_error_response_and_user_services_not_setup)
        return d

    @patch('pixelated.config.leap.BootstrapUserServices.setup')
    @patch('pixelated.authentication.Authenticator.authenticate')
    def test_successful_login_responds_interstitial(self, mock_authenticate, mock_user_bootstrap_setup):
        mock_authenticate.return_value = self.user_auth

        d = self.web.get(self.request)

        def assert_interstitial_in_response(_):
            mock_authenticate.assert_called_once_with(self.username, self.password)
            interstitial_js_in_template = '<script src="startup-assets/Interstitial.js"></script>'
            self.assertIn(interstitial_js_in_template, self.request.written[0])

        d.addCallback(assert_interstitial_in_response)
        return d

    @patch('pixelated.config.leap.BootstrapUserServices.setup')
    @patch('pixelated.authentication.Authenticator.authenticate')
    def test_successful_login_runs_user_services_bootstrap_when_interstitial_loaded(self, mock_authenticate, mock_user_bootstrap_setup):
        mock_authenticate.return_value = self.user_auth

        d = self.web.get(self.request)

        def assert_login_setup_service_for_user(_):
            mock_user_bootstrap_setup.assert_called_once_with(self.user_auth, self.password, 'pt-BR')

        d.addCallback(assert_login_setup_service_for_user)
        return d

    @patch('pixelated.config.leap.BootstrapUserServices.setup')
    @patch('pixelated.authentication.Authenticator.authenticate')
    def test_successful_adds_cookies_to_indicat_logged_in_status_when_services_are_loaded(self, mock_authenticate, mock_user_bootstrap_setup):
        mock_authenticate.return_value = self.user_auth
        irrelevant = None
        mock_user_bootstrap_setup.return_value = defer.succeed(irrelevant)

        d = self.web.get(self.request)

        def assert_login_setup_service_for_user(_):
            self.assertTrue(self.resource.get_session(self.request).is_logged_in())

        d.addCallback(assert_login_setup_service_for_user)
        return d
开发者ID:bwagnerr,项目名称:pixelated-user-agent,代码行数:99,代码来源:test_login_resource.py

示例13: TestLoginPOST

# 需要导入模块: from twisted.web.test.requesthelper import DummyRequest [as 别名]
# 或者: from twisted.web.test.requesthelper.DummyRequest import addArg [as 别名]
class TestLoginPOST(unittest.TestCase):
    def setUp(self):
        self.services_factory = mock()
        self.provider = mock()
        self.authenticator = MagicMock()
        self.resource = LoginResource(self.services_factory, self.provider, authenticator=self.authenticator)
        self.web = DummySite(self.resource)

        self.request = DummyRequest([''])
        username = 'ayoyo'
        self.request.addArg('username', username)
        password = 'ayoyo_password'
        self.username = username
        self.password = password
        self.request.addArg('password', password)
        self.request.method = 'POST'
        user_auth = mock()
        user_auth.uuid = 'some_user_uuid'
        self.user_auth = user_auth

    @patch('twisted.web.util.redirectTo')
    @patch('pixelated.resources.session.PixelatedSession.is_logged_in')
    def test_should_redirect_to_home_if_user_if_already_logged_in(self, mock_logged_in, mock_redirect):
        mock_logged_in.return_value = True
        when(self.services_factory).has_session(ANY()).thenReturn(True)
        mock_redirect.return_value = "mocked redirection"

        d = self.web.get(self.request)

        def assert_redirected_to_home(_):
            mock_redirect.assert_called_once_with('/', self.request)
            self.assertFalse(self.authenticator.authenticate.called)

        d.addCallback(assert_redirected_to_home)
        return d

    @patch('pixelated.config.leap.BootstrapUserServices.setup')
    @patch('twisted.web.util.redirectTo')
    def test_should_redirect_to_login_with_error_flag_when_login_fails(self,
                                                                       mock_redirect,
                                                                       mock_user_bootstrap_setup):
        self.authenticator.authenticate.side_effect = UnauthorizedLogin()
        mock_redirect.return_value = "mocked redirection"

        d = self.web.get(self.request)

        def assert_redirected_to_login(_):
            self.authenticator.authenticate.assert_called_once_with(self.username, self.password)
            mock_redirect.assert_called_once_with('/login?auth-error', self.request)
            self.assertFalse(mock_user_bootstrap_setup.called)
            self.assertFalse(self.resource.get_session(self.request).is_logged_in())

        d.addCallback(assert_redirected_to_login)
        return d

    @patch('pixelated.config.leap.BootstrapUserServices.setup')
    def test_successful_login_responds_interstitial(self, mock_user_bootstrap_setup):
        self.authenticator.authenticate.return_value = self.user_auth

        d = self.web.get(self.request)

        def assert_interstitial_in_response(_):
            self.authenticator.authenticate.assert_called_once_with(self.username, self.password)
            interstitial_js_in_template = '<script src="/public/interstitial.js"></script>'
            self.assertIn(interstitial_js_in_template, self.request.written[0])

        d.addCallback(assert_interstitial_in_response)
        return d

    @patch('pixelated.config.leap.BootstrapUserServices.setup')
    def test_successful_login_runs_user_services_bootstrap_when_interstitial_loaded(self, mock_user_bootstrap_setup):
        self.authenticator.authenticate.return_value = self.user_auth

        d = self.web.get(self.request)

        def assert_login_setup_service_for_user(_):
            mock_user_bootstrap_setup.assert_called_once_with(self.user_auth, self.password, 'en-US')

        d.addCallback(assert_login_setup_service_for_user)
        return d

    @patch('pixelated.config.leap.BootstrapUserServices.setup')
    def test_successful_adds_cookies_to_indicate_logged_in_status_when_services_are_loaded(self, mock_user_bootstrap_setup):
        self.authenticator.authenticate.return_value = self.user_auth
        irrelevant = None
        mock_user_bootstrap_setup.return_value = defer.succeed(irrelevant)

        d = self.web.get(self.request)

        def assert_login_setup_service_for_user(_):
            self.assertTrue(self.resource.get_session(self.request).is_logged_in())

        d.addCallback(assert_login_setup_service_for_user)
        return d

    @patch('pixelated.resources.session.PixelatedSession.login_started')
    def test_session_adds_login_started_status_after_authentication(self, mock_login_started):
        self.authenticator.authenticate.return_value = self.user_auth

        d = self.web.get(self.request)
#.........这里部分代码省略.........
开发者ID:pixelated,项目名称:pixelated-user-agent,代码行数:103,代码来源:test_login_resource.py


注:本文中的twisted.web.test.requesthelper.DummyRequest.addArg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。