Added unit test to the Yahoo Finance sensor (#3943)
This commit is contained in:
1 parent
2b37b4251b
commit
fee01fcccc
3 files changed
+126
-1
No files matched your search
@@ -0,0 +1,41 @@
|
||||
"""The tests for the Yahoo Finance platform."""
|
||||
import json
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import homeassistant.components.sensor as sensor
|
||||
from homeassistant.bootstrap import setup_component
|
||||
from tests.common import (
|
||||
get_test_home_assistant, load_fixture, assert_setup_component)
|
||||
|
||||
VALID_CONFIG = {
|
||||
'platform': 'yahoo_finance',
|
||||
'symbol': 'YHOO'
|
||||
}
|
||||
|
||||
|
||||
class TestYahooFinanceSetup(unittest.TestCase):
|
||||
"""Test the Yahoo Finance 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()
|
||||
|
||||
@patch('yahoo_finance.Base._request',
|
||||
return_value=json.loads(load_fixture('yahoo_finance.json')))
|
||||
def test_default_setup(self, m): # pylint: disable=invalid-name
|
||||
"""Test the default setup."""
|
||||
with assert_setup_component(1, sensor.DOMAIN):
|
||||
assert setup_component(self.hass, sensor.DOMAIN, {
|
||||
'sensor': VALID_CONFIG})
|
||||
|
||||
state = self.hass.states.get('sensor.yahoo_stock')
|
||||
self.assertEqual("41.69", state.attributes.get('open'))
|
||||
self.assertEqual("41.79", state.attributes.get('prev_close'))
|
||||
self.assertEqual("YHOO", state.attributes.get('unit_of_measurement'))
|
||||
Reference in new issue
Block a user