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


Python Mock.headers方法代码示例

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


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

示例1: get_mock

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
def get_mock():
    ysc = youtube_status_code
    yu = youtube_url
    yc = youtube_cookies
    yt = youtube_text
    yh = youtube_headers
    yosc = youtube_oembed_status_code
    you = youtube_oembed_url
    yoh = youtube_oembed_headers
    yot = youtube_oembed_text

    mock_obj_1 = Mock()
    mock_obj_1.status_code = ysc
    mock_obj_1.url = yu
    mock_obj_1.headers = yh
    mock_obj_1.cookies = yc
    mock_obj_1.text = yt
    mock_obj_1.json = lambda: json.loads(mock_obj_1.text)

    mock_obj_2 = Mock()
    mock_obj_2.status_code = 200
    mock_obj_2.url = you
    mock_obj_2.headers = yoh
    mock_obj_2.text = yot
    mock_obj_2.json = lambda: json.loads(mock_obj_2.text)

    return [mock_obj_1, mock_obj_1, mock_obj_2]
开发者ID:greyside,项目名称:django-mesh,代码行数:29,代码来源:youtube_data.py

示例2: test_resource_in_discovery_container_after_get_patch_delete

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
    def test_resource_in_discovery_container_after_get_patch_delete(self):
        with mock.patch('requests.get') as requests_get_mock:
            resource = {"@odata.id": "odata.id", "something": "irrelevant"}
            get_response = Mock()
            get_response.status_code = ReturnCodes.OK
            get_response.headers = {}
            get_response.text = json.dumps(resource)
            requests_get_mock.return_value = get_response
            discovery_container = DiscoveryContainer()
            self.api_caller.get_resource("/resource", discovery_container)
            self.assertEqual(discovery_container["http://{API_ENDPOINT}/resource".format(
                API_ENDPOINT=API_ENDPOINT)].body,
                             resource)

            patched_resource = {"@odata.id": "odata.id", "something": "relevant"}
            get_response.text = json.dumps(patched_resource)

            with mock.patch('requests.patch') as requests_patch_mock:
                patch_response = Mock()
                patch_response.status_code = ReturnCodes.OK
                patch_response.headers = {}
                patch_response.text = "{}"
                requests_patch_mock.return_value = patch_response
                _, _, _, _ = self.api_caller.patch_resource("/resource", discovery_container)
                self.assertEqual(discovery_container["http://{API_ENDPOINT}/resource".format(
                API_ENDPOINT=API_ENDPOINT)].body, patched_resource)

                with mock.patch('requests.delete') as requests_delete_mock:
                    delete_response = Mock()
                    delete_response.status_code = ReturnCodes.NO_CONTENT
                    delete_response.headers = {}
                    delete_response.text = ""
                    requests_delete_mock.return_value = delete_response
                    _, _, _, _ = self.api_caller.delete_resource("/resource", discovery_container)
                    self.assertNotIn("/resource", discovery_container)
开发者ID:01org,项目名称:intelRSD,代码行数:37,代码来源:test_api_caller.py

示例3: test_gluster_check_object_creation_err

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
 def test_gluster_check_object_creation_err(self):
     with patch('gluster.swift.common.constraints.__check_object_creation',
                mock_check_object_creation):
         req = Mock()
         req.headers = []
         self.assertTrue(cnt.gluster_check_object_creation(req, 'dir/.'))
         req.headers = ['x-delete-at']
         self.assertTrue(cnt.gluster_check_object_creation(req, 'dir/z'))
开发者ID:allfs,项目名称:gluster-swift,代码行数:10,代码来源:test_constraints.py

