Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a fixture for dialogflow calls in unit tests #17999

Merged
merged 2 commits into from Nov 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions tests/components/dialogflow/test_init.py
Expand Up @@ -16,19 +16,25 @@
REQUEST_TIMESTAMP = "2017-01-21T17:54:18.952Z"
CONTEXT_NAME = "78a5db95-b7d6-4d50-9c9b-2fc73a5e34c3_id_dialog_context"

calls = []


@pytest.fixture
async def fixture(hass, aiohttp_client):
"""Initialize a Home Assistant server for testing this module."""
async def calls(hass, fixture):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think that coroutines were supported as pytest fixtures without using pytest-asyncio.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point, yet it passes…

"""Return a list of Dialogflow calls triggered."""
calls = []

@callback
def mock_service(call):
"""Mock action call."""
calls.append(call)

hass.services.async_register('test', 'dialogflow', mock_service)

return calls


@pytest.fixture
async def fixture(hass, aiohttp_client):
"""Initialize a Home Assistant server for testing this module."""
await async_setup_component(hass, dialogflow.DOMAIN, {
"dialogflow": {},
})
Expand Down Expand Up @@ -371,7 +377,7 @@ async def test_intent_request_without_slots(hass, fixture):
assert "You are both home, you silly" == text


async def test_intent_request_calling_service(fixture):
async def test_intent_request_calling_service(fixture, calls):
"""Test a request for calling a service.

If this request is done async the test could finish before the action
Expand Down