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


Python aioresponses.aioresponses方法代码示例

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


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

示例1: test_agent_app_list_zero_apps_running

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_agent_app_list_zero_apps_running(self):
        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()

        slave_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S3"
        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}"
            )
            with aioresponses(passthrough=[local_address]) as rsps:
                build_mesos_cluster(rsps, slave_id)
                resp = await client.get(
                    f"/agents/{slave_id}/apps",
                    headers={"Authorization": f"Token {self.user_auth_key}"},
                )
                self.assertEqual(200, resp.status)
                data = await resp.json()
                self.assertEqual(0, len(data["apps"])) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:20,代码来源:test_agents.py

示例2: get_forecast_async

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def get_forecast_async():
    async def get_async_data():
        darksky = DarkSkyAsync("api_key")
        with aioresponses.aioresponses() as resp:
            resp.get(re.compile(".+"), status=200, payload=copy.deepcopy(DATA))

            result = await darksky.get_forecast(
                DATA["latitude"],
                DATA["longitude"],
                client_session=aiohttp.ClientSession()
            )

        return result

    loop = asyncio.get_event_loop()
    return loop.run_until_complete(get_async_data()) 
开发者ID:Detrous,项目名称:darksky,代码行数:18,代码来源:test_forecast.py

示例3: test_api_exception

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_api_exception():
    """Test API response Exception"""

    loop = asyncio.get_event_loop()
    with aioresponses() as m:
        json_obj = {
            "error": "Signature verification failed"
        }
        m.post('https://api.idex.market/return24Volume', payload=json_obj, status=200)

        async def _run_test():
            client = await AsyncClient.create(api_key)
            with pytest.raises(IdexAPIException):
                await client.get_24hr_volume()

        loop.run_until_complete(_run_test()) 
开发者ID:sammchardy,项目名称:python-idex,代码行数:18,代码来源:test_api_request.py

示例4: test_http_interpreter

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_http_interpreter():
    with aioresponses() as mocked:
        mocked.post("https://example.com/parse")

        endpoint = EndpointConfig('https://example.com')
        interpreter = RasaNLUHttpInterpreter(endpoint=endpoint)
        await interpreter.parse(text='message_text', message_id='1134')

        r = latest_request(
            mocked, "POST", "https://example.com/parse")

        query = json_of_latest_request(r)
        response = {'project': 'default',
                    'q': 'message_text',
                    'message_id': '1134',
                    'model': None,
                    'token': None}

        assert query == response 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:21,代码来源:test_interpreter.py

示例5: test_http_parsing

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_http_parsing():
    message = UserMessage('lunch?')

    endpoint = EndpointConfig('https://interpreter.com')
    with aioresponses() as mocked:
        mocked.post('https://interpreter.com/parse',
                    repeat=True,
                    status=200)

        inter = RasaNLUHttpInterpreter(endpoint=endpoint)
        try:
            await MessageProcessor(
                inter, None, None, None, None)._parse_message(message)
        except KeyError:
            pass  # logger looks for intent and entities, so we except

        r = latest_request(
            mocked, 'POST',
            "https://interpreter.com/parse")

        assert r
        assert json_of_latest_request(r)['message_id'] == message.message_id 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:24,代码来源:test_processor.py

示例6: test_print_history

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_print_history(mock_endpoint):
    tracker_dump = utils.read_file(
        "data/test_trackers/tracker_moodbot.json")

    sender_id = uuid.uuid4().hex

    url = '{}/conversations/{}/tracker?include_events=AFTER_RESTART'.format(
        mock_endpoint.url, sender_id)
    with aioresponses() as mocked:
        mocked.get(url,
                   body=tracker_dump,
                   headers={"Accept": "application/json"})

        await interactive._print_history(sender_id, mock_endpoint)

        assert latest_request(mocked, 'get', url) is not None 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:18,代码来源:test_interactive.py

示例7: test_is_listening_for_messages

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_is_listening_for_messages(mock_endpoint):
    tracker_dump = utils.read_file(
        "data/test_trackers/tracker_moodbot.json")

    sender_id = uuid.uuid4().hex

    url = '{}/conversations/{}/tracker?include_events=APPLIED'.format(
        mock_endpoint.url, sender_id)
    with aioresponses() as mocked:
        mocked.get(url, body=tracker_dump,
                   headers={"Content-Type": "application/json"})

        is_listening = await interactive.is_listening_for_message(
            sender_id, mock_endpoint)

        assert is_listening 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:18,代码来源:test_interactive.py

示例8: test_interactive_domain_persistence

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_interactive_domain_persistence(mock_endpoint, tmpdir):
    # Test method interactive._write_domain_to_file

    tracker_dump = "data/test_trackers/tracker_moodbot.json"
    tracker_json = utils.read_json_file(tracker_dump)

    events = tracker_json.get("events", [])

    domain_path = tmpdir.join("interactive_domain_save.yml").strpath

    url = '{}/domain'.format(mock_endpoint.url)
    with aioresponses() as mocked:
        mocked.get(url, payload={})

        await interactive._write_domain_to_file(domain_path, events,
                                                mock_endpoint)

    saved_domain = utils.read_yaml_file(domain_path)

    for default_action in default_actions():
        assert default_action.name() not in saved_domain["actions"] 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:23,代码来源:test_interactive.py

