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


Python MagicMock.session方法代码示例

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


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

示例1: test_address_save_without_address

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
 def test_address_save_without_address(self, mock_save):
     request = MagicMock()
     request.user.is_authenticated.return_value = False
     request.session = {}
     request.POST = dict(NEW_ADDRESS, method='dummy_shipping')
     request.session = {STORAGE_SESSION_KEY: {}}
     group = MagicMock()
     group.address = None
     storage = {'address': NEW_ADDRESS}
     step = ShippingStep(request, storage, group)
     self.assertTrue(step.forms_are_valid(), "Forms don't validate.")
     step.save()
     self.assertEqual(mock_save.call_count, 0)
     self.assertTrue(isinstance(storage['address'], dict),
                     'dict expected')
开发者ID:abnormal,项目名称:saleor,代码行数:17,代码来源:tests.py

示例2: req

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
def req():
    """XXX: Very simple mock request, improve this"""
    req = MagicMock()
    req.header = ["0", "1", "2", "3", "4", "5"]
    req.session = {}
    req.params = {}
    return req
开发者ID:hibozzy,项目名称:mediatum,代码行数:9,代码来源:fixtures.py

示例3: test_get_session_var

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
    def test_get_session_var(self):
        """
        Ensure get_session_var function is working properly.
        """
        from garage.session import get_session_var

        self._msg("test", "get_session_var", first=True)
        key = "abc"
        val = "123"
        request = MagicMock()
        my_dict = {key: val}

        def getitem(name):
            return my_dict[name]

        def setitem(name, val):
            my_dict[name] = val

        request.session = MagicMock(spec_set=dict)
        request.session.__getitem__.side_effect = getitem
        request.session.__setitem__.side_effect = setitem

        result = get_session_var(request, key)
        self.assertEqual(result, val)
        self._msg("key", key)
        self._msg("val", val)
        self._msg("result", result)

        val = "foo"
        my_dict[key] = val
        result = get_session_var(request, key)
        self.assertEqual(result, val)
        self._msg("key", key)
        self._msg("val", val)
        self._msg("result", result)
开发者ID:shuiziliu,项目名称:django-garage,代码行数:37,代码来源:tests.py

示例4: assert_expire_in_extended

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
    def assert_expire_in_extended(self, req_path, should_expire_in, should_extend, headers=None, query_string=None):
        request = MagicMock(path=req_path)
        request.method = "GET"
        request.user = MagicMock()
        request.user.is_authenticated.return_value = True
        thirty_mins_ago = (datetime.datetime.now() - datetime.timedelta(minutes=30)).strftime("%Y-%m-%dT%H:%M:%S.%f")
        request.session = {"_session_security": thirty_mins_ago}

        if headers:
            request.META = headers

        if query_string:
            request.REQUEST = query_string

        before_response = {}
        response = self.middleware.process_response(request, before_response)
        self.assertIsNotNone(response.get("Session-Expires-In"))

        self.assertIsAlmostEqualMinutes(response.get("Session-Expires-In"), should_expire_in - 30, delta=1.0)
        self.middleware.process_request(request)
        response2 = self.middleware.process_response(request, before_response)
        self.assertIsNotNone(response2.get("Session-Expires-In"))
        if should_extend:
            self.assertIsAlmostEqualMinutes(response.get("Session-Expires-In"), should_expire_in, delta=1.0)
        else:
            self.assertIsAlmostEqualMinutes(response.get("Session-Expires-In"), should_expire_in - 30, delta=1.0)
开发者ID:ministryofjustice,项目名称:cla_frontend,代码行数:28,代码来源:test_middleware.py

示例5: test_other_results

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
 def test_other_results(self, m_inspect):
     m_session = MagicMock()
     ret = MagicMock()
     ret.session = m_session
     m_inspect.return_value = ret
     res = self.fw.other_results
     self.assertEqual(res,
                      m_session.query().join().filter().order_by().all())
开发者ID:quarkslab,项目名称:irma,代码行数:10,代码来源:test_models_files_ext.py

