Change name of Forecast.io platform to Dark Sky (#3698)
* Rename Forecast.io platform to Dark Sky * Upgrade to python-forecastio to 1.3.5 * Update to reflect name change (Forecast.io -> Dark Sky) * Rename forecast to darksky
This commit is contained in:
1 parent
cb3a78b330
commit
a94571fd10
5 files changed
+38
-32
No files matched your search
+17
-11
@@ -1,4 +1,4 @@
|
||||
"""The tests for the forecast.io platform."""
|
||||
"""The tests for the Dark Sky platform."""
|
||||
import re
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
@@ -8,13 +8,14 @@ from requests.exceptions import HTTPError
|
||||
import requests_mock
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.components.sensor import forecast
|
||||
from homeassistant.components.sensor import darksky
|
||||
from homeassistant.bootstrap import setup_component
|
||||
|
||||
from tests.common import load_fixture, get_test_home_assistant
|
||||
|
||||
|
||||
class TestForecastSetup(unittest.TestCase):
|
||||
"""Test the forecast.io platform."""
|
||||
class TestDarkSkySetup(unittest.TestCase):
|
||||
"""Test the Dark Sky platform."""
|
||||
|
||||
def setUp(self):
|
||||
"""Initialize values for this testcase class."""
|
||||
@@ -30,33 +31,38 @@ class TestForecastSetup(unittest.TestCase):
|
||||
self.hass.config.latitude = self.lat
|
||||
self.hass.config.longitude = self.lon
|
||||
|
||||
def test_setup_with_config(self):
|
||||
"""Test the platform setup with configuration."""
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, 'sensor', {'darksky': self.config}))
|
||||
|
||||
def test_setup_no_latitude(self):
|
||||
"""Test that the component is not loaded without required config."""
|
||||
self.hass.config.latitude = None
|
||||
self.assertFalse(forecast.setup_platform(self.hass, {}, MagicMock()))
|
||||
self.assertFalse(darksky.setup_platform(self.hass, {}, MagicMock()))
|
||||
|
||||
@patch('forecastio.api.get_forecast')
|
||||
def test_setup_bad_api_key(self, mock_get_forecast):
|
||||
"""Test for handling a bad API key."""
|
||||
# The forecast API wrapper that we use raises an HTTP error
|
||||
# The Dark Sky API wrapper that we use raises an HTTP error
|
||||
# when you try to use a bad (or no) API key.
|
||||
url = 'https://api.forecast.io/forecast/{}/{},{}?units=auto'.format(
|
||||
url = 'https://api.darksky.net/forecast/{}/{},{}?units=auto'.format(
|
||||
self.key, str(self.lat), str(self.lon)
|
||||
)
|
||||
msg = '400 Client Error: Bad Request for url: {}'.format(url)
|
||||
mock_get_forecast.side_effect = HTTPError(msg,)
|
||||
|
||||
response = forecast.setup_platform(self.hass, self.config, MagicMock())
|
||||
response = darksky.setup_platform(self.hass, self.config, MagicMock())
|
||||
self.assertFalse(response)
|
||||
|
||||
@requests_mock.Mocker()
|
||||
@patch('forecastio.api.get_forecast', wraps=forecastio.api.get_forecast)
|
||||
def test_setup(self, m, mock_get_forecast):
|
||||
"""Test for successfully setting up the forecast.io platform."""
|
||||
uri = ('https://api.forecast.io\/forecast\/(\w+)\/'
|
||||
uri = ('https://api.darksky.net\/forecast\/(\w+)\/'
|
||||
'(-?\d+\.?\d*),(-?\d+\.?\d*)')
|
||||
m.get(re.compile(uri),
|
||||
text=load_fixture('forecast.json'))
|
||||
forecast.setup_platform(self.hass, self.config, MagicMock())
|
||||
text=load_fixture('darksky.json'))
|
||||
darksky.setup_platform(self.hass, self.config, MagicMock())
|
||||
self.assertTrue(mock_get_forecast.called)
|
||||
self.assertEqual(mock_get_forecast.call_count, 1)
|
||||
Reference in new issue
Block a user