Example #1
0
async def test_init_country_only(websession: aiohttp.ClientSession) -> None:
    """Test initialisation with country only."""
    session = RenaultSession(
        websession=websession,
        country=TEST_COUNTRY,
    )
    assert await session._get_country()
    with pytest.raises(
            RenaultException,
            match="Credential `gigya-api-key` not found in credential cache.",
    ):
        assert await session._get_gigya_api_key()
    with pytest.raises(
            RenaultException,
            match="Credential `gigya-root-url` not found in credential cache.",
    ):
        assert await session._get_gigya_root_url()
    with pytest.raises(
            RenaultException,
            match=
            "Credential `kamereon-api-key` not found in credential cache.",
    ):
        assert await session._get_kamereon_api_key()
    with pytest.raises(
            RenaultException,
            match=
            "Credential `kamereon-root-url` not found in credential cache.",
    ):
        assert await session._get_kamereon_root_url()
Example #2
0
def session(websession: aiohttp.ClientSession) -> RenaultSession:
    """Fixture for testing RenaultSession."""
    return RenaultSession(
        websession=websession,
        country=TEST_COUNTRY,
        locale_details=TEST_LOCALE_DETAILS,
    )
Example #3
0
def get_logged_in_session(websession: aiohttp.ClientSession) -> RenaultSession:
    """Get initialised RenaultSession."""
    return RenaultSession(
        websession=websession,
        country=TEST_COUNTRY,
        locale_details=TEST_LOCALE_DETAILS,
        credential_store=get_logged_in_credential_store(),
    )
Example #4
0
async def test_init_locale_only(websession: aiohttp.ClientSession) -> None:
    """Test initialisation with locale only."""
    session = RenaultSession(
        websession=websession,
        locale=TEST_LOCALE,
    )
    assert await session._get_country()
    assert await session._get_gigya_api_key()
    assert await session._get_gigya_root_url()
    assert await session._get_kamereon_api_key()
    assert await session._get_kamereon_root_url()
Example #5
0
async def test_init_locale_details_only(
        websession: aiohttp.ClientSession) -> None:
    """Test initialisation with locale_details only."""
    session = RenaultSession(
        websession=websession,
        locale_details=TEST_LOCALE_DETAILS,
    )
    with pytest.raises(
            RenaultException,
            match="Credential `country` not found in credential cache.",
    ):
        assert await session._get_country()
    assert await session._get_gigya_api_key()
    assert await session._get_gigya_root_url()
    assert await session._get_kamereon_api_key()
    assert await session._get_kamereon_root_url()
Example #6
0
async def _create_renault_session(websession: aiohttp.ClientSession,
                                  ctx_data: Dict[str, Any]) -> RenaultSession:
    """Get RenaultClient for use by CLI."""
    credential_store: CredentialStore = ctx_data["credential_store"]
    locale = ctx_data.get("locale")
    if not locale:
        locale = await get_locale(websession, ctx_data)

    country = locale[-2:]
    locale_details = await get_api_keys(locale=locale, websession=websession)
    return RenaultSession(
        websession=websession,
        locale=locale,
        country=country,
        locale_details=locale_details,
        credential_store=credential_store,
    )