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


Python Mock.session方法代码示例

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


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

示例1: test_change_plan_form

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
 def test_change_plan_form(self):
     request = Mock()
     request.META = {}
     request.session = DummySession()
     user = get_user_model().objects.create_user(username="patrick")
     user.set_password("eldarion")
     user.save()
     PaymentPlan.objects.bulk_create(PLANS)
     customer = Customer.objects.create(
         stripe_id="cus_1",
         user=user
     )
     CurrentSubscription.objects.create(
         customer=customer,
         plan=PaymentPlan.objects.get(key="pro"),
         quantity=1,
         start=timezone.now(),
         status="active",
         cancel_at_period_end=False,
         amount=decimal.Decimal("19.99")
     )
     user = authenticate(username="patrick", password="eldarion")
     login(request, user)
     context = {
         "request": request
     }
     change_plan_form(context)
     self.assertTrue("form" in context)
开发者ID:justcompile,项目名称:django-stripe-payments,代码行数:30,代码来源:test_templatetags.py

示例2: test_change_plan_form

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
 def test_change_plan_form(self):
     request = Mock()
     request.META = {}
     request.session = DummySession()
     user = get_user_model().objects.create_user(username="patrick")
     user.set_password("eldarion")
     user.save()
     customer = CustomerProxy.objects.create(
         stripe_id="cus_1",
         user=user
     )
     plan = PlanProxy.objects.create(
         amount=10,
         currency="usd",
         interval="monthly",
         interval_count=1,
         name="Pro"
     )
     SubscriptionProxy.objects.create(
         customer=customer,
         plan=plan,
         quantity=1,
         start=timezone.now(),
         status="active",
         cancel_at_period_end=False
     )
     user = authenticate(username="patrick", password="eldarion")
     login(request, user)
     context = {
         "request": request
     }
     change_plan_form(context)
     self.assertTrue("form" in context)
开发者ID:jsalva,项目名称:pinax-stripe,代码行数:35,代码来源:test_templatetags.py

示例3: _test_authorize_template

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
    def _test_authorize_template(self, response_type="supported_grant", factory_ex=None, handler_ex=None):
        '''This method provides a template method for testing handle_authorize method from oauth2 controller.'''

        expected_response = Mock()

        client_facade = Mock()
        client_facade.session = Mock()

        request = Mock()
        request.params = {"response_type": response_type}

        request.models = Mock()
        request.models.Client = client_facade

        grant_handler = Mock()

        if not handler_ex:
            grant_handler.handle_grant = Mock(return_value=expected_response)
        else:
            grant_handler.handle_grant = Mock(side_effect=handler_ex)

        if not factory_ex:
            self._handlers_factory.get_handler = Mock(return_value=grant_handler)
        else:
            self._handlers_factory.get_handler = Mock(side_effect=factory_ex)

        response = self._oauth2_controller.handle_authorize(request)

        self.assertEqual(expected_response, response)

        self._handlers_factory.get_handler.assert_called_once_with("supported_grant", client_facade.session)
        grant_handler.handle_grant.assert_called_once_with(request)
开发者ID:rcosnita,项目名称:fantastico,代码行数:34,代码来源:test_oauth2_controller.py

示例4: test_put_request

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
 def test_put_request(self):
     middleware = DBRoutingMiddleware()
     request = Mock(spec=HttpRequest, method='PUT')
     request.session = {}
     output = middleware.process_request(request)
     self.assertIsNone(output)
     self.assertTrue(is_thread_readwrite())
开发者ID:Omosofe,项目名称:django-opendebates,代码行数:9,代码来源:test_router.py

示例5: test_set_flavour_with_session_backend

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
    def test_set_flavour_with_session_backend(self):
        original_FLAVOURS_STORAGE_BACKEND = settings.FLAVOURS_STORAGE_BACKEND
        try:
            settings.FLAVOURS_STORAGE_BACKEND = 'session'
            request = Mock()
            request.session = {}
            set_flavour('mobile', request=request)
            self.assertEqual(request.session, {})
            set_flavour('mobile', request=request, permanent=True)
            self.assertEqual(request.session, {
                settings.FLAVOURS_SESSION_KEY: u'mobile'
            })
            self.assertEqual(get_flavour(request), 'mobile')

            response = self.client.get('/')
            self.assertFalse('sessionid' in response.cookies)
            response = self.client.get('/', {
                settings.FLAVOURS_GET_PARAMETER: 'mobile',
            })
            self.assertTrue('sessionid' in response.cookies)
            sessionid = response.cookies['sessionid'].value
            session = Session.objects.get(session_key=sessionid)
            session_data = session.get_decoded()
            self.assertTrue(settings.FLAVOURS_SESSION_KEY in session_data)
            self.assertEqual(session_data[settings.FLAVOURS_SESSION_KEY], 'mobile')
        finally:
            settings.FLAVOURS_STORAGE_BACKEND = original_FLAVOURS_STORAGE_BACKEND
