|
| 1 | +from typing import Dict, Optional |
1 | 2 | from json import load, loads |
2 | 3 | from typing import Sequence |
3 | 4 | from unittest.mock import PropertyMock |
4 | | - |
| 5 | +from lumapps.api import __version__ |
5 | 6 | from httpx import HTTPStatusError |
6 | | -from pytest import fixture, raises |
| 7 | +from pytest import fixture, raises, mark |
7 | 8 |
|
8 | | -from lumapps.api.base_client import BaseClient |
| 9 | +from lumapps.api.base_client import BaseClient, fetch_access_token |
| 10 | +from lumapps.api.client import LumAppsClient |
9 | 11 | from lumapps.api.errors import BadCallError, BaseClientError |
10 | 12 | from lumapps.api.utils import ( |
11 | 13 | FILTERS, |
@@ -378,3 +380,48 @@ def get(*args, **kwargs): |
378 | 380 | def test_get_new_client_as_using_dwd(cli: BaseClient): |
379 | 381 | with raises(NotImplementedError): |
380 | 382 | cli. get_new_client_as_using_dwd( "[email protected]") |
| 383 | + |
| 384 | +@mark.parametrize("cell, api_info, expected_exception", [ |
| 385 | + ("go-cell-002", {"base_url": "https://go-cell-002.api.lumapps.com/"}, None), |
| 386 | + ("ms-cell-001", {"base_url": "https://ms-cell-001.api.lumapps.com/"}, None), |
| 387 | + ("go-cell-003", {"base_url": "https://go-cell-003.beta.api.lumapps.com/"}, None), |
| 388 | + ("go-cell-004", {"base_url": "https://go-cell-004.api.lumapps.com/"}, BaseClientError), |
| 389 | + ("go-cell-001", {"base_url": "http://localhost/sdk"}, BaseClientError), |
| 390 | + ("go-cell-001", {}, BaseClientError), |
| 391 | +]) |
| 392 | +def test_create_client(cell: str, api_info: Dict[str, str], expected_exception: Optional[Exception]) -> None: |
| 393 | + # Given / When |
| 394 | + if expected_exception: |
| 395 | + with raises(expected_exception): |
| 396 | + LumAppsClient( |
| 397 | + "123", |
| 398 | + None, |
| 399 | + api_info=api_info, |
| 400 | + auth_info={"client_id": "abc", "client_secret": "789"}, |
| 401 | + ) |
| 402 | + return |
| 403 | + else: |
| 404 | + client = LumAppsClient( |
| 405 | + "123", |
| 406 | + None, |
| 407 | + api_info=api_info, |
| 408 | + auth_info={"client_id": "abc", "client_secret": "789"}, |
| 409 | + ) |
| 410 | + |
| 411 | + # Then |
| 412 | + assert client._headers == { |
| 413 | + "x-lumapps-analytics": "off", |
| 414 | + "User-Agent": f"lumapps-sdk {__version__}", |
| 415 | + "authorization": "Bearer None" |
| 416 | + } |
| 417 | + assert client.base_url == api_info["base_url"].rstrip("/") |
| 418 | + if ".beta." in client.base_url: |
| 419 | + assert client._discovery_url == ( |
| 420 | + "https://storage.googleapis.com/prod-frontend-static-assets/api-discovery/" |
| 421 | + f"lumapps-discovery-beta-{cell}.json" |
| 422 | + ) |
| 423 | + else: |
| 424 | + assert client._discovery_url == ( |
| 425 | + "https://storage.googleapis.com/prod-frontend-static-assets/api-discovery/" |
| 426 | + f"lumapps-discovery-{cell}.json" |
| 427 | + ) |
0 commit comments