PS4 bump to renamed dependency (#27144)

* Change to renamed dependency pyps4-2ndscreen 0.9.0

* Rename / bump to ps4 dependency to 1.0.0

* update requirements

* Rename test req

* Fix import

* Bump 1.0.1

* Fix flaky test leaving files behind
This commit is contained in:
ktnrg45 authored and Fabian Affolter committed 2019-10-06 14:43:34 +02:00
1 parent bd6bbcd5af
commit 1ecc883ef4
9 files changed
+56 -66

No files matched your search

+31 -32
View File
@@ -1,6 +1,8 @@
"""Define tests for the PlayStation 4 config flow."""
from unittest.mock import patch
from pyps4_2ndscreen.errors import CredentialTimeout
from homeassistant import data_entry_flow
from homeassistant.components import ps4
from homeassistant.components.ps4.const import DEFAULT_NAME, DEFAULT_REGION
@@ -73,28 +75,28 @@ async def test_full_flow_implementation(hass):
manager = hass.config_entries
# User Step Started, results in Step Creds
with patch("pyps4_homeassistant.Helper.port_bind", return_value=None):
with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None):
result = await flow.async_step_user()
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "creds"
# Step Creds results with form in Step Mode.
with patch("pyps4_homeassistant.Helper.get_creds", return_value=MOCK_CREDS):
with patch("pyps4_2ndscreen.Helper.get_creds", return_value=MOCK_CREDS):
result = await flow.async_step_creds({})
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "mode"
# Step Mode with User Input which is not manual, results in Step Link.
with patch(
"pyps4_homeassistant.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
"pyps4_2ndscreen.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
):
result = await flow.async_step_mode(MOCK_AUTO)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "link"
# User Input results in created entry.
with patch("pyps4_homeassistant.Helper.link", return_value=(True, True)), patch(
"pyps4_homeassistant.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
with patch("pyps4_2ndscreen.Helper.link", return_value=(True, True)), patch(
"pyps4_2ndscreen.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
):
result = await flow.async_step_link(MOCK_CONFIG)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
@@ -126,20 +128,20 @@ async def test_multiple_flow_implementation(hass):
manager = hass.config_entries
# User Step Started, results in Step Creds
with patch("pyps4_homeassistant.Helper.port_bind", return_value=None):
with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None):
result = await flow.async_step_user()
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "creds"
# Step Creds results with form in Step Mode.
with patch("pyps4_homeassistant.Helper.get_creds", return_value=MOCK_CREDS):
with patch("pyps4_2ndscreen.Helper.get_creds", return_value=MOCK_CREDS):
result = await flow.async_step_creds({})
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "mode"
# Step Mode with User Input which is not manual, results in Step Link.
with patch(
"pyps4_homeassistant.Helper.has_devices",
"pyps4_2ndscreen.Helper.has_devices",
return_value=[{"host-ip": MOCK_HOST}, {"host-ip": MOCK_HOST_ADDITIONAL}],
):
result = await flow.async_step_mode(MOCK_AUTO)
@@ -147,8 +149,8 @@ async def test_multiple_flow_implementation(hass):
assert result["step_id"] == "link"
# User Input results in created entry.
with patch("pyps4_homeassistant.Helper.link", return_value=(True, True)), patch(
"pyps4_homeassistant.Helper.has_devices",
with patch("pyps4_2ndscreen.Helper.link", return_value=(True, True)), patch(
"pyps4_2ndscreen.Helper.has_devices",
return_value=[{"host-ip": MOCK_HOST}, {"host-ip": MOCK_HOST_ADDITIONAL}],
):
result = await flow.async_step_link(MOCK_CONFIG)
@@ -175,8 +177,8 @@ async def test_multiple_flow_implementation(hass):
# Test additional flow.
# User Step Started, results in Step Mode:
with patch("pyps4_homeassistant.Helper.port_bind", return_value=None), patch(
"pyps4_homeassistant.Helper.has_devices",
with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None), patch(
"pyps4_2ndscreen.Helper.has_devices",
return_value=[{"host-ip": MOCK_HOST}, {"host-ip": MOCK_HOST_ADDITIONAL}],
):
result = await flow.async_step_user()
@@ -184,14 +186,14 @@ async def test_multiple_flow_implementation(hass):
assert result["step_id"] == "creds"
# Step Creds results with form in Step Mode.
with patch("pyps4_homeassistant.Helper.get_creds", return_value=MOCK_CREDS):
with patch("pyps4_2ndscreen.Helper.get_creds", return_value=MOCK_CREDS):
result = await flow.async_step_creds({})
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "mode"
# Step Mode with User Input which is not manual, results in Step Link.
with patch(
"pyps4_homeassistant.Helper.has_devices",
"pyps4_2ndscreen.Helper.has_devices",
return_value=[{"host-ip": MOCK_HOST}, {"host-ip": MOCK_HOST_ADDITIONAL}],
):
result = await flow.async_step_mode(MOCK_AUTO)
@@ -200,9 +202,9 @@ async def test_multiple_flow_implementation(hass):
# Step Link
with patch(
"pyps4_homeassistant.Helper.has_devices",
"pyps4_2ndscreen.Helper.has_devices",
return_value=[{"host-ip": MOCK_HOST}, {"host-ip": MOCK_HOST_ADDITIONAL}],
), patch("pyps4_homeassistant.Helper.link", return_value=(True, True)):
), patch("pyps4_2ndscreen.Helper.link", return_value=(True, True)):
result = await flow.async_step_link(MOCK_CONFIG_ADDITIONAL)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"][CONF_TOKEN] == MOCK_CREDS
@@ -232,13 +234,13 @@ async def test_port_bind_abort(hass):
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
with patch("pyps4_homeassistant.Helper.port_bind", return_value=MOCK_UDP_PORT):
with patch("pyps4_2ndscreen.Helper.port_bind", return_value=MOCK_UDP_PORT):
reason = "port_987_bind_error"
result = await flow.async_step_user(user_input=None)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == reason
with patch("pyps4_homeassistant.Helper.port_bind", return_value=MOCK_TCP_PORT):
with patch("pyps4_2ndscreen.Helper.port_bind", return_value=MOCK_TCP_PORT):
reason = "port_997_bind_error"
result = await flow.async_step_user(user_input=None)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
@@ -253,7 +255,7 @@ async def test_duplicate_abort(hass):
flow.creds = MOCK_CREDS
with patch(
"pyps4_homeassistant.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
"pyps4_2ndscreen.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
):
result = await flow.async_step_link(user_input=None)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
@@ -274,9 +276,9 @@ async def test_additional_device(hass):
assert len(manager.async_entries()) == 1
with patch(
"pyps4_homeassistant.Helper.has_devices",
"pyps4_2ndscreen.Helper.has_devices",
return_value=[{"host-ip": MOCK_HOST}, {"host-ip": MOCK_HOST_ADDITIONAL}],
), patch("pyps4_homeassistant.Helper.link", return_value=(True, True)):
), patch("pyps4_2ndscreen.Helper.link", return_value=(True, True)):
result = await flow.async_step_link(MOCK_CONFIG_ADDITIONAL)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"][CONF_TOKEN] == MOCK_CREDS
@@ -296,7 +298,7 @@ async def test_no_devices_found_abort(hass):
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
with patch("pyps4_homeassistant.Helper.has_devices", return_value=[]):
with patch("pyps4_2ndscreen.Helper.has_devices", return_value=[]):
result = await flow.async_step_link()
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "no_devices_found"
@@ -310,8 +312,7 @@ async def test_manual_mode(hass):
# Step Mode with User Input: manual, results in Step Link.
with patch(
"pyps4_homeassistant.Helper.has_devices",
return_value=[{"host-ip": flow.m_device}],
"pyps4_2ndscreen.Helper.has_devices", return_value=[{"host-ip": flow.m_device}]
):
result = await flow.async_step_mode(MOCK_MANUAL)
assert flow.m_device == MOCK_HOST
@@ -324,7 +325,7 @@ async def test_credential_abort(hass):
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
with patch("pyps4_homeassistant.Helper.get_creds", return_value=None):
with patch("pyps4_2ndscreen.Helper.get_creds", return_value=None):
result = await flow.async_step_creds({})
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "credential_error"
@@ -332,12 +333,10 @@ async def test_credential_abort(hass):
async def test_credential_timeout(hass):
"""Test that Credential Timeout shows error."""
from pyps4_homeassistant.errors import CredentialTimeout
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
with patch("pyps4_homeassistant.Helper.get_creds", side_effect=CredentialTimeout):
with patch("pyps4_2ndscreen.Helper.get_creds", side_effect=CredentialTimeout):
result = await flow.async_step_creds({})
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["errors"] == {"base": "credential_timeout"}
@@ -349,8 +348,8 @@ async def test_wrong_pin_error(hass):
flow.hass = hass
flow.location = MOCK_LOCATION
with patch("pyps4_homeassistant.Helper.link", return_value=(True, False)), patch(
"pyps4_homeassistant.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
with patch("pyps4_2ndscreen.Helper.link", return_value=(True, False)), patch(
"pyps4_2ndscreen.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
):
result = await flow.async_step_link(MOCK_CONFIG)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
@@ -364,8 +363,8 @@ async def test_device_connection_error(hass):
flow.hass = hass
flow.location = MOCK_LOCATION
with patch("pyps4_homeassistant.Helper.link", return_value=(False, True)), patch(
"pyps4_homeassistant.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
with patch("pyps4_2ndscreen.Helper.link", return_value=(False, True)), patch(
"pyps4_2ndscreen.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
):
result = await flow.async_step_link(MOCK_CONFIG)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
+11 -13
View File
@@ -1,7 +1,7 @@
"""Tests for the PS4 media player platform."""
from unittest.mock import MagicMock, patch
from pyps4_homeassistant.credential import get_ddp_message
from pyps4_2ndscreen.credential import get_ddp_message
from homeassistant.components import ps4
from homeassistant.components.media_player.const import (
@@ -295,9 +295,7 @@ async def test_media_attributes_are_loaded(hass):
async def test_device_info_is_set_from_status_correctly(hass):
"""Test that device info is set correctly from status update."""
mock_d_registry = mock_device_registry(hass)
with patch(
"pyps4_homeassistant.ps4.get_status", return_value=MOCK_STATUS_OFF
), patch(MOCK_SAVE, side_effect=MagicMock()):
with patch("pyps4_2ndscreen.ps4.get_status", return_value=MOCK_STATUS_OFF):
mock_entity_id = await setup_mock_component(hass)
await hass.async_block_till_done()
@@ -447,9 +445,9 @@ async def test_media_stop(hass):
async def test_select_source(hass):
"""Test that select source service calls function with title."""
mock_data = {MOCK_TITLE_ID: MOCK_GAMES_DATA}
with patch(
"pyps4_homeassistant.ps4.get_status", return_value=MOCK_STATUS_IDLE
), patch(MOCK_LOAD, return_value=mock_data):
with patch("pyps4_2ndscreen.ps4.get_status", return_value=MOCK_STATUS_IDLE), patch(
MOCK_LOAD, return_value=mock_data
):
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
@@ -473,9 +471,9 @@ async def test_select_source(hass):
async def test_select_source_caps(hass):
"""Test that select source service calls function with upper case title."""
mock_data = {MOCK_TITLE_ID: MOCK_GAMES_DATA}
with patch(
"pyps4_homeassistant.ps4.get_status", return_value=MOCK_STATUS_IDLE
), patch(MOCK_LOAD, return_value=mock_data):
with patch("pyps4_2ndscreen.ps4.get_status", return_value=MOCK_STATUS_IDLE), patch(
MOCK_LOAD, return_value=mock_data
):
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
@@ -502,9 +500,9 @@ async def test_select_source_caps(hass):
async def test_select_source_id(hass):
"""Test that select source service calls function with Title ID."""
mock_data = {MOCK_TITLE_ID: MOCK_GAMES_DATA}
with patch(
"pyps4_homeassistant.ps4.get_status", return_value=MOCK_STATUS_IDLE
), patch(MOCK_LOAD, return_value=mock_data):
with patch("pyps4_2ndscreen.ps4.get_status", return_value=MOCK_STATUS_IDLE), patch(
MOCK_LOAD, return_value=mock_data
):
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(