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


Python requests_mock.mock方法代码示例

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


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

示例1: test_calc_route_info_with_path_not_ignored

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_calc_route_info_with_path_not_ignored(self):
        with requests_mock.mock() as m:
            lat = [47.49, 47.612, 47.645]
            lon = [19.04, 18.99, 18.82]
            bounds = [{"bottom": 47.4, "top": 47.5, "left": 19, "right": 19.1}, None, {"bottom": 47.6, "top": 47.7, "left": 18.8, "right": 18.9}]
            length = [400, 5000, 500]
            time = [40, 300, 50]
            address_to_coords_response = [
                '[{"city":"Test1","location":{"lat":%s,"lon":%s},"bounds":%s}]' % (lat[0], lon[0], str(bounds[0]).replace("'", '"')),
                '[{"city":"Test2","location":{"lat":%s,"lon":%s},"bounds":%s}]' % (lat[2], lon[2], str(bounds[2]).replace("'", '"'))
            ]
            m.get(self.address_req, [{'text': address_to_coords_response[0]}, {'text': address_to_coords_response[1]}])
            route = wrc.WazeRouteCalculator("", "")
        route_mock = mock.Mock(return_value={"results": [
            {"length": length[0], "crossTime": time[0], "path": {"x": lon[0], "y": lat[0]}},
            {"length": length[1], "crossTime": time[1], "path": {"x": lon[1], "y": lat[1]}},
            {"length": length[2], "crossTime": time[2], "path": {"x": lon[2], "y": lat[2]}}
        ]})
        route.get_route = route_mock
        time, dist = route.calc_route_info()
        assert route_mock.called
        assert time == 6.5
        assert dist == 5.9 
开发者ID:kovacsbalu,项目名称:WazeRouteCalculator,代码行数:25,代码来源:tests.py

示例2: test_calc_route_info_with_ignored_and_nort

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_calc_route_info_with_ignored_and_nort(self):
        with requests_mock.mock() as m:
            lat = [47.49, 47.612, 47.645]
            lon = [19.04, 18.99, 18.82]
            bounds = [{"bottom": 47.4, "top": 47.5, "left": 19, "right": 19.1}, None, {"bottom": 47.6, "top": 47.7, "left": 18.8, "right": 18.9}]
            length = [400, 5000, 500]
            time = [40, 360, 60]
            nort_time = [40, 300, 50]
            address_to_coords_response = [
                '[{"city":"Test1","location":{"lat":%s,"lon":%s},"bounds":%s}]' % (lat[0], lon[0], str(bounds[0]).replace("'", '"')),
                '[{"city":"Test2","location":{"lat":%s,"lon":%s},"bounds":%s}]' % (lat[2], lon[2], str(bounds[2]).replace("'", '"'))
            ]
            m.get(self.address_req, [{'text': address_to_coords_response[0]}, {'text': address_to_coords_response[1]}])
            route = wrc.WazeRouteCalculator("", "")
        route_mock = mock.Mock(return_value={"results": [
            {"length": length[0], "crossTime": time[0], "crossTimeWithoutRealTime": nort_time[0], "path": {"x": lon[0], "y": lat[0]}},
            {"length": length[1], "crossTime": time[1], "crossTimeWithoutRealTime": nort_time[1], "path": {"x": lon[1], "y": lat[1]}},
            {"length": length[2], "crossTime": time[2], "crossTimeWithoutRealTime": nort_time[2], "path": {"x": lon[2], "y": lat[2]}}
        ]})
        route.get_route = route_mock
        time, dist = route.calc_route_info(stop_at_bounds=True, real_time=False)
        assert route_mock.called
        assert time == 5.00
        assert dist == 5.00 
开发者ID:kovacsbalu,项目名称:WazeRouteCalculator,代码行数:26,代码来源:tests.py

