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


Python Mock.status_code方法代码示例

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


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

示例1: test_import_geospatial_data_blob_state_failure

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
 def test_import_geospatial_data_blob_state_failure(self, post_mock,
         execute_tasks_mock, delete_mock, get_mock):
     """Import data source test with upload blob failing."""
     get_mock.__name__ = 'get'
     delete_mock.__name__ = 'delete'
     post_mock.__name__ = 'post'
     res = {'uuid': 'test_blob_uuid'}
     mock_1 = Mock()
     mock_1.status_code = 200
     mock_1.json.return_value = res
     post_mock.return_value = mock_1
     mock_2 = Mock()
     mock_2.status_code = 200
     mock_2.json.return_value = {}
     delete_mock.return_value = mock_2
     mock_3 = Mock()
     mock_3.status_code = 200
     mock_3.json.side_effect = [
         {'uuid': 'test_blob_uuid', 'state': 'started'},
         {'uuid': 'test_blob_uuid', 'state': 'failure'}]
     get_mock.return_value = mock_3
     tfile = tempfile.NamedTemporaryFile(delete=False)
     tfile.close()
     self.assertRaises(snowfloat.errors.RequestError,
         self.client.import_geospatial_data, tfile.name,
         state_check_interval=0.1)
     self.import_geospatial_data_helper(post_mock, get_mock,
         execute_tasks_mock, validate_execute_tasks=False)
     os.remove(tfile.name)
开发者ID:Web5design,项目名称:snowfloat-python,代码行数:31,代码来源:test_client.py

示例2: test_parse_fedora_access

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
    def test_parse_fedora_access(self):
        TEMPLATE_TEXT = """
            {% load fedora %}
            {% fedora_access %}
                {{ test_obj.value }}
            {% permission_denied %}
                permission fallback
            {% fedora_failed %}
                connection fallback
            {% end_fedora_access %}
        """
        t = Template(TEMPLATE_TEXT)
        test_obj = MockFedoraObject()
        ctx = Context({'test_obj': test_obj})

        val = t.render(ctx)
        self.assertEqual(val.strip(), 'sample text')

        response = Mock()
        response.status_code = 401
        response.headers = {'content-type': 'text/plain'}
        response.content = ''
        test_obj._value = PermissionDenied(response)  # force test_obj.value to fail
        val = t.render(ctx)
        self.assertEqual(val.strip(), 'permission fallback')

        response.status_code = 500
        test_obj._value = RequestFailed(response)  # force test_obj.value to fail
        val = t.render(ctx)
        self.assertEqual(val.strip(), 'connection fallback')
开发者ID:WSULib,项目名称:eulfedora,代码行数:32,代码来源:test_templatetags.py

示例3: test_auth_header_preserved_from_s3_redirects

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
    def test_auth_header_preserved_from_s3_redirects(self):
        request = AWSRequest()
        request.url = 'https://bucket.s3.amazonaws.com/'
        request.method = 'GET'
        request.headers['Authorization'] = 'original auth header'
        prepared_request = request.prepare()

        fake_response = Mock()
        fake_response.headers = {
            'location': 'https://bucket.s3-us-west-2.amazonaws.com'}
        fake_response.url = request.url
        fake_response.status_code = 307
        fake_response.is_permanent_redirect = False
        # This line is needed to disable the cookie handling
        # code in requests.
        fake_response.raw._original_response = None

        success_response = Mock()
        success_response.raw._original_response = None
        success_response.is_redirect = False
        success_response.status_code = 200
        session = PreserveAuthSession()
        session.send = Mock(return_value=success_response)

        list(session.resolve_redirects(
            fake_response, prepared_request, stream=False))

        redirected_request = session.send.call_args[0][0]
        # The Authorization header for the newly sent request should
        # still have our original Authorization header.
        self.assertEqual(
            redirected_request.headers['Authorization'],
            'original auth header')
开发者ID:brint,项目名称:botocore,代码行数:35,代码来源:test_endpoint.py

