-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Stubs for Gigya * Fix mypy * Remove exceptions amends * Reset stubs
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Gigya client for authentication.""" | ||
import logging | ||
from typing import Dict | ||
|
||
from aiohttp import ClientSession | ||
|
||
from .const import CONF_GIGYA_APIKEY | ||
from .const import CONF_GIGYA_URL | ||
from renault_api.model import gigya as model | ||
from renault_api.model.gigya import GigyaGetAccountInfoData | ||
from renault_api.model.gigya import GigyaLoginSessionInfo | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class Gigya(object): | ||
"""Gigya client for authentication.""" | ||
|
||
def __init__( | ||
self, websession: ClientSession, locale_details: Dict[str, str] | ||
) -> None: | ||
"""Initialise Gigya.""" | ||
self._websession = websession | ||
|
||
self._api_key = locale_details[CONF_GIGYA_APIKEY] | ||
self._root_url = locale_details[CONF_GIGYA_URL] | ||
|
||
async def login(self, login_id: str, password: str) -> model.GigyaLoginResponse: | ||
"""POST to /accounts.login.""" | ||
return model.GigyaLoginResponse( | ||
0, | ||
None, | ||
GigyaLoginSessionInfo("cookieValue"), | ||
) | ||
|
||
async def get_account_info( | ||
self, login_token: str | ||
) -> model.GigyaGetAccountInfoResponse: | ||
"""POST to /accounts.getAccountInfo.""" | ||
return model.GigyaGetAccountInfoResponse( | ||
0, | ||
None, | ||
GigyaGetAccountInfoData("person-id"), | ||
) | ||
|
||
async def get_jwt(self, login_token: str) -> model.GigyaGetJWTResponse: | ||
"""POST to /accounts.getAccountInfo.""" | ||
return model.GigyaGetJWTResponse( | ||
0, | ||
None, | ||
"id_token", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Constants for the test suite fixtures.""" | ||
from renault_api.const import AVAILABLE_LOCALES | ||
from renault_api.const import CONF_GIGYA_URL | ||
|
||
|
||
TEST_LOCALE = "fr_FR" | ||
TEST_PASSWORD = "test_password" | ||
TEST_PERSON_ID = "person-id-1" | ||
TEST_USERNAME = "test@example.com" | ||
|
||
TEST_LOCALE_DETAILS = AVAILABLE_LOCALES[TEST_LOCALE] | ||
TEST_GIGYA_URL = TEST_LOCALE_DETAILS[CONF_GIGYA_URL] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Test cases for the Renault client API keys.""" | ||
import pytest | ||
from aiohttp.client import ClientSession | ||
from tests.const import TEST_LOCALE_DETAILS | ||
from tests.const import TEST_PASSWORD | ||
from tests.const import TEST_USERNAME | ||
|
||
from renault_api.gigya import Gigya | ||
|
||
|
||
@pytest.fixture | ||
def gigya(websession: ClientSession) -> Gigya: | ||
"""Fixture for testing Gigya.""" | ||
return Gigya(websession=websession, locale_details=TEST_LOCALE_DETAILS) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_login(gigya: Gigya) -> None: | ||
"""Test valid login response.""" | ||
login_response = await gigya.login(TEST_USERNAME, TEST_PASSWORD) | ||
assert login_response.get_session_cookie() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_login_failed(gigya: Gigya) -> None: | ||
"""Test failed login response.""" | ||
pass | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_person_id(gigya: Gigya) -> None: | ||
"""Test valid getAccountInfo response.""" | ||
login_token = "mock" | ||
account_info_response = await gigya.get_account_info(login_token) | ||
assert account_info_response.get_person_id() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_jwt_token(gigya: Gigya) -> None: | ||
"""Test valid getJWT response.""" | ||
login_token = "mock" | ||
jwt_response = await gigya.get_jwt(login_token) | ||
assert jwt_response.id_token |