示例6: test_set_session_var_error

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
    def test_set_session_var_error(self):
        """
        set_session_var should bypass setting request.session raises
        exception.
        """
        from garage.session import set_session_var

        self._msg("test", "set_session_var error", first=True)

        request = MagicMock()
        my_dict = {}

        def getitem(name):
            return my_dict[name]

        def setitem(name, val):
            my_dict[name] = "AttributeError"
            raise AttributeError

        request.session = MagicMock(spec_set=dict)
        request.session.__getitem__.side_effect = getitem
        request.session.__setitem__.side_effect = setitem
        set_session_var(request, "key", "val")
        result = my_dict.get("key")
        self.assertEqual(result, "AttributeError")
        self._msg("result", result)

        request = MagicMock()
        my_dict = {}

        def getitem(name):
            return my_dict[name]

        def setitem(name, val):
            my_dict[name] = "TypeError"
            raise TypeError

        request.session = MagicMock(spec_set=dict)
        request.session.__getitem__.side_effect = getitem
        request.session.__setitem__.side_effect = setitem
        set_session_var(request, "key", "val")
        result = my_dict.get("key")
        self.assertEqual(result, "TypeError")
        self._msg("result", result)
开发者ID:shuiziliu,项目名称:django-garage,代码行数:46,代码来源:tests.py

示例7: mock_request

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
 def mock_request(self, authed, path='/'):
     mock_request = MagicMock()
     mock_request.method = 'GET'
     mock_request.user.is_authenticated.return_value = authed
     mock_request.POST = {}
     mock_request.META = {}
     mock_request.session = {}
     mock_request.build_absolute_uri.return_value = path
     mock_request.get_full_path.return_value = path
     return mock_request
开发者ID:miing,项目名称:mci_migo,代码行数:12,代码来源:test_decorators.py

示例8: test_get_session_var_error

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
    def test_get_session_var_error(self):
        """
        get_session_var should return default value if getting key
        raises exception.
        """
        from garage.session import get_session_var

        self._msg("test", "get_session_var error", first=True)
        request = MagicMock()
        my_dict = {}

        def getitem(name):
            raise AttributeError

        def setitem(name, val):
            my_dict[name] = val

        request.session = MagicMock(spec_set=dict)
        request.session.__getitem__.side_effect = getitem
        request.session.__setitem__.side_effect = setitem
        result = get_session_var(request, "key", default="AttributeError")
        calls = request.session.mock_calls
        self._msg("calls", calls)
        self.assertEqual(result, "AttributeError")
        self._msg("result", result)

        request = MagicMock()
        my_dict = {}

        def getitem(name):
            raise TypeError

        def setitem(name, val):
            my_dict[name] = val

        request.session = MagicMock(spec_set=dict)
        request.session.__getitem__.side_effect = getitem
        request.session.__setitem__.side_effect = setitem
        result = get_session_var(request, "key", default="TypeError")
        calls = request.session.mock_calls
        self._msg("calls", calls)
        self.assertEqual(result, "TypeError")
        self._msg("result", result)
开发者ID:shuiziliu,项目名称:django-garage,代码行数:45,代码来源:tests.py

示例9: request

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
 def request(self, lti_launch={"custom_canvas_api_domain": TEST_DOMAIN},
             get_params={}):
     request = MagicMock()
     session = {"oauth_return_uri": self.TEST_DOMAIN}
     if lti_launch:
         session["LTI_LAUNCH"] = lti_launch
     request.session = session
     request.GET = get_params
     request.user.oauthtoken.updated_on = TEST_TIME
     return request
开发者ID:penzance,项目名称:ab-testing-tool,代码行数:12,代码来源:tests.py

