Add delete command (#17816)

This commit is contained in:
Bram Kragten 2018-10-26 17:29:33 +02:00 committed by Paulus Schoutsen
parent 86d7bc4962
commit 3175627363
2 changed files with 82 additions and 3 deletions

View file

@ -498,7 +498,7 @@ async def test_lovelace_add_card_position(hass, hass_ws_client):
async def test_lovelace_move_card_position(hass, hass_ws_client):
"""Test add_card command."""
"""Test move_card command."""
await async_setup_component(hass, 'lovelace')
client = await hass_ws_client(hass)
yaml = YAML(typ='rt')
@ -524,7 +524,7 @@ async def test_lovelace_move_card_position(hass, hass_ws_client):
async def test_lovelace_move_card_view(hass, hass_ws_client):
"""Test add_card command."""
"""Test move_card to view command."""
await async_setup_component(hass, 'lovelace')
client = await hass_ws_client(hass)
yaml = YAML(typ='rt')
@ -550,7 +550,7 @@ async def test_lovelace_move_card_view(hass, hass_ws_client):
async def test_lovelace_move_card_view_position(hass, hass_ws_client):
"""Test add_card command."""
"""Test move_card to view with position command."""
await async_setup_component(hass, 'lovelace')
client = await hass_ws_client(hass)
yaml = YAML(typ='rt')
@ -574,3 +574,29 @@ async def test_lovelace_move_card_view_position(hass, hass_ws_client):
assert msg['id'] == 5
assert msg['type'] == TYPE_RESULT
assert msg['success']
async def test_lovelace_delete_card(hass, hass_ws_client):
"""Test delete_card command."""
await async_setup_component(hass, 'lovelace')
client = await hass_ws_client(hass)
yaml = YAML(typ='rt')
with patch('homeassistant.components.lovelace.load_yaml',
return_value=yaml.load(TEST_YAML_A)), \
patch('homeassistant.components.lovelace.save_yaml') \
as save_yaml_mock:
await client.send_json({
'id': 5,
'type': 'lovelace/config/card/delete',
'card_id': 'test',
})
msg = await client.receive_json()
result = save_yaml_mock.call_args_list[0][0][1]
cards = result.mlget(['views', 1, 'cards'], list_ok=True)
assert len(cards) == 2
assert cards[0]['title'] == 'Example'
assert msg['id'] == 5
assert msg['type'] == TYPE_RESULT
assert msg['success']