示例4: test_registration

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
    def test_registration(self):
        """
        Test handle registration and subsequent checks.
        """
        client = self.portal.handle_client

        response = Mock()
        response.status_code = 201
        response.headers = {"location": self.handle_url}
        client.session.post = Mock(return_value=response)

        view = self.portal.page.restrictedTraverse('hasHandle')

        self.assertEqual(view.create(), self.handle_url)
        self.assertTrue(view.hasHandle())
        self.assertEqual(view.handle(), self.handle)

        response.status_code = 204
        response.text = ''
        client.session.get = Mock(return_value=response)
        client.session.put = Mock(return_value=response)
        client.session.delete = Mock(return_value=response)

        self.assertEqual(view.read(), self.handle_url)
        self.assertEqual(view.update(), self.handle_url)

        self.assertTrue(view.hasDeletePermission())
        self.assertEqual(view.delete(), None)
开发者ID:collective,项目名称:collective.handleclient,代码行数:30,代码来源:test_view.py

示例5: setUp

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
    def setUp(self, mock_requests):
        mock_tournament_response = Mock(spec=requests.Response)
        mock_matches_response = Mock(spec=requests.Response)
        mock_participants_response = Mock(spec=requests.Response)

        with open(TOURNAMENT_JSON_FILE) as f:
            self.tournament_json_dict = json.load(f)

        with open(MATCHES_JSON_FILE) as f:
            self.matches_json_dict = json.load(f)

        with open(PARTICIPANTS_JSON_FILE) as f:
            self.participants_json_dict = json.load(f)

        mock_tournament_response.status_code = 200
        mock_matches_response.status_code = 200
        mock_participants_response.status_code = 200

        mock_tournament_response.json.return_value = self.tournament_json_dict
        mock_matches_response.json.return_value = self.matches_json_dict
        mock_participants_response.json.return_value = self.participants_json_dict

        expected_tournament_url = scraper.challonge.TOURNAMENT_URL % TOURNAMENT_ID;
        expected_matches_url = scraper.challonge.MATCHES_URL % TOURNAMENT_ID;
        expected_participants_url = scraper.challonge.PARTICIPANTS_URL % TOURNAMENT_ID;

        mock_requests_return_values = {
                (expected_tournament_url, TEMPLATE_API_KEY): mock_tournament_response,
                (expected_matches_url, TEMPLATE_API_KEY): mock_matches_response,
                (expected_participants_url, TEMPLATE_API_KEY): mock_participants_response
        }
        mock_requests.get.side_effect = lambda url, **kwargs: mock_requests_return_values[(url, kwargs['params']['api_key'])]

        self.scraper = ChallongeScraper(TOURNAMENT_ID, TEMPLATE_CONFIG_FILE_PATH)
开发者ID:garsh0p,项目名称:garpr,代码行数:36,代码来源:test_challonge.py

示例6: test_autoCreateSensor

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
    def test_autoCreateSensor(self):
        sensorNotFound = Mock()
        sensorNotFound.status_code = 404
        sensorNotFound.text = '{"errorcode": "404-001", "message": ""}'

        created = Mock()
        created.status_code = 201

        ok = Mock()
        ok.status_code = 200

        request = Mock()
        request.side_effect = [authRequest(), sensorNotFound, created, ok]
        sensorcloud.webrequest.Requests.Request = request

        device = sensorcloud.Device("FAKE", "fake")
        sensor = device.sensor("sensor")
        self.assertTrue("channel" in sensor)

        calls = [
                mock.call('GET', 'https://dsx.sensorcloud.microstrain.com/SensorCloud/devices/FAKE/sensors/sensor/channels/channel/attributes/', mock.ANY),
                mock.call('PUT', 'https://dsx.sensorcloud.microstrain.com/SensorCloud/devices/FAKE/sensors/sensor/', mock.ANY),
                mock.call('GET', 'https://dsx.sensorcloud.microstrain.com/SensorCloud/devices/FAKE/sensors/sensor/channels/channel/attributes/', mock.ANY)
        ]
        request.assert_has_calls(calls)
开发者ID:LORD-MicroStrain,项目名称:SensorCloud,代码行数:27,代码来源:test_sensor.py

示例7: test_get_techloan_data

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
    def test_get_techloan_data(self):
        """
        Tests that getting the data from the techloan instance
        returns the expected data and raises errors appropriately
        """
        test_json = self.load_json_file('cte_techloan_type_data.json')
        status_codes = [200, 400]
        # Mock a get call with different status codes returned
        for status in status_codes:
            mock = Mock()
            mock.status_code = status
            mock.json = Mock(return_value=test_json)

            with patch.object(requests, 'get', return_value=mock):
                techloan_data = cte_techloan.get_techloan_data()
                if (status == 200):
                    self.assertEqual(techloan_data, test_json)
                else:
                    self.assertIs(techloan_data, None)

        # Mock a call with invalid techloan_data
        test_json = 1
        mock = Mock()
        mock.status_code = 200
        mock.json = Mock(return_value=test_json)

        with patch.object(requests, 'get', return_value=mock):
            techloan_data = cte_techloan.get_techloan_data()
            self.assertIs(techloan_data, None)