示例4: test_service_policies

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
    def test_service_policies(self):
        gc = Mock()
        service_key = 'service_key'
        pdpm = PolicyDecisionPointManager(gc)
        # see that the PDP for service is the default
        self.assertEqual(pdpm.get_service_pdp(service_key), pdpm.load_common_service_pdp)

        pdpm.load_service_policy_rules(service_key, self.permit_ION_MANAGER_rule)

        # see that the PDP for service is not the default anymore
        self.assertNotEqual(pdpm.get_service_pdp(service_key), pdpm.load_common_service_pdp)

        # check request without a service_key raises NotFound error
        invocation = Mock()
        invocation.message_annotations = {}

        invocation.get_message_receiver.return_value = None
        with self.assertRaises(NotFound) as chk_res:
            pdpm.check_service_request_policies(invocation)
        self.assertIn(chk_res.exception.message, 'No receiver for this message')

        # check that, because actor does not have ION_MANAGER role, policy evaluates to a denial
        # (really Not Applicable, because of the inelegant hack of a policy we are setting up our pdp with)
        mock_header = Mock()
        invocation.message_annotations = {}
        invocation.message = {'argument1': 0}
        invocation.headers = {'op': 'op', 'process': 'process', 'request': 'request', 'ion-actor-id': 'ion-actor-id', 'receiver': 'resource-registry',
                                   'sender-type': 'sender-type', 'sender-service': 'Unknown', 'ion-actor-roles': {'org_name': ['ion-actor-roles']}}
        invocation.get_message_receiver.return_value = 'service_key'
        invocation.get_service_name.return_value = 'Unknown'
        invocation.get_message_sender.return_value = ['Unknown','Unknown']

        def get_header_value(key, default):
            return invocation.headers.get(key, default)
        mock_header.side_effect = get_header_value
        invocation.get_header_value = mock_header
        mock_args = Mock()
        process = Mock()
        process.org_governance_name = 'org_name'
        invocation.args = {'process': process}

        def get_arg_value(key, default):
            return invocation.args.get(key, default)
        mock_args.side_effect = get_arg_value
        invocation.get_arg_value = mock_args

        gc.system_root_org_name = 'sys_org_name'

        response = pdpm.check_service_request_policies(invocation)
        self.assertEqual(response.value, "NotApplicable")

        # check that policy evaluates to Permit because actor has ION_MANAGER role
        invocation.message_annotations = {}
        invocation.headers = {'op': 'op', 'process': 'process', 'request': 'request', 'ion-actor-id': 'ion-actor-id', 'receiver': 'resource-registry',
                                   'sender-type': 'sender-type', 'sender-service': 'sender-service', 'ion-actor-roles': {'sys_org_name': ['ION_MANAGER']}}
        response = pdpm.check_service_request_policies(invocation)
        self.assertEqual(response.value, "Permit")
开发者ID:ateranishi,项目名称:pyon,代码行数:59,代码来源:test_policy_decision.py

示例5: test_validate_headers

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
 def test_validate_headers(self):
     req = Mock()
     req.headers = []
     self.assertEqual(cnt.validate_headers(req), '')
     req.headers = ['x-some-header']
     self.assertEqual(cnt.validate_headers(req), '')
     req.headers = ['x-delete-at', 'x-some-header']
     self.assertNotEqual(cnt.validate_headers(req), '')
     req.headers = ['x-delete-after', 'x-some-header']
     self.assertNotEqual(cnt.validate_headers(req), '')
     req.headers = ['x-delete-at', 'x-delete-after', 'x-some-header']
     self.assertNotEqual(cnt.validate_headers(req), '')
开发者ID:allfs,项目名称:gluster-swift,代码行数:14,代码来源:test_constraints.py

示例6: test_gluster_check_object_creation_err

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
 def test_gluster_check_object_creation_err(self):
     with patch('gluster.swift.common.constraints.__check_object_creation',
                mock_check_object_creation):
         req = Mock()
         req.headers = []
         self.assertTrue(cnt.gluster_check_object_creation(req, 'dir/.'))
         #TODO: Although we now support x-delete-at and x-delete-after,
         #retained this test case as we may add some other header to
         #unsupported list in future
         raise SkipTest
         req.headers = ['x-delete-at']
         self.assertTrue(cnt.gluster_check_object_creation(req, 'dir/z'))
