當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。