hass-core/tests/components/waze_travel_time/conftest.py
Raman Gupta 5305d083ec
Add config flow for Waze Travel Time (#43419)
* Add config flow for Waze Travel Time

* update translations

* setup entry is async

* fix update logic during setup

* support old config method in the interim

* fix requirements

* fix requirements

* add abort string

* changes based on @bdraco review

* fix tests

* add device identifier

* Update homeassistant/components/waze_travel_time/__init__.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* fix tests

* Update homeassistant/components/waze_travel_time/sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* log warning for deprecation message

* PR feedback

* fix tests and bugs

* re-add name to config schema to avoid breaking change

* handle if we get name from config in entry title

* fix name logic

* always set up options with defaults

* Update homeassistant/components/waze_travel_time/sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update config_flow.py

* Update sensor.py

* handle options updates by getting options on every update

* patch library instead of sensor

* fixes and make sure first update writes the state

* validate config entry data during config flow and entry setup

* fix input parameters

* fix tests

* invert if statement

* remove unnecessary else

* exclude helpers from coverage

* remove async_setup because it's no longer needed

* fix patch statements

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-04-05 19:25:52 -04:00

57 lines
1.7 KiB
Python

"""Fixtures for Waze Travel Time tests."""
from unittest.mock import patch
from WazeRouteCalculator import WRCError
import pytest
@pytest.fixture(name="skip_notifications", autouse=True)
def skip_notifications_fixture():
"""Skip notification calls."""
with patch("homeassistant.components.persistent_notification.async_create"), patch(
"homeassistant.components.persistent_notification.async_dismiss"
):
yield
@pytest.fixture(name="validate_config_entry")
def validate_config_entry_fixture():
"""Return valid config entry."""
with patch(
"homeassistant.components.waze_travel_time.helpers.WazeRouteCalculator"
) as mock_wrc:
obj = mock_wrc.return_value
obj.calc_all_routes_info.return_value = None
yield
@pytest.fixture(name="bypass_setup")
def bypass_setup_fixture():
"""Bypass entry setup."""
with patch(
"homeassistant.components.waze_travel_time.async_setup_entry",
return_value=True,
):
yield
@pytest.fixture(name="mock_update")
def mock_update_fixture():
"""Mock an update to the sensor."""
with patch(
"homeassistant.components.waze_travel_time.sensor.WazeRouteCalculator.calc_all_routes_info",
return_value={"My route": (150, 300)},
):
yield
@pytest.fixture(name="invalidate_config_entry")
def invalidate_config_entry_fixture():
"""Return invalid config entry."""
with patch(
"homeassistant.components.waze_travel_time.helpers.WazeRouteCalculator"
) as mock_wrc:
obj = mock_wrc.return_value
obj.calc_all_routes_info.return_value = {}
obj.calc_all_routes_info.side_effect = WRCError("test")
yield