Split up tests to avoid CI timeouts (#122096)

This commit is contained in:
Michael Hansen 2024-07-17 13:32:26 -05:00 committed by GitHub
parent 52b90621c7
commit fa0a5451b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 158 additions and 64 deletions

View File

@ -351,24 +351,14 @@
'card': dict({ 'card': dict({
}), }),
'data': dict({ 'data': dict({
'failed': list([ 'code': 'no_valid_targets',
]),
'success': list([
dict({
'id': 'light.kitchen',
'name': 'kitchen light',
'type': <IntentResponseTargetType.ENTITY: 'entity'>,
}),
]),
'targets': list([
]),
}), }),
'language': 'en', 'language': 'en',
'response_type': 'action_done', 'response_type': 'error',
'speech': dict({ 'speech': dict({
'plain': dict({ 'plain': dict({
'extra_data': None, 'extra_data': None,
'speech': 'Turned on the light', 'speech': 'Sorry, I am not aware of any device called my cool light',
}), }),
}), }),
}), }),
@ -474,6 +464,96 @@
}), }),
}) })
# --- # ---
# name: test_intent_entity_fail_if_unexposed
dict({
'conversation_id': None,
'response': dict({
'card': dict({
}),
'data': dict({
'code': 'no_valid_targets',
}),
'language': 'en',
'response_type': 'error',
'speech': dict({
'plain': dict({
'extra_data': None,
'speech': 'Sorry, I am not aware of any device called kitchen light',
}),
}),
}),
})
# ---
# name: test_intent_entity_remove_custom_name
dict({
'conversation_id': None,
'response': dict({
'card': dict({
}),
'data': dict({
'code': 'no_valid_targets',
}),
'language': 'en',
'response_type': 'error',
'speech': dict({
'plain': dict({
'extra_data': None,
'speech': 'Sorry, I am not aware of any device called kitchen light',
}),
}),
}),
})
# ---
# name: test_intent_entity_remove_custom_name.1
dict({
'conversation_id': None,
'response': dict({
'card': dict({
}),
'data': dict({
'failed': list([
]),
'success': list([
dict({
'id': 'light.kitchen',
'name': 'kitchen light',
'type': <IntentResponseTargetType.ENTITY: 'entity'>,
}),
]),
'targets': list([
]),
}),
'language': 'en',
'response_type': 'action_done',
'speech': dict({
'plain': dict({
'extra_data': None,
'speech': 'Turned on the light',
}),
}),
}),
})
# ---
# name: test_intent_entity_remove_custom_name.2
dict({
'conversation_id': None,
'response': dict({
'card': dict({
}),
'data': dict({
'code': 'no_valid_targets',
}),
'language': 'en',
'response_type': 'error',
'speech': dict({
'plain': dict({
'extra_data': None,
'speech': 'Sorry, I am not aware of any device called renamed light',
}),
}),
}),
})
# ---
# name: test_intent_entity_renamed # name: test_intent_entity_renamed
dict({ dict({
'conversation_id': None, 'conversation_id': None,

View File

@ -1558,6 +1558,31 @@ async def test_intent_entity_renamed(
assert data == snapshot assert data == snapshot
assert data["response"]["response_type"] == "action_done" assert data["response"]["response_type"] == "action_done"
async def test_intent_entity_remove_custom_name(
hass: HomeAssistant,
init_components,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test that removing a custom name allows targeting the entity by its auto-generated name again."""
context = Context()
entity = MockLight("kitchen light", STATE_ON)
entity._attr_unique_id = "1234"
entity.entity_id = "light.kitchen"
setup_test_component_platform(hass, LIGHT_DOMAIN, [entity])
assert await async_setup_component(
hass,
LIGHT_DOMAIN,
{LIGHT_DOMAIN: [{"platform": "test"}]},
)
await hass.async_block_till_done()
calls = async_mock_service(hass, LIGHT_DOMAIN, "turn_on")
# Should fail with auto-generated name
entity_registry.async_update_entity("light.kitchen", name="renamed light")
result = await conversation.async_converse( result = await conversation.async_converse(
hass, "turn on kitchen light", None, context hass, "turn on kitchen light", None, context
) )
@ -1578,6 +1603,7 @@ async def test_intent_entity_renamed(
assert data == snapshot assert data == snapshot
assert data["response"]["response_type"] == "action_done" assert data["response"]["response_type"] == "action_done"
assert len(calls) == 1
result = await conversation.async_converse( result = await conversation.async_converse(
hass, "turn on renamed light", None, context hass, "turn on renamed light", None, context
@ -1588,6 +1614,42 @@ async def test_intent_entity_renamed(
assert data["response"]["response_type"] == "error" assert data["response"]["response_type"] == "error"
async def test_intent_entity_fail_if_unexposed(
hass: HomeAssistant,
init_components,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test that an entity is not usable if unexposed."""
context = Context()
entity = MockLight("kitchen light", STATE_ON)
entity._attr_unique_id = "1234"
entity.entity_id = "light.kitchen"
setup_test_component_platform(hass, LIGHT_DOMAIN, [entity])
assert await async_setup_component(
hass,
LIGHT_DOMAIN,
{LIGHT_DOMAIN: [{"platform": "test"}]},
)
await hass.async_block_till_done()
calls = async_mock_service(hass, LIGHT_DOMAIN, "turn_on")
# Unexpose the entity
expose_entity(hass, "light.kitchen", False)
await hass.async_block_till_done(wait_background_tasks=True)
result = await conversation.async_converse(
hass, "turn on kitchen light", None, context
)
data = result.as_dict()
assert data == snapshot
assert data["response"]["response_type"] == "error"
assert len(calls) == 0
async def test_intent_entity_exposed( async def test_intent_entity_exposed(
hass: HomeAssistant, hass: HomeAssistant,
init_components, init_components,
@ -1611,52 +1673,12 @@ async def test_intent_entity_exposed(
{LIGHT_DOMAIN: [{"platform": "test"}]}, {LIGHT_DOMAIN: [{"platform": "test"}]},
) )
await hass.async_block_till_done() await hass.async_block_till_done()
entity_registry.async_update_entity("light.kitchen", aliases={"my cool light"})
await hass.async_block_till_done()
calls = async_mock_service(hass, LIGHT_DOMAIN, "turn_on") calls = async_mock_service(hass, LIGHT_DOMAIN, "turn_on")
result = await conversation.async_converse(
hass, "turn on kitchen light", None, context
)
assert len(calls) == 1 # Unexpose, then expose the entity
data = result.as_dict()
assert data == snapshot
assert data["response"]["response_type"] == "action_done"
calls.clear()
result = await conversation.async_converse(
hass, "turn on my cool light", None, context
)
assert len(calls) == 1
data = result.as_dict()
assert data == snapshot
assert data["response"]["response_type"] == "action_done"
# Unexpose the entity
expose_entity(hass, "light.kitchen", False) expose_entity(hass, "light.kitchen", False)
await hass.async_block_till_done(wait_background_tasks=True) await hass.async_block_till_done()
result = await conversation.async_converse(
hass, "turn on kitchen light", None, context
)
data = result.as_dict()
assert data == snapshot
assert data["response"]["response_type"] == "error"
result = await conversation.async_converse(
hass, "turn on my cool light", None, context
)
data = result.as_dict()
assert data == snapshot
assert data["response"]["response_type"] == "error"
# Now expose the entity
expose_entity(hass, "light.kitchen", True) expose_entity(hass, "light.kitchen", True)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -1664,18 +1686,10 @@ async def test_intent_entity_exposed(
hass, "turn on kitchen light", None, context hass, "turn on kitchen light", None, context
) )
data = result.as_dict()
assert data == snapshot
assert data["response"]["response_type"] == "action_done"
result = await conversation.async_converse(
hass, "turn on my cool light", None, context
)
data = result.as_dict() data = result.as_dict()
assert data == snapshot assert data == snapshot
assert data["response"]["response_type"] == "action_done" assert data["response"]["response_type"] == "action_done"
assert len(calls) == 1
async def test_intent_conversion_not_expose_new( async def test_intent_conversion_not_expose_new(