This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+23 -20
View File
@@ -5,7 +5,11 @@ from pyopenuv.errors import OpenUvError
from homeassistant import data_entry_flow
from homeassistant.components.openuv import DOMAIN, config_flow
from homeassistant.const import (
CONF_API_KEY, CONF_ELEVATION, CONF_LATITUDE, CONF_LONGITUDE)
CONF_API_KEY,
CONF_ELEVATION,
CONF_LATITUDE,
CONF_LONGITUDE,
)
from tests.common import MockConfigEntry, MockDependency, mock_coro
@@ -19,7 +23,7 @@ def uv_index_response():
@pytest.fixture
def mock_pyopenuv(uv_index_response):
"""Mock the pyopenuv library."""
with MockDependency('pyopenuv') as mock_pyopenuv_:
with MockDependency("pyopenuv") as mock_pyopenuv_:
mock_pyopenuv_.Client().uv_index.return_value = uv_index_response
yield mock_pyopenuv_
@@ -27,7 +31,7 @@ def mock_pyopenuv(uv_index_response):
async def test_duplicate_error(hass):
"""Test that errors are shown when duplicates are added."""
conf = {
CONF_API_KEY: '12345abcde',
CONF_API_KEY: "12345abcde",
CONF_ELEVATION: 59.1234,
CONF_LATITUDE: 39.128712,
CONF_LONGITUDE: -104.9812612,
@@ -38,15 +42,14 @@ async def test_duplicate_error(hass):
flow.hass = hass
result = await flow.async_step_user(user_input=conf)
assert result['errors'] == {CONF_LATITUDE: 'identifier_exists'}
assert result["errors"] == {CONF_LATITUDE: "identifier_exists"}
@pytest.mark.parametrize(
'uv_index_response', [mock_coro(exception=OpenUvError)])
@pytest.mark.parametrize("uv_index_response", [mock_coro(exception=OpenUvError)])
async def test_invalid_api_key(hass, mock_pyopenuv):
"""Test that an invalid API key throws an error."""
conf = {
CONF_API_KEY: '12345abcde',
CONF_API_KEY: "12345abcde",
CONF_ELEVATION: 59.1234,
CONF_LATITUDE: 39.128712,
CONF_LONGITUDE: -104.9812612,
@@ -56,7 +59,7 @@ async def test_invalid_api_key(hass, mock_pyopenuv):
flow.hass = hass
result = await flow.async_step_user(user_input=conf)
assert result['errors'] == {CONF_API_KEY: 'invalid_api_key'}
assert result["errors"] == {CONF_API_KEY: "invalid_api_key"}
async def test_show_form(hass):
@@ -66,14 +69,14 @@ async def test_show_form(hass):
result = await flow.async_step_user(user_input=None)
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'user'
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
async def test_step_import(hass, mock_pyopenuv):
"""Test that the import step works."""
conf = {
CONF_API_KEY: '12345abcde',
CONF_API_KEY: "12345abcde",
CONF_ELEVATION: 59.1234,
CONF_LATITUDE: 39.128712,
CONF_LONGITUDE: -104.9812612,
@@ -83,10 +86,10 @@ async def test_step_import(hass, mock_pyopenuv):
flow.hass = hass
result = await flow.async_step_import(import_config=conf)
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['title'] == '39.128712, -104.9812612'
assert result['data'] == {
CONF_API_KEY: '12345abcde',
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "39.128712, -104.9812612"
assert result["data"] == {
CONF_API_KEY: "12345abcde",
CONF_ELEVATION: 59.1234,
CONF_LATITUDE: 39.128712,
CONF_LONGITUDE: -104.9812612,
@@ -96,7 +99,7 @@ async def test_step_import(hass, mock_pyopenuv):
async def test_step_user(hass, mock_pyopenuv):
"""Test that the user step works."""
conf = {
CONF_API_KEY: '12345abcde',
CONF_API_KEY: "12345abcde",
CONF_ELEVATION: 59.1234,
CONF_LATITUDE: 39.128712,
CONF_LONGITUDE: -104.9812612,
@@ -106,10 +109,10 @@ async def test_step_user(hass, mock_pyopenuv):
flow.hass = hass
result = await flow.async_step_user(user_input=conf)
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['title'] == '39.128712, -104.9812612'
assert result['data'] == {
CONF_API_KEY: '12345abcde',
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "39.128712, -104.9812612"
assert result["data"] == {
CONF_API_KEY: "12345abcde",
CONF_ELEVATION: 59.1234,
CONF_LATITUDE: 39.128712,
CONF_LONGITUDE: -104.9812612,