Use setup_component in tests v2 (#3537)

* setup_component - sun

* setup_component - updater

* setup_component - weblink
This commit is contained in:
Pascal Vizeli 2016-09-26 23:20:36 +02:00 committed by GitHub
parent ea4f49f0a0
commit cae10cfe26
4 changed files with 18 additions and 9 deletions

View file

@ -4,6 +4,7 @@ import unittest
from unittest.mock import patch
from datetime import timedelta, datetime
from homeassistant.bootstrap import setup_component
import homeassistant.core as ha
import homeassistant.util.dt as dt_util
import homeassistant.components.sun as sun
@ -31,7 +32,8 @@ class TestSun(unittest.TestCase):
def test_setting_rising(self):
"""Test retrieving sun setting and rising."""
sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
setup_component(self.hass, sun.DOMAIN, {
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
from astral import Astral
@ -71,7 +73,8 @@ class TestSun(unittest.TestCase):
def test_state_change(self):
"""Test if the state changes at next setting/rising."""
sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
setup_component(self.hass, sun.DOMAIN, {
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
if sun.is_on(self.hass):
test_state = sun.STATE_BELOW_HORIZON
@ -98,7 +101,8 @@ class TestSun(unittest.TestCase):
with patch('homeassistant.helpers.condition.dt_util.utcnow',
return_value=june):
assert sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
assert setup_component(self.hass, sun.DOMAIN, {
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
state = self.hass.states.get(sun.ENTITY_ID)

View file

@ -4,6 +4,7 @@ from unittest.mock import patch
import requests
from homeassistant.bootstrap import setup_component
from homeassistant.components import updater
import homeassistant.util.dt as dt_util
from tests.common import fire_time_changed, get_test_home_assistant
@ -31,7 +32,7 @@ class TestUpdater(unittest.TestCase):
mock_get_newest_version.return_value = NEW_VERSION
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION
self.assertTrue(updater.setup(self.hass, {
self.assertTrue(setup_component(self.hass, updater.DOMAIN, {
'updater': None
}))
@ -44,7 +45,7 @@ class TestUpdater(unittest.TestCase):
mock_get_newest_version.return_value = MOCK_CURRENT_VERSION
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION
self.assertTrue(updater.setup(self.hass, {
self.assertTrue(setup_component(self.hass, updater.DOMAIN, {
'updater': None
}))
@ -76,6 +77,6 @@ class TestUpdater(unittest.TestCase):
"""Test if the updater component is disabled on dev."""
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION + 'dev'
self.assertFalse(updater.setup(self.hass, {
self.assertFalse(setup_component(self.hass, updater.DOMAIN, {
'updater': None
}))

View file

@ -1,6 +1,7 @@
"""The tests for the weblink component."""
import unittest
from homeassistant.bootstrap import setup_component
from homeassistant.components import weblink
from homeassistant import bootstrap
@ -28,7 +29,7 @@ class TestComponentWeblink(unittest.TestCase):
def test_entities_get_created(self):
"""Test if new entity is created."""
self.assertTrue(weblink.setup(self.hass, {
self.assertTrue(setup_component(self.hass, weblink.DOMAIN, {
weblink.DOMAIN: {
'entities': [
{

View file

@ -6,6 +6,7 @@ from datetime import datetime, timedelta
from astral import Astral
from homeassistant.bootstrap import setup_component
import homeassistant.core as ha
from homeassistant.const import MATCH_ALL
from homeassistant.helpers.event import (
@ -186,7 +187,8 @@ class TestEventHelpers(unittest.TestCase):
# Setup sun component
self.hass.config.latitude = latitude
self.hass.config.longitude = longitude
sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
setup_component(self.hass, sun.DOMAIN, {
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
# Get next sunrise/sunset
astral = Astral()
@ -241,7 +243,8 @@ class TestEventHelpers(unittest.TestCase):
# Setup sun component
self.hass.config.latitude = latitude
self.hass.config.longitude = longitude
sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
setup_component(self.hass, sun.DOMAIN, {
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
# Get next sunrise/sunset
astral = Astral()