示例3: test_calc_route_info_stopatbounds_missing_bounds

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_calc_route_info_stopatbounds_missing_bounds(self):
        with requests_mock.mock() as m:
            lat = [47.49, 47.612, 47.645]
            lon = [19.04, 18.99, 18.82]
            bounds = [None, None, {"bottom": 47.6, "top": 47.7, "left": 18.8, "right": 18.9}]
            length = [400, 5000, 500]
            time = [45, 300, 60]
            address_to_coords_response = [
                '[{"city":"Test1","location":{"lat":%s,"lon":%s},"bounds":null}]' % (lat[0], lon[0]),
                '[{"city":"Test2","location":{"lat":%s,"lon":%s},"bounds":%s}]' % (lat[2], lon[2], str(bounds[2]).replace("'", '"'))
            ]
            m.get(self.address_req, [{'text': address_to_coords_response[0]}, {'text': address_to_coords_response[1]}])
            route = wrc.WazeRouteCalculator("", "")
        route_mock = mock.Mock(return_value={"results": [
            {"length": length[0], "crossTime": time[0], "path": {"x": lon[0], "y": lat[0]}},
            {"length": length[1], "crossTime": time[1], "path": {"x": lon[1], "y": lat[1]}},
            {"length": length[2], "crossTime": time[2], "path": {"x": lon[2], "y": lat[2]}}
        ]})
        route.get_route = route_mock
        time, dist = route.calc_route_info(stop_at_bounds=True)
        assert route_mock.called
        assert time == 5.75
        assert dist == 5.40 
开发者ID:kovacsbalu,项目名称:WazeRouteCalculator,代码行数:25,代码来源:tests.py

示例4: driver_wrapper

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def driver_wrapper():
    # Reset wrappers pool values
    DriverWrappersPool._empty_pool()
    DriverWrapper.config_properties_filenames = None

    # Create a new wrapper
    driver_wrapper = DriverWrappersPool.get_default_wrapper()
    driver_wrapper.driver = mock.MagicMock()

    # Configure properties
    root_path = os.path.dirname(os.path.realpath(__file__))
    config_files = ConfigFiles()
    config_files.set_config_directory(os.path.join(root_path, 'conf'))
    config_files.set_config_properties_filenames('properties.cfg')
    config_files.set_output_directory(os.path.join(root_path, 'output'))
    driver_wrapper.configure(config_files)

    yield driver_wrapper

    # Reset wrappers pool values
    DriverWrappersPool._empty_pool()
    DriverWrapper.config_properties_filenames = None 
开发者ID:Telefonica,项目名称:toolium,代码行数:24,代码来源:test_driver_utils.py

示例5: test_get_remote_node_ggr

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_get_remote_node_ggr(driver_wrapper, utils):
    # Configure mock
    driver_wrapper.driver.session_id = '5af'
    grid_url = 'http://{}:{}/grid/api/testsession?session={}'.format('localhost', 4444, '5af')
    ggr_url = 'http://{}:{}/host/{}'.format('localhost', 4444, '5af')
    ggr_response_json = {'Count': 3, 'Username': '', 'Scheme': '', 'VNC': '', 'Name': 'host_name', 'Password': '',
                         'Port': 4500}

    with requests_mock.mock() as req_mock:
        req_mock.get(grid_url, text='non_json_response')
        req_mock.get(ggr_url, json=ggr_response_json)

        # Get remote node and check result
        assert utils.get_remote_node() == ('ggr', 'host_name')
        assert grid_url == req_mock.request_history[0].url
        assert ggr_url == req_mock.request_history[1].url 
开发者ID:Telefonica,项目名称:toolium,代码行数:18,代码来源:test_driver_utils.py

示例6: test_get_remote_node_non_grid

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_get_remote_node_non_grid(driver_wrapper, utils):
    # Configure mock
    driver_wrapper.driver.session_id = '5af'
    grid_url = 'http://{}:{}/grid/api/testsession?session={}'.format('localhost', 4444, '5af')
    ggr_url = 'http://{}:{}/host/{}'.format('localhost', 4444, '5af')
    selenoid_url = 'http://{}:{}/status'.format('localhost', 4444)

    with requests_mock.mock() as req_mock:
        req_mock.get(grid_url, text='non_json_response')
        req_mock.get(ggr_url, json={})
        req_mock.get(selenoid_url, json={})

        # Get remote node and check result
        assert utils.get_remote_node() == ('selenium', 'localhost')
        assert grid_url == req_mock.request_history[0].url
        assert ggr_url == req_mock.request_history[1].url
        assert selenoid_url == req_mock.request_history[2].url 