示例10: test_process_response_logged_in_with_session_but_invalid_session_security_key

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
    def test_process_response_logged_in_with_session_but_invalid_session_security_key(self):
        request = MagicMock(path="/")
        request.method = "GET"
        request.user = MagicMock()
        request.user.is_authenticated.return_value = True

        request.session = {"_session_security": u"cantp😺 😸 😻 😽 😼 🙀 😿 😹 😾arsethisasadate"}

        before_response = {}
        with self.assertRaises(UnicodeEncodeError):
            self.middleware.process_response(request, before_response)
开发者ID:ministryofjustice,项目名称:cla_frontend,代码行数:13,代码来源:test_middleware.py

示例11: test_address_save_with_address_in_group

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
 def test_address_save_with_address_in_group(self, mock_save):
     request = MagicMock()
     request.user.is_authenticated.return_value = False
     request.session = {}
     request.POST = dict(NEW_ADDRESS, method='dummy_shipping')
     group = MagicMock()
     group.address = NEW_ADDRESS
     storage = {'address': NEW_ADDRESS}
     step = ShippingStep(request, storage, group)
     self.assertTrue(step.forms_are_valid(), "Forms don't validate.")
     step.save()
     self.assertEqual(mock_save.call_count, 0)
开发者ID:abnormal,项目名称:saleor,代码行数:14,代码来源:tests.py

示例12: test_process_response_logged_in_with_session_but_valid_session_security_key

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
    def test_process_response_logged_in_with_session_but_valid_session_security_key(self):
        request = MagicMock(path="/")
        request.method = "GET"
        request.user = MagicMock()
        request.user.is_authenticated.return_value = True

        request.session = {"_session_security": datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")}
        before_response = {}

        response = self.middleware.process_response(request, before_response)
        self.assertIsNotNone(response.get("Session-Expires-In"))
        self.assertIsAlmostEqualMinutes(response.get("Session-Expires-In"), EXPIRE_AFTER // 60, delta=1.0)
开发者ID:ministryofjustice,项目名称:cla_frontend,代码行数:14,代码来源:test_middleware.py

示例13: test_address_save_with_address_in_checkout

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
 def test_address_save_with_address_in_checkout(self, mock_save):
     request = MagicMock()
     request.user.is_authenticated.return_value = False
     request.session = {}
     request.POST = dict(NEW_ADDRESS, method='dummy_shipping')
     original_billing_address = {'name': 'Change Me', 'id': 10}
     group = MagicMock()
     group.address = None
     storage = {'address': original_billing_address}
     step = ShippingStep(request, storage, group)
     self.assertTrue(step.forms_are_valid(), "Forms don't validate.")
     step.save()
     self.assertEqual(mock_save.call_count, 0)
     self.assertEqual(storage['address'], NEW_ADDRESS)
开发者ID:abnormal,项目名称:saleor,代码行数:16,代码来源:tests.py

示例14: get_test_request

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
 def get_test_request(self):
     """
     Sets up a mock request object
     """
     request = MagicMock()
     request.LTI = dict(DEFAULT_LTI_PARAMS)
     request.method = "POST"
     request.lti_initial_request = True
     request.lti_authentication_successful = True
     request.POST = {
         "lti_message_type": "basic-lti-launch-request",
         "custom_component_display_name": "Not Scored Assignment"
     }
     request.session = {}
     request.user = self.get_test_user()
     return request
开发者ID:mitodl,项目名称:sga-lti,代码行数:18,代码来源:middleware_test.py

示例15: test_create_page_after_confirmation

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import session [as 别名]
    def test_create_page_after_confirmation(self):
        """
        This method tests the ability of the create view to recognise once a user has completed the pattern creation
        process. The expected result of this test is for the view to be recognise this state correctly.
        """
        # Set up a request to test the post-confirmation logic
        class session_dict(dict):
            def invalidate(self):
                pass
        request = MagicMock()
        d = session_dict()
        d["confirmed"] = "true"
        request.session = d

        response = create_view(request)

        # Assert that the 'user' has been rerouted to the beginning of the process
        assert isinstance(response, HTTPFound)
开发者ID:CO600GOL,项目名称:Game_of_life,代码行数:20,代码来源:test_create.py


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