|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
5 | 5 | import os
|
6 |
| -from typing import Any, cast |
| 6 | +from typing import TYPE_CHECKING, Any, Iterator, AsyncIterator, cast |
7 | 7 |
|
8 | 8 | import pytest
|
9 | 9 |
|
10 | 10 | from finch import Finch, AsyncFinch
|
11 | 11 | from finch.types import CreateAccessTokenResponse
|
12 | 12 | from tests.utils import assert_matches_type
|
13 | 13 |
|
| 14 | +if TYPE_CHECKING: |
| 15 | + from _pytest.fixtures import FixtureRequest |
| 16 | + |
14 | 17 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
|
| 18 | +client_id = "00000000-0000-0000-0000-000000000000" |
| 19 | +client_secret = "TEST" |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture(scope="module") |
| 23 | +def client(request: FixtureRequest) -> Iterator[Finch]: |
| 24 | + strict = getattr(request, "param", True) |
| 25 | + if not isinstance(strict, bool): |
| 26 | + raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}") |
| 27 | + |
| 28 | + with Finch( |
| 29 | + base_url=base_url, client_id=client_id, client_secret=client_secret, _strict_response_validation=strict |
| 30 | + ) as client: |
| 31 | + yield client |
| 32 | + |
| 33 | + |
| 34 | +@pytest.fixture(scope="module") |
| 35 | +async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncFinch]: |
| 36 | + strict = getattr(request, "param", True) |
| 37 | + if not isinstance(strict, bool): |
| 38 | + raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}") |
| 39 | + |
| 40 | + async with AsyncFinch( |
| 41 | + base_url=base_url, client_id=client_id, client_secret=client_secret, _strict_response_validation=strict |
| 42 | + ) as client: |
| 43 | + yield client |
15 | 44 |
|
16 | 45 |
|
17 | 46 | class TestAccessTokens:
|
|
0 commit comments