| 1 |
"""Fixtures for tests.""" |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from unittest.mock import AsyncMock, MagicMock |
| 6 |
|
| 7 |
import pytest |
| 8 |
from tenacity import wait_none |
| 9 |
|
| 10 |
from nice_go._aws_cognito_authenticator import AwsCognitoAuthenticator |
| 11 |
from nice_go._ws_client import WebSocketClient |
| 12 |
from nice_go.nice_go_api import NiceGOApi |
| 13 |
|
| 14 |
|
| 15 |
@pytest.fixture |
| 16 |
def mock_api() -> NiceGOApi: |
| 17 |
"""Mocked NiceGOApi instance.""" |
| 18 |
api = NiceGOApi() |
| 19 |
api._session = AsyncMock() |
| 20 |
api._device_ws = AsyncMock() |
| 21 |
api._endpoints = { |
| 22 |
"GraphQL": { |
| 23 |
"device": { |
| 24 |
"wss": "wss://test", |
| 25 |
"https": "https://test", |
| 26 |
}, |
| 27 |
"events": { |
| 28 |
"wss": "wss://test", |
| 29 |
"https": "https://test", |
| 30 |
}, |
| 31 |
}, |
| 32 |
} |
| 33 |
api.connect.retry.wait = wait_none() |
| 34 |
return api |
| 35 |
|
| 36 |
|
| 37 |
@pytest.fixture |
| 38 |
def mock_ws_client() -> WebSocketClient: |
| 39 |
"""Mocked WebSocketClient instance.""" |
| 40 |
ws = WebSocketClient(client_session=MagicMock()) |
| 41 |
ws.ws = AsyncMock(closed=False) |
| 42 |
ws._dispatch = MagicMock() |
| 43 |
ws.id_token = "test_token" |
| 44 |
ws.host = "test_host" |
| 45 |
return ws |
| 46 |
|
| 47 |
|
| 48 |
@pytest.fixture |
| 49 |
def mock_authenticator() -> AwsCognitoAuthenticator: |
| 50 |
"""Mocked AwsCognitoAuthenticator instance.""" |
| 51 |
return AwsCognitoAuthenticator( |
| 52 |
"test_region", |
| 53 |
"test_client_id", |
| 54 |
"test_pool_id", |
| 55 |
"test_identity_pool_id", |
| 56 |
) |