home-assistant/tests/components/sensor/test_london_underground.py
Robin 865865ca0f Add london_underground (#8272)
* Add tube_state

Add tube_state sensor

* Final cleanup

* Make corrections

Correct PLATFORM_SCHEMA

* Fix space

* Make test pass

* Correct format of test

Test still failing, don’t understand why

* correct description

* Make test pass

Preferred method below returns None

state = self.hass.states.get('sensor.london_overground')

* Format for hound

* indent

* Make requested changes to test, not working

Test fails with:

AssertionError: assert 0 > 0
where 0 = len([])

Surely I need tube_state.setup_platform ?

* Fixed test

Config was wrong

* Change component name to london_tube

* Update name to london_underground

Make consistent

* cleanup
2017-07-02 11:32:38 -07:00

38 lines
1.2 KiB
Python

"""The tests for the tube_state platform."""
import unittest
import requests_mock
from homeassistant.components.sensor.london_underground import CONF_LINE, URL
from homeassistant.setup import setup_component
from tests.common import load_fixture, get_test_home_assistant
VALID_CONFIG = {
'platform': 'london_underground',
CONF_LINE: [
'London Overground',
]
}
class TestLondonTubeSensor(unittest.TestCase):
"""Test the tube_state platform."""
def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
@requests_mock.Mocker()
def test_setup(self, mock_req):
"""Test for operational tube_state sensor with proper attributes."""
mock_req.get(URL, text=load_fixture('london_underground.json'))
self.assertTrue(
setup_component(self.hass, 'sensor', {'sensor': self.config}))
state = self.hass.states.get('sensor.london_overground')
assert state.state == 'Minor Delays'
assert state.attributes.get('Description') == 'something'