Rewrite transport_nsw sensor tests to pytest tests (#41169)
* Improve transport_nsw sensor tests. * patch fix.
This commit is contained in:
parent
27c3ce16c3
commit
e64b8774ec
1 changed files with 14 additions and 25 deletions
|
@ -1,10 +1,7 @@
|
|||
"""The tests for the Transport NSW (AU) sensor platform."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
VALID_CONFIG = {
|
||||
"sensor": {
|
||||
|
@ -31,24 +28,16 @@ def get_departuresMock(_stop_id, route, destination, api_key):
|
|||
return data
|
||||
|
||||
|
||||
class TestRMVtransportSensor(unittest.TestCase):
|
||||
"""Test the TransportNSW sensor."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up things to run when tests begin."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.addCleanup(self.hass.stop)
|
||||
|
||||
@patch("TransportNSW.TransportNSW.get_departures", side_effect=get_departuresMock)
|
||||
def test_transportnsw_config(self, mock_get_departures):
|
||||
"""Test minimal TransportNSW configuration."""
|
||||
assert setup_component(self.hass, "sensor", VALID_CONFIG)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get("sensor.next_bus")
|
||||
assert state.state == "16"
|
||||
assert state.attributes["stop_id"] == "209516"
|
||||
assert state.attributes["route"] == "199"
|
||||
assert state.attributes["delay"] == 6
|
||||
assert state.attributes["real_time"] == "y"
|
||||
assert state.attributes["destination"] == "Palm Beach"
|
||||
assert state.attributes["mode"] == "Bus"
|
||||
@patch("TransportNSW.TransportNSW.get_departures", side_effect=get_departuresMock)
|
||||
async def test_transportnsw_config(mocked_get_departures, hass):
|
||||
"""Test minimal TransportNSW configuration."""
|
||||
assert await async_setup_component(hass, "sensor", VALID_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.next_bus")
|
||||
assert state.state == "16"
|
||||
assert state.attributes["stop_id"] == "209516"
|
||||
assert state.attributes["route"] == "199"
|
||||
assert state.attributes["delay"] == 6
|
||||
assert state.attributes["real_time"] == "y"
|
||||
assert state.attributes["destination"] == "Palm Beach"
|
||||
assert state.attributes["mode"] == "Bus"
|
||||
|
|
Loading…
Add table
Reference in a new issue