开发者ID:AsherBond,项目名称:gluster-swift,代码行数:14,代码来源:test_constraints.py

示例7: test_validate_headers_ignoring_config_set

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
 def test_validate_headers_ignoring_config_set(self):
     with patch('gluster.swift.common.constraints.'
                'Glusterfs._ignore_unsupported_headers', True):
         req = Mock()
         req.headers = []
         self.assertEqual(cnt.validate_headers(req), '')
         req.headers = ['x-some-header']
         self.assertEqual(cnt.validate_headers(req), '')
         req.headers = ['x-delete-at', 'x-some-header']
         self.assertEqual(cnt.validate_headers(req), '')
         req.headers = ['x-delete-after', 'x-some-header']
         self.assertEqual(cnt.validate_headers(req), '')
         req.headers = ['x-delete-at', 'x-delete-after', 'x-some-header']
         self.assertEqual(cnt.validate_headers(req), '')
开发者ID:allfs,项目名称:gluster-swift,代码行数:16,代码来源:test_constraints.py

示例8: get_signed_grade_mock_request_with_correct_signature

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
    def get_signed_grade_mock_request_with_correct_signature(self):
        """
        Generate a proper LTI request object
        """
        mock_request = Mock()
        mock_request.headers = {
            'X-Requested-With': 'XMLHttpRequest',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Authorization': (
                u'OAuth realm="https://testurl/", oauth_body_hash="wwzA3s8gScKD1VpJ7jMt9b%2BMj9Q%3D",'
                'oauth_nonce="18821463", oauth_timestamp="1409321145", '
                'oauth_consumer_key="__consumer_key__", oauth_signature_method="HMAC-SHA1", '
                'oauth_version="1.0", oauth_signature="fHsE1hhIz76/msUoMR3Lyb7Aou4%3D"'
            )
        }
        mock_request.url = u'https://testurl'
        mock_request.http_method = u'POST'
        mock_request.method = mock_request.http_method

        mock_request.body = (
            '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n'
            '<imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">'
            '<imsx_POXHeader><imsx_POXRequestHeaderInfo><imsx_version>V1.0</imsx_version>'
            '<imsx_messageIdentifier>edX_fix</imsx_messageIdentifier></imsx_POXRequestHeaderInfo>'
            '</imsx_POXHeader><imsx_POXBody><replaceResultRequest><resultRecord><sourcedGUID>'
            '<sourcedId>MITxLTI/MITxLTI/201x:localhost%3A8000-i4x-MITxLTI-MITxLTI-lti-3751833a214a4f66a0d18f63234207f2:363979ef768ca171b50f9d1bfb322131</sourcedId>'  # pylint: disable=line-too-long
            '</sourcedGUID><result><resultScore><language>en</language><textString>0.32</textString></resultScore>'
            '</result></resultRecord></replaceResultRequest></imsx_POXBody></imsx_POXEnvelopeRequest>'
        )

        return mock_request
开发者ID:dehamzah,项目名称:edx-platform,代码行数:33,代码来源:test_lti_unit.py

示例9: test_username_from_request_fails_for_missing_user_info

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
 def test_username_from_request_fails_for_missing_user_info(self,
                                                            validate_mock,
                                                            fetch_mock):
     mock_http_request = Mock()
     mock_http_request.headers = {'Authorization': 'Bearer any_access_token'}
     validate_mock.return_value = False
     self.assertIsNone(username_from_request(mock_http_request))
开发者ID:ImmobilienScout24,项目名称:c-bastion,代码行数:9,代码来源:oidc_tests.py

示例10: test_username_from_request_succeds

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
 def test_username_from_request_succeds(self, validate_mock, fetch_mock):
     mock_http_request = Mock()
     mock_http_request.headers = {'Authorization':
                                  'Bearer any_access_token'}
     fetch_mock.return_value = {'sub': 'any_user'}
     validate_mock.return_value = True
     self.assertEqual('any_user', username_from_request(mock_http_request))