开发者ID:uw-it-aca,项目名称:spacescout_labstats,代码行数:31,代码来源:test_cte_techloan.py

示例8: test_resource_in_discovery_container_after_get_patch_delete

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [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

示例9: get_mock

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [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

示例10: test_import_geospatial_data_task_error

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
 def test_import_geospatial_data_task_error(self, post_mock,
         execute_tasks_mock, delete_mock, get_mock):
     """Import data source test with task failing."""
     get_mock.__name__ = 'get'
     delete_mock.__name__ = 'delete'
     post_mock.__name__ = 'post'
     res = {'uuid': 'test_blob_uuid'}
     mock_1 = Mock()
     mock_1.status_code = 200
     mock_1.json.return_value = res
     post_mock.return_value = mock_1
     mock_2 = Mock()
     mock_2.status_code = 200
     mock_2.json.side_effect = snowfloat.errors.RequestError(status=500,
         code=None, message=None, more=None)
     delete_mock.return_value = mock_2
     mock_3 = Mock()
     mock_3.status_code = 200
     mock_3.json.side_effect = [
         {'uuid': 'test_blob_uuid', 'state': 'started'},
         {'uuid': 'test_blob_uuid', 'state': 'success'}]
     get_mock.return_value = mock_3
     execute_tasks_mock.return_value = [{'error': 'test_error'},]
     tfile = tempfile.NamedTemporaryFile(delete=False)
     tfile.close()
     self.assertRaises(snowfloat.errors.RequestError,
         self.client.import_geospatial_data, tfile.name, srid=4326,
         state_check_interval=0.1)
     self.import_geospatial_data_helper(post_mock, get_mock,
         execute_tasks_mock)
     os.remove(tfile.name)
开发者ID:Web5design,项目名称:snowfloat-python,代码行数:33,代码来源:test_client.py

示例11: test_delete

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
 def test_delete(self):
     resp = Mock()
     resp.status_code = 200
     body = None
     self.instances.api.client.delete = Mock(return_value=(resp, body))
     self.instances.delete('instance1')
     resp.status_code = 500
     self.assertRaises(Exception, self.instances.delete, 'instance1')
开发者ID:cweidenkeller,项目名称:python-troveclient,代码行数:10,代码来源:test_instances.py

示例12: test__action

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
 def test__action(self):
     resp = Mock()
     self.management.api.client.post = Mock(return_value=(resp, 'body'))
     resp.status_code = 200
     self.management._action(1, 'body')
     self.assertEqual(1, self.management.api.client.post.call_count)
     resp.status_code = 400
     self.assertRaises(Exception, self.management._action, 1, 'body')
     self.assertEqual(2, self.management.api.client.post.call_count)
开发者ID:adamfokken,项目名称:python-troveclient,代码行数:11,代码来源:test_management.py

示例13: side_effect

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
        def side_effect(*args, **kwargs):
            response = Mock()
            data = json.loads(kwargs.get("data", "{}"))
            if "source_language_code" in data and "name" in data and "slug" in data:
                response.status_code = 201
            else:
                response.status_code = 400

            return response
开发者ID:scottybarr,项目名称:python-transifex,代码行数:11,代码来源:test_api.py

示例14: __init__

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
 def __init__(self):
     ticket_mock = Mock()
     ticket_mock.content = json.dumps(_get_ticket('Test'))
     ticket_mock.status_code = 200
     child_mock = Mock()
     child_mock.content = json.dumps([_get_ticket('Child'),
                                      _get_ticket('Child2')])
     child_mock.status_code = 200
     self.mocks = [ticket_mock, child_mock]
开发者ID:OddBloke,项目名称:centipede,代码行数:11,代码来源:test_views.py

示例15: get

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status_code [as 别名]
 def get(self, url):
     self.count += 1
     resp = Mock(spec = requests.models.Response)
     if self.count == 3:
         resp.status_code = 200
         resp.content = self.successful_response
     else:
         resp.status_code = 500
     return resp
开发者ID:sgravrock,项目名称:flickr-to-go,代码行数:11,代码来源:test_photo.py


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