开发者ID:Telefonica,项目名称:toolium,代码行数:19,代码来源:test_driver_utils.py

示例7: test_get_remote_video_url

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_get_remote_video_url(utils):
    # Configure mock
    url = 'http://{}:{}/video'.format('10.20.30.40', 3000)
    video_url = 'http://{}:{}/download_video/f4.mp4'.format('10.20.30.40', 3000)
    video_response_json = {'exit_code': 1, 'out': [],
                           'error': ['Cannot call this endpoint without required parameters: session and action'],
                           'available_videos': {'5af': {'size': 489701,
                                                        'session': '5af',
                                                        'last_modified': 1460041262558,
                                                        'download_url': video_url,
                                                        'absolute_path': 'C:\\f4.mp4'}},
                           'current_videos': []}

    with requests_mock.mock() as req_mock:
        req_mock.get(url, json=video_response_json)

        # Get remote video url and check result
        assert utils._get_remote_video_url('10.20.30.40', '5af') == video_url
        assert url == req_mock.request_history[0].url 
开发者ID:Telefonica,项目名称:toolium,代码行数:21,代码来源:test_driver_utils.py

示例8: test_is_remote_video_enabled

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_is_remote_video_enabled(utils):
    # Configure mock
    url = 'http://{}:{}/config'.format('10.20.30.40', 3000)
    config_response_json = {'out': [], 'error': [], 'exit_code': 0,
                            'filename': ['selenium_grid_extras_config.json'],
                            'config_runtime': {'theConfigMap': {
                                'video_recording_options': {'width': '1024', 'videos_to_keep': '5',
                                                            'frames': '30',
                                                            'record_test_videos': 'true'}}}}

    with requests_mock.mock() as req_mock:
        req_mock.get(url, json=config_response_json)

        # Get remote video configuration and check result
        assert utils.is_remote_video_enabled('10.20.30.40') is True
        assert url == req_mock.request_history[0].url 
开发者ID:Telefonica,项目名称:toolium,代码行数:18,代码来源:test_driver_utils.py

示例9: test_is_remote_video_enabled_disabled

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_is_remote_video_enabled_disabled(utils):
    # Configure mock
    url = 'http://{}:{}/config'.format('10.20.30.40', 3000)
    config_response_json = {'out': [], 'error': [], 'exit_code': 0,
                            'filename': ['selenium_grid_extras_config.json'],
                            'config_runtime': {'theConfigMap': {
                                'video_recording_options': {'width': '1024', 'videos_to_keep': '5',
                                                            'frames': '30',
                                                            'record_test_videos': 'false'}}}}

    with requests_mock.mock() as req_mock:
        req_mock.get(url, json=config_response_json)

        # Get remote video configuration and check result
        assert utils.is_remote_video_enabled('10.20.30.40') is False
        assert url == req_mock.request_history[0].url 
开发者ID:Telefonica,项目名称:toolium,代码行数:18,代码来源:test_driver_utils.py

示例10: logger

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def logger():
    # Configure logger mock
    logger = mock.MagicMock()
    logger_patch = mock.patch('logging.getLogger', mock.MagicMock(return_value=logger))
    logger_patch.start()

    yield logger

    logger_patch.stop()

    # Clear jira module configuration
    jira.enabled = None
    jira.execution_url = None
    jira.summary_prefix = None
    jira.labels = None
    jira.comments = None
    jira.fix_version = None
    jira.build = None
    jira.only_if_changes = None
    jira.jira_tests_status.clear()
    jira.attachments = [] 
开发者ID:Telefonica,项目名称:toolium,代码行数:23,代码来源:test_jira.py