开发者ID:ImmobilienScout24,项目名称:c-bastion,代码行数:9,代码来源:oidc_tests.py

示例11: mock_response

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
    def mock_response(self, status_code, headers, data):
        mock_response = Mock()
        mock_response.status_code = status_code
        mock_response.headers = headers
        mock_response.text = json.dumps(data)

        self.request_mock.return_value = mock_response
开发者ID:chosak,项目名称:delighted-python,代码行数:9,代码来源:__init__.py

示例12: setUp

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
 def setUp(self):
     response = Mock()
     response.content = json.dumps({'status': 'ok'})
     response.headers = {'Content-Type': 'application/json'}
     response.ok = True
     response.status_code = requests.codes.ok
     self.response = response
开发者ID:10to8,项目名称:rauth,代码行数:9,代码来源:base.py

示例13: setUp

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
    def setUp(self):
        # mock request object
        request = Request()
        request.method = "GET"
        request.url = "http://example.com/"
        request.params = {}
        request.data = {}
        request.params_and_data = {}
        self.request = request

        # mock response object
        response = Mock()
        response.content = "access_token=321"
        response.headers = {"content-type": "text/html; charset=UTF-8"}
        response.ok = True
        response.status_code = 200
        self.response = response

        # mock raise_for_status with an error
        def raise_for_status():
            raise Exception("Response not OK!")

        self.raise_for_status = raise_for_status

        # mock hook object
        hook = Mock()
        hook.consumer_key = "123"
        hook.consumer_secret = "456"
        hook.access_token = "321"
        hook.access_token_secret = "654"
        self.hook = hook
开发者ID:checkraiser,项目名称:rauth,代码行数:33,代码来源:base.py

示例14: test_head_object_with_json

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
 def test_head_object_with_json(self):
     http_response = Mock()
     http_response.encoding = 'utf-8'
     http_response.headers = CaseInsensitiveDict(
         {'Date': 'Thu, 22 Aug 2013 02:11:57 GMT',
          'Content-Length': '0',
          'x-amz-request-id': '2B74ECB010FF029E',
          'ETag': '"40d06eb6194712ac1c915783004ef730"',
          'Server': 'AmazonS3',
          'content-type': 'application/json',
          'Content-Type': 'application/json',
          'accept-ranges': 'bytes',
          'Last-Modified': 'Tue, 20 Aug 2013 18:33:25 GMT',
          'x-amz-server-side-encryption': 'AES256'})
     http_response.content = ''
     put_object = self.s3.get_operation('HeadObject')
     expected = {"AcceptRanges": "bytes",
                 "ContentType": "application/json",
                 "LastModified": "Tue, 20 Aug 2013 18:33:25 GMT",
                 "ContentLength": "0",
                 "ETag": '"40d06eb6194712ac1c915783004ef730"',
                 "ServerSideEncryption": "AES256"
                 }
     response_data = get_response(self.session, put_object,
                                  http_response)[1]
     self.assertEqual(response_data, expected)
开发者ID:ainoya,项目名称:botocore,代码行数:28,代码来源:test_response_parsing.py

示例15: build_response_mock

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import headers [as 别名]
def build_response_mock(status_code, json_body=None, headers=None,
                        add_content_length=True, **kwargs):
    real_response = requests.Response()
    real_response.status_code = status_code

    text = None
    if json_body is not None:
        text = json.dumps(json_body)
        if add_content_length and headers is not {}:
            real_response.headers['content-length'] = len(text)

    if headers is not None:
        for k, v in headers.items():
            real_response.headers[k] = v

    for k, v in kwargs.items():
        setattr(real_response, k, v)

    response = Mock(wraps=real_response, autospec=True)
    if text:
        response.text = text

    # for some reason, wraps cannot handle attributes which are dicts
    # and accessed by key
    response.headers = real_response.headers
    response.content = text

    return response
开发者ID:openstack,项目名称:python-jenkins,代码行数:30,代码来源:helper.py


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