1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Move elevation to core config and clean up HTTP mocking in tests (#2378)

* Stick version numbers

* Move elevation to core config

* Migrate forecast test to requests-mock

* Migrate YR tests to requests-mock

* Add requests_mock to requirements_test.txt

* Move conf code from bootstrap to config

* More config fixes

* Fix some more issues

* Add test for set config and failing auto detect
This commit is contained in:
Paulus Schoutsen
2016-06-27 09:02:45 -07:00
committed by GitHub
parent dc75b28b90
commit 6714392e9c
26 changed files with 1779 additions and 337 deletions

View File

@@ -1,39 +1,40 @@
"""The tests for the Yr sensor platform."""
from datetime import datetime
from unittest import TestCase
from unittest.mock import patch
import pytest
import requests_mock
from homeassistant.bootstrap import _setup_component
import homeassistant.util.dt as dt_util
from tests.common import get_test_home_assistant
from tests.common import get_test_home_assistant, load_fixture
@pytest.mark.usefixtures('betamax_session')
class TestSensorYr:
class TestSensorYr(TestCase):
"""Test the Yr sensor."""
def setup_method(self, method):
def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.config.latitude = 32.87336
self.hass.config.longitude = 117.22743
def teardown_method(self, method):
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
def test_default_setup(self, betamax_session):
@requests_mock.Mocker()
def test_default_setup(self, m):
"""Test the default setup."""
m.get('http://api.yr.no/weatherapi/locationforecast/1.9/',
text=load_fixture('yr.no.json'))
now = datetime(2016, 6, 9, 1, tzinfo=dt_util.UTC)
with patch('homeassistant.components.sensor.yr.requests.Session',
return_value=betamax_session):
with patch('homeassistant.components.sensor.yr.dt_util.utcnow',
return_value=now):
assert _setup_component(self.hass, 'sensor', {
'sensor': {'platform': 'yr',
'elevation': 0}})
with patch('homeassistant.components.sensor.yr.dt_util.utcnow',
return_value=now):
assert _setup_component(self.hass, 'sensor', {
'sensor': {'platform': 'yr',
'elevation': 0}})
state = self.hass.states.get('sensor.yr_symbol')
@@ -41,23 +42,24 @@ class TestSensorYr:
assert state.state.isnumeric()
assert state.attributes.get('unit_of_measurement') is None
def test_custom_setup(self, betamax_session):
@requests_mock.Mocker()
def test_custom_setup(self, m):
"""Test a custom setup."""
m.get('http://api.yr.no/weatherapi/locationforecast/1.9/',
text=load_fixture('yr.no.json'))
now = datetime(2016, 6, 9, 1, tzinfo=dt_util.UTC)
with patch('homeassistant.components.sensor.yr.requests.Session',
return_value=betamax_session):
with patch('homeassistant.components.sensor.yr.dt_util.utcnow',
return_value=now):
assert _setup_component(self.hass, 'sensor', {
'sensor': {'platform': 'yr',
'elevation': 0,
'monitored_conditions': [
'pressure',
'windDirection',
'humidity',
'fog',
'windSpeed']}})
with patch('homeassistant.components.sensor.yr.dt_util.utcnow',
return_value=now):
assert _setup_component(self.hass, 'sensor', {
'sensor': {'platform': 'yr',
'elevation': 0,
'monitored_conditions': [
'pressure',
'windDirection',
'humidity',
'fog',
'windSpeed']}})
state = self.hass.states.get('sensor.yr_pressure')
assert 'hPa' == state.attributes.get('unit_of_measurement')