开发者ID:Akoten,项目名称:django-mobile,代码行数:29,代码来源:test_base.py

示例6: test_login_and_store_credentials_in_session

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
    def test_login_and_store_credentials_in_session(self):
        # only testing custom logic, which happens on POST
        # everything else is handled by django.contrib.auth
        mockrequest = Mock()
        mockrequest.method = 'POST'

        def not_logged_in(rqst):
            rqst.user.is_authenticated.return_value = False

        def set_logged_in(rqst):
            rqst.user.is_authenticated.return_value = True
            rqst.POST.get.return_value = "TEST_PASSWORD"

        # failed login
        with patch('eulfedora.views.authviews.login',
                   new=Mock(side_effect=not_logged_in)):
            mockrequest.session = dict()
            response = login_and_store_credentials_in_session(mockrequest)
            self.assert_(FEDORA_PASSWORD_SESSION_KEY not in mockrequest.session,
                         'user password for fedora should not be stored in session on failed login')

        # successful login
        with patch('eulfedora.views.authviews.login',
                   new=Mock(side_effect=set_logged_in)):
            response = login_and_store_credentials_in_session(mockrequest)
            self.assert_(FEDORA_PASSWORD_SESSION_KEY in mockrequest.session,
                         'user password for fedora should be stored in session on successful login')
            # test password stored in the mock request
            pwd = mockrequest.POST.get()
            # encrypted password stored in session
            sessionpwd = mockrequest.session[FEDORA_PASSWORD_SESSION_KEY]
            self.assertNotEqual(pwd, sessionpwd,
                                'password should not be stored in the session without encryption')
            self.assertEqual(pwd, cryptutil.decrypt(sessionpwd),
                             'user password stored in session is encrypted')
开发者ID:bodleian,项目名称:eulfedora,代码行数:37,代码来源:test_views.py

示例7: test_transfer_error

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
    def test_transfer_error(self, mock_vofile):
        vofile = MagicMock()
        mock_vofile.return_value = vofile

        vospace_url = 'https://somevospace.server/vospace'
        session = Mock()
        session.get.side_effect = [Mock(content='COMPLETED')]
        conn = Mock(spec=Connection)
        conn.session = session

        test_client = Client()

        # use the mocked connection instead of the real one
        test_client.conn = conn

        # job successfully completed
        vofile.read.side_effect = [b'QUEUED', b'COMPLETED']
        self.assertFalse(test_client.get_transfer_error(
            vospace_url + '/results/transferDetails', 'vos://vospace'))
        session.get.assert_called_once_with(vospace_url + '/phase',
                                            allow_redirects=False)

        # job suspended
        session.reset_mock()
        session.get.side_effect = [Mock(content=b'COMPLETED')]
        vofile.read.side_effect = [b'QUEUED', b'SUSPENDED']
        with self.assertRaises(OSError):
            test_client.get_transfer_error(
                vospace_url + '/results/transferDetails', 'vos://vospace')
        # check arguments for session.get calls
        self.assertEquals(
            [call(vospace_url + '/phase', allow_redirects=False)],
            session.get.call_args_list)

        # job encountered an internal error
        session.reset_mock()
        vofile.read.side_effect = Mock(side_effect=[b'QUEUED', b'ERROR'])
        session.get.side_effect = [Mock(content=b'COMPLETED'),
                                   Mock(text='InternalFault')]
        with self.assertRaises(OSError):
            test_client.get_transfer_error(
                vospace_url + '/results/transferDetails', 'vos://vospace')
        self.assertEquals([call(vospace_url + '/phase', allow_redirects=False),
                           call(vospace_url + '/error')],
                          session.get.call_args_list)

        # job encountered an unsupported link error
        session.reset_mock()
        link_file = 'testlink.fits'
        vofile.read.side_effect = Mock(side_effect=[b'QUEUED', b'ERROR'])
        session.get.side_effect = [Mock(content=b'COMPLETED'),
                                   Mock(
                                       text="Unsupported link target: " +
                                            link_file)]
        self.assertEquals(link_file, test_client.get_transfer_error(
            vospace_url + '/results/transferDetails', 'vos://vospace'))
        self.assertEquals([call(vospace_url + '/phase', allow_redirects=False),
                           call(vospace_url + '/error')],
                          session.get.call_args_list)
