async def test_full_flow_implementation(
        hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
    """Test registering an integration and finishing flow works."""
    aioclient_mock.get(
        f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}"
        f"://{FIXTURE_USER_INPUT[CONF_HOST]}"
        f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status",
        json={"version": "v0.99.0"},
        headers={"Content-Type": CONTENT_TYPE_JSON},
    )

    flow = config_flow.AdGuardHomeFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=None)
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "user"

    result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT)
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == FIXTURE_USER_INPUT[CONF_HOST]
    assert result["data"][CONF_HOST] == FIXTURE_USER_INPUT[CONF_HOST]
    assert result["data"][CONF_PASSWORD] == FIXTURE_USER_INPUT[CONF_PASSWORD]
    assert result["data"][CONF_PORT] == FIXTURE_USER_INPUT[CONF_PORT]
    assert result["data"][CONF_SSL] == FIXTURE_USER_INPUT[CONF_SSL]
    assert result["data"][CONF_USERNAME] == FIXTURE_USER_INPUT[CONF_USERNAME]
    assert result["data"][CONF_VERIFY_SSL] == FIXTURE_USER_INPUT[
        CONF_VERIFY_SSL]
Exemplo n.º 2
0
async def test_full_flow_implementation(hass, aioclient_mock):
    """Test registering an integration and finishing flow works."""
    aioclient_mock.get(
        "{}://{}:{}/control/status".format(
            'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http',
            FIXTURE_USER_INPUT[CONF_HOST],
            FIXTURE_USER_INPUT[CONF_PORT],
        ),
        json={'version': '1.0'},
        headers={'Content-Type': 'application/json'},
    )

    flow = config_flow.AdGuardHomeFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=None)
    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'user'

    result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT)
    assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result['title'] == FIXTURE_USER_INPUT[CONF_HOST]
    assert result['data'][CONF_HOST] == FIXTURE_USER_INPUT[CONF_HOST]
    assert result['data'][CONF_PASSWORD] == FIXTURE_USER_INPUT[CONF_PASSWORD]
    assert result['data'][CONF_PORT] == FIXTURE_USER_INPUT[CONF_PORT]
    assert result['data'][CONF_SSL] == FIXTURE_USER_INPUT[CONF_SSL]
    assert result['data'][CONF_USERNAME] == FIXTURE_USER_INPUT[CONF_USERNAME]
    assert (
        result['data'][CONF_VERIFY_SSL] == FIXTURE_USER_INPUT[CONF_VERIFY_SSL])
Exemplo n.º 3
0
async def test_full_flow_implementation(hass, aioclient_mock):
    """Test registering an integration and finishing flow works."""
    aioclient_mock.get(
        "{}://{}:{}/control/status".format(
            "https" if FIXTURE_USER_INPUT[CONF_SSL] else "http",
            FIXTURE_USER_INPUT[CONF_HOST],
            FIXTURE_USER_INPUT[CONF_PORT],
        ),
        json={"version": "1.0"},
        headers={"Content-Type": "application/json"},
    )

    flow = config_flow.AdGuardHomeFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=None)
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "user"

    result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT)
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == FIXTURE_USER_INPUT[CONF_HOST]
    assert result["data"][CONF_HOST] == FIXTURE_USER_INPUT[CONF_HOST]
    assert result["data"][CONF_PASSWORD] == FIXTURE_USER_INPUT[CONF_PASSWORD]
    assert result["data"][CONF_PORT] == FIXTURE_USER_INPUT[CONF_PORT]
    assert result["data"][CONF_SSL] == FIXTURE_USER_INPUT[CONF_SSL]
    assert result["data"][CONF_USERNAME] == FIXTURE_USER_INPUT[CONF_USERNAME]
    assert result["data"][CONF_VERIFY_SSL] == FIXTURE_USER_INPUT[
        CONF_VERIFY_SSL]
Exemplo n.º 4
0
async def test_outdated_adguard_version(hass, aioclient_mock):
    """Test we show abort when connecting with unsupported AdGuard version."""
    aioclient_mock.get(
        "{}://{}:{}/control/status".format(
            "https" if FIXTURE_USER_INPUT[CONF_SSL] else "http",
            FIXTURE_USER_INPUT[CONF_HOST],
            FIXTURE_USER_INPUT[CONF_PORT],
        ),
        json={"version": "v0.98.0"},
        headers={"Content-Type": "application/json"},
    )

    flow = config_flow.AdGuardHomeFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=None)
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "user"

    result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT)
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
    assert result["reason"] == "adguard_home_outdated"
    assert result["description_placeholders"] == {
        "current_version": "v0.98.0",
        "minimal_version": MIN_ADGUARD_HOME_VERSION,
    }
async def test_show_authenticate_form(hass: HomeAssistant) -> None:
    """Test that the setup form is served."""
    flow = config_flow.AdGuardHomeFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=None)

    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "user"
Exemplo n.º 6
0
async def test_show_authenticate_form(hass):
    """Test that the setup form is served."""
    flow = config_flow.AdGuardHomeFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=None)

    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'user'
Exemplo n.º 7
0
async def test_connection_error(hass, aioclient_mock):
    """Test we show user form on AdGuard Home connection error."""
    aioclient_mock.get(
        f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}"
        f"://{FIXTURE_USER_INPUT[CONF_HOST]}"
        f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status",
        exc=aiohttp.ClientError,
    )

    flow = config_flow.AdGuardHomeFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT)

    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["step_id"] == "user"
    assert result["errors"] == {"base": "cannot_connect"}
Exemplo n.º 8
0
async def test_connection_error(hass, aioclient_mock):
    """Test we show user form on AdGuard Home connection error."""
    aioclient_mock.get(
        "{}://{}:{}/control/status".format(
            'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http',
            FIXTURE_USER_INPUT[CONF_HOST],
            FIXTURE_USER_INPUT[CONF_PORT],
        ),
        exc=aiohttp.ClientError,
    )

    flow = config_flow.AdGuardHomeFlowHandler()
    flow.hass = hass
    result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT)

    assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert result['step_id'] == 'user'
    assert result['errors'] == {'base': 'connection_error'}