示例11: test_create

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_create(self):
        """
        This tests the 'Create Virtual Function' operation.
        """
        vf_mgr = self.partition.virtual_functions
        with requests_mock.mock() as m:
            result = {
                'element-uri':
                    '/api/partitions/fake-part-id-1/virtual-functions/'
                    'fake-vf-id-1'
            }
            m.post('/api/partitions/fake-part-id-1/virtual-functions',
                   json=result)

            vf = vf_mgr.create(properties={})

            assert isinstance(vf, VirtualFunction)
            assert vf.properties == result
            assert vf.uri == result['element-uri'] 
开发者ID:zhmcclient,项目名称:python-zhmcclient,代码行数:21,代码来源:test_virtual_function.py

示例12: setup_method

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def setup_method(self):
        self.session = Session('vswitch-dpm-host', 'vswitch-user',
                               'vswitch-pwd')
        self.client = Client(self.session)
        with requests_mock.mock() as m:
            # Because logon is deferred until needed, we perform it
            # explicitly in order to keep mocking in the actual test simple.
            m.post('/api/sessions', json={'api-session': 'vswitch-session-id'})
            self.session.logon()

        self.cpc_mgr = self.client.cpcs
        with requests_mock.mock() as m:
            result = {
                'cpcs': [
                    {
                        'object-uri': '/api/cpcs/vswitch-cpc-id-1',
                        'name': 'CPC',
                        'status': 'service-required',
                    }
                ]
            }
            m.get('/api/cpcs', json=result)

            cpcs = self.cpc_mgr.list()
            self.cpc = cpcs[0] 
开发者ID:zhmcclient,项目名称:python-zhmcclient,代码行数:27,代码来源:test_virtual_switch.py

示例13: test_address_to_coords

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_address_to_coords(self):
        from_address = 'From address'
        to_address = 'To address'
        test_address = "Testaddress"
        with requests_mock.mock() as m:
            m.get(self.address_req, text=self.address_to_coords_response)
            route = wrc.WazeRouteCalculator(from_address, to_address)
            coords = route.address_to_coords(test_address)
        assert coords == {'lat': self.lat, 'lon': self.lon, 'bounds': self.bounds}
        assert m.call_count == 3 
开发者ID:kovacsbalu,项目名称:WazeRouteCalculator,代码行数:12,代码来源:tests.py

示例14: test_address_to_coords_reversed

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_address_to_coords_reversed(self):
        from_address = 'From address'
        to_address = 'To address'
        test_address = "Testaddress"

        bounds = {"top": 47.4, "bottom": 47.5, "right": 19, "left": 19.3}
        address_to_coords_response = '[{"city":"Test","location":{"lat":%s,"lon":%s},"bounds":%s}]' % (self.lat, self.lon, str(bounds).replace("'", '"'))

        with requests_mock.mock() as m:
            m.get(self.address_req, text=address_to_coords_response)
            route = wrc.WazeRouteCalculator(from_address, to_address)
            coords = route.address_to_coords(test_address)
        assert coords == {'lat': self.lat, 'lon': self.lon, 'bounds': self.bounds}
        assert m.call_count == 3 
开发者ID:kovacsbalu,项目名称:WazeRouteCalculator,代码行数:16,代码来源:tests.py

示例15: test_address_to_coords_nocity

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import mock [as 别名]
def test_address_to_coords_nocity(self):
        from_address = 'From address'
        to_address = 'To address'
        test_address = "Testaddress"
        address_to_coords_response = '[{"location":{"lat":%s,"lon":%s},"bounds":%s}]' % (self.lat, self.lon, str(self.bounds).replace("'", '"'))
        with pytest.raises(wrc.WRCError):
            with requests_mock.mock() as m:
                m.get(self.address_req, text=address_to_coords_response)
                route = wrc.WazeRouteCalculator(from_address, to_address)
                coords = route.address_to_coords(test_address) 
开发者ID:kovacsbalu,项目名称:WazeRouteCalculator,代码行数:12,代码来源:tests.py


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