StarLine integration (#27197)
* Device Tracker works * Device Tracker works * Binary Sensor * Sensor * Lock * Switch and service * New switches * Update interval options * WIP * Translation errors * Check online state * WIP * Move to aiohttp * Some checks * CI * CI * .coveragerc * Black * icon_for_signal_level test * update_interval renamed to scan_interval * async logic * Fix cookie read * Requirement starline * Reformat * Requirements updated * ConfigEntryNotReady * Requirement starline * Lint fix * Requirement starline * available status * Translations * Expiration to config * CI * Linter fix * Small renaming * Update slnet token * Starline version bump * Fix updates * Black * Small fix * Removed unused fields * CI * set_scan_interval service * deps updated * Horn switch * Starline lib updated * Starline lib updated * Black * Support multiple integrations * Review * async_will_remove_from_hass * Deps updated * Test config flow * Requirements * CI * Review * Review * Review * Review * Review * CI * pylint fix * Review * Support "mayak" devices * Icons removed * Removed options_flow * Removed options_flow test * Removed options_flow test
This commit is contained in:
1 parent
c21650473a
commit
a37260faa9
23 files changed
+1179
No files matched your search
@@ -0,0 +1 @@
|
||||
"""Tests for the StarLine component."""
|
||||
@@ -0,0 +1,126 @@
|
||||
"""Tests for StarLine config flow."""
|
||||
import requests_mock
|
||||
from homeassistant.components.starline import config_flow
|
||||
|
||||
TEST_APP_ID = "666"
|
||||
TEST_APP_SECRET = "appsecret"
|
||||
TEST_APP_CODE = "appcode"
|
||||
TEST_APP_TOKEN = "apptoken"
|
||||
TEST_APP_SLNET = "slnettoken"
|
||||
TEST_APP_SLID = "slidtoken"
|
||||
TEST_APP_UID = "123"
|
||||
TEST_APP_USERNAME = "sluser"
|
||||
TEST_APP_PASSWORD = "slpassword"
|
||||
|
||||
|
||||
async def test_flow_works(hass):
|
||||
"""Test that config flow works."""
|
||||
with requests_mock.Mocker() as mock:
|
||||
mock.get(
|
||||
"https://id.starline.ru/apiV3/application/getCode/",
|
||||
text='{"state": 1, "desc": {"code": "' + TEST_APP_CODE + '"}}',
|
||||
)
|
||||
mock.get(
|
||||
"https://id.starline.ru/apiV3/application/getToken/",
|
||||
text='{"state": 1, "desc": {"token": "' + TEST_APP_TOKEN + '"}}',
|
||||
)
|
||||
mock.post(
|
||||
"https://id.starline.ru/apiV3/user/login/",
|
||||
text='{"state": 1, "desc": {"user_token": "' + TEST_APP_SLID + '"}}',
|
||||
)
|
||||
mock.post(
|
||||
"https://developer.starline.ru/json/v2/auth.slid",
|
||||
text='{"code": 200, "user_id": "' + TEST_APP_UID + '"}',
|
||||
cookies={"slnet": TEST_APP_SLNET},
|
||||
)
|
||||
mock.get(
|
||||
"https://developer.starline.ru/json/v2/user/{}/user_info".format(
|
||||
TEST_APP_UID
|
||||
),
|
||||
text='{"code": 200, "devices": [{"device_id": "123", "imei": "123", "alias": "123", "battery": "123", "ctemp": "123", "etemp": "123", "fw_version": "123", "gsm_lvl": "123", "phone": "123", "status": "1", "ts_activity": "123", "typename": "123", "balance": {}, "car_state": {}, "car_alr_state": {}, "functions": [], "position": {}}], "shared_devices": []}',
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN, context={"source": "user"}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "auth_app"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
config_flow.CONF_APP_ID: TEST_APP_ID,
|
||||
config_flow.CONF_APP_SECRET: TEST_APP_SECRET,
|
||||
},
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "auth_user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
config_flow.CONF_USERNAME: TEST_APP_USERNAME,
|
||||
config_flow.CONF_PASSWORD: TEST_APP_PASSWORD,
|
||||
},
|
||||
)
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "Application {}".format(TEST_APP_ID)
|
||||
|
||||
|
||||
async def test_step_auth_app_code_falls(hass):
|
||||
"""Test config flow works when app auth code fails."""
|
||||
with requests_mock.Mocker() as mock:
|
||||
mock.get(
|
||||
"https://id.starline.ru/apiV3/application/getCode/", text='{"state": 0}}'
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
context={"source": "user"},
|
||||
data={
|
||||
config_flow.CONF_APP_ID: TEST_APP_ID,
|
||||
config_flow.CONF_APP_SECRET: TEST_APP_SECRET,
|
||||
},
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "auth_app"
|
||||
assert result["errors"] == {"base": "error_auth_app"}
|
||||
|
||||
|
||||
async def test_step_auth_app_token_falls(hass):
|
||||
"""Test config flow works when app auth token fails."""
|
||||
with requests_mock.Mocker() as mock:
|
||||
mock.get(
|
||||
"https://id.starline.ru/apiV3/application/getCode/",
|
||||
text='{"state": 1, "desc": {"code": "' + TEST_APP_CODE + '"}}',
|
||||
)
|
||||
mock.get(
|
||||
"https://id.starline.ru/apiV3/application/getToken/", text='{"state": 0}'
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
context={"source": "user"},
|
||||
data={
|
||||
config_flow.CONF_APP_ID: TEST_APP_ID,
|
||||
config_flow.CONF_APP_SECRET: TEST_APP_SECRET,
|
||||
},
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "auth_app"
|
||||
assert result["errors"] == {"base": "error_auth_app"}
|
||||
|
||||
|
||||
async def test_step_auth_user_falls(hass):
|
||||
"""Test config flow works when user fails."""
|
||||
with requests_mock.Mocker() as mock:
|
||||
mock.post("https://id.starline.ru/apiV3/user/login/", text='{"state": 0}')
|
||||
flow = config_flow.StarlineFlowHandler()
|
||||
flow.hass = hass
|
||||
result = await flow.async_step_auth_user(
|
||||
user_input={
|
||||
config_flow.CONF_USERNAME: TEST_APP_USERNAME,
|
||||
config_flow.CONF_PASSWORD: TEST_APP_PASSWORD,
|
||||
}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "auth_user"
|
||||
assert result["errors"] == {"base": "error_auth_user"}
|
||||
Reference in new issue
Block a user