开发者ID:canfar,项目名称:vos,代码行数:61,代码来源:test_vos.py

示例8: test_show_failure_message_when_delete_admin_unit_fails

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
 def test_show_failure_message_when_delete_admin_unit_fails(self):
     request = Mock()
     request.session = {}
     admin_unit_manager = Mock()
     request.method = 'POST'
     request.POST.side_effect = Exception
     response = views.delete_administrative_unit(request, admin_unit_manager)
     self.assertEquals(request.session['message'], "Unable to delete Admin unit")
开发者ID:jwishnie,项目名称:unicef-project-mapping,代码行数:10,代码来源:admin_views_tests.py

示例9: test_set_flavour_permanent

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
    def test_set_flavour_permanent(self):
        request = Mock()
        request.session = MagicMock()

        set_flavour("mobile", request=request)
        self.assertEqual(request.session.__setitem__.call_args, None)
        set_flavour("mobile", request=request, permanent=True)
        self.assertEqual(request.session.__setitem__.call_args, ((settings.FLAVOURS_SESSION_KEY, "mobile"), {}))
开发者ID:savidworks,项目名称:django-mobile,代码行数:10,代码来源:tests.py

示例10: test_do_logout

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
    def test_do_logout(self):
        registry = Mock()
        registry.prefs = self.prefs
        registry.session = "foobar"
        cli = self._makeit(registry)

        cli.onecmd('logout')
        self.assertEqual(None, cli.registry.session)
开发者ID:longaccess,项目名称:longaccess-client,代码行数:10,代码来源:test_login.py

示例11: test_get_request

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
 def test_get_request(self):
     # Get request uses replica DB if not pinned
     middleware = DBRoutingMiddleware()
     request = Mock(spec=HttpRequest, method='GET')
     request.session = {}
     output = middleware.process_request(request)
     self.assertIsNone(output)
     self.assertFalse(is_thread_readwrite())
开发者ID:Omosofe,项目名称:django-opendebates,代码行数:10,代码来源:test_router.py

示例12: test_create_courseref_only_lti

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
 def test_create_courseref_only_lti(self, mocked):
     """
     Test that only LTI is allowed.
     """
     request = Mock()
     request.session = {}
     res = create_courseref(request)
     self.assertEqual(res.content, 'Only LTI allowed')
开发者ID:cjlee112,项目名称:socraticqs2,代码行数:10,代码来源:tests.py

示例13: test_delete_admin_unit

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
 def test_delete_admin_unit(self):
     request = Mock()
     request.session = {}
     admin_unit_manager = Mock()
     request.method = 'POST'
     request.POST.get.return_value = 1
     admin_unit_manager.get.delete.return_value = ""
     response = views.delete_administrative_unit(request, admin_unit_manager)
     self.assertEquals(request.session['message'], "Admin unit has been deleted successfully")
开发者ID:jwishnie,项目名称:unicef-project-mapping,代码行数:11,代码来源:admin_views_tests.py

示例14: test_get_default_view_smartphone

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
    def test_get_default_view_smartphone(self):

        request = Mock()
        request.META = {'HTTP_USER_AGENT': ''}
        request.session = {}
        with patch('wirecloud.platform.views.ua_parse') as ua_parse_mock:
            ua_parse_mock.return_value = Mock(is_mobile=True)
            self.assertEqual(get_default_view(request), 'smartphone')
            self.assertEqual(request.session['default_mode'], 'smartphone')
开发者ID:Fiware,项目名称:apps.Wirecloud,代码行数:11,代码来源:base.py

示例15: test_get_request_pinned

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import session [as 别名]
 def test_get_request_pinned(self):
     # If session is pinned, use master DB
     middleware = DBRoutingMiddleware()
     request = Mock(spec=HttpRequest, method='GET')
     request.session = {
         PINNING_KEY: datetime.now() + timedelta(seconds=30)
     }
     output = middleware.process_request(request)
     self.assertIsNone(output)
     self.assertTrue(is_thread_readwrite())
开发者ID:Omosofe,项目名称:django-opendebates,代码行数:12,代码来源:test_router.py


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