示例9: test_remote_action_endpoint_responds_500

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_remote_action_endpoint_responds_500(
        default_dispatcher_collecting,
        default_domain):
    tracker = DialogueStateTracker("default",
                                   default_domain.slots)

    endpoint = EndpointConfig("https://example.com/webhooks/actions")
    remote_action = action.RemoteAction("my_action", endpoint)

    with aioresponses() as mocked:
        mocked.post('https://example.com/webhooks/actions', status=500)

        with pytest.raises(Exception) as execinfo:
            await remote_action.run(default_dispatcher_collecting,
                                    tracker,
                                    default_domain)
        assert "Failed to execute custom action." in str(execinfo.value) 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:19,代码来源:test_actions.py

示例10: test_remote_action_endpoint_responds_400

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_remote_action_endpoint_responds_400(
        default_dispatcher_collecting,
        default_domain):
    tracker = DialogueStateTracker("default",
                                   default_domain.slots)

    endpoint = EndpointConfig("https://example.com/webhooks/actions")
    remote_action = action.RemoteAction("my_action", endpoint)

    with aioresponses() as mocked:
        # noinspection PyTypeChecker
        mocked.post(
            'https://example.com/webhooks/actions',
            exception=ClientResponseError(
                400, None, '{"action_name": "my_action"}'))

        with pytest.raises(Exception) as execinfo:
            await remote_action.run(default_dispatcher_collecting,
                                    tracker,
                                    default_domain)

    assert execinfo.type == ActionExecutionRejection
    assert "Custom action 'my_action' rejected to run" in str(execinfo.value) 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:25,代码来源:test_actions.py

示例11: test_get_apps_running_for_agent_mesos_orchestrator_zero_apps

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_get_apps_running_for_agent_mesos_orchestrator_zero_apps(
        self
    ):
        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}"
            )
            with aioresponses(passthrough=[local_address]) as rsps:
                agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S44"
                build_mesos_cluster(rsps, agent_id)
                agent = await self.agents_service.get_agent_by_id(
                    agent_id, self.user, self.account, self.mesos_orchestrator
                )
                apps = await self.agents_service.get_apps_running_for_agent(
                    self.user, agent, self.mesos_orchestrator
                )
                self.assertEquals([], apps) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:19,代码来源:test_agent_services.py

示例12: test_get_apps_running_for_agent_mesos_orchestrator_some_apps

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_get_apps_running_for_agent_mesos_orchestrator_some_apps(
        self
    ):
        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}"
            )
            with aioresponses(passthrough=[local_address]) as rsps:
                agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S9"
                build_mesos_cluster(rsps, agent_id)
                self.account.owner = "asgard"
                agent = await self.agents_service.get_agent_by_id(
                    agent_id, self.user, self.account, self.mesos_orchestrator
                )
                apps = await self.agents_service.get_apps_running_for_agent(
                    self.user, agent, self.mesos_orchestrator
                )
                self.assertEquals(1, len(apps)) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:20,代码来源:test_agent_services.py

示例13: test_get_app_stats_has_some_data

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_get_app_stats_has_some_data(self):
        with aioresponses() as rsps:
            agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S0"
            build_mesos_cluster(rsps, agent_id)
            add_agent_task_stats(
                rsps, agent_id, index_name="asgard-app-stats-2019-03-29-*"
            )
            stats = await self.apps_backend.get_app_stats(
                MesosApp(id="infra-asgard-api"),
                self.interval,
                self.user,
                self.account,
            )
            self.assertEqual(
                AppStats(cpu_pct="4.51", ram_pct="22.68", cpu_thr_pct="2.89"),
                stats,
            ) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:19,代码来源:test_marathon_apps_backend.py

示例14: test_get_agent_by_id_return_None_if_agent_not_found

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_get_agent_by_id_return_None_if_agent_not_found(self):
        slave_id = "39e1a8e3-0fd1-4ba6-981d-e01318944957-S2"
        with aioresponses() as rsps:
            rsps.get(
                f"{settings.MESOS_API_URLS[0]}/redirect",
                status=301,
                headers={"Location": settings.MESOS_API_URLS[0]},
            )
            rsps.get(
                f"{settings.MESOS_API_URLS[0]}/slaves?slave_id={slave_id}",
                payload={"slaves": []},
                status=200,
            )
            agent = await self.mesos_backend.get_agent_by_id(
                slave_id,  # Agent from asgard-infra namespace
                self.user,
                self.account,
            )
            self.assertIsNone(agent) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:21,代码来源:test_mesos_orchestrator.py

示例15: test_get_apps_returns_empty_list_if_agent_not_found

# 需要导入模块: import aioresponses [as 别名]
# 或者: from aioresponses import aioresponses [as 别名]
def test_get_apps_returns_empty_list_if_agent_not_found(self):
        slave_id = "39e1a8e3-0fd1-4ba6-981d-e01318944957-S2"
        with aioresponses() as rsps:
            rsps.get(
                f"{settings.MESOS_API_URLS[0]}/redirect",
                status=301,
                headers={"Location": settings.MESOS_API_URLS[0]},
            )
            rsps.get(
                f"{settings.MESOS_API_URLS[0]}/slaves?slave_id={slave_id}",
                payload={"slaves": []},
                status=200,
            )

            agent = await self.mesos_backend.get_agent_by_id(
                slave_id, self.user, self.account
            )
            apps = await self.mesos_backend.get_apps_running_for_agent(
                self.user, agent
            )
            self.assertEqual(0, len(apps)) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:23,代码来源:test_mesos_orchestrator.py


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