Skip to content

Commit 083f0b5

Browse files
committed
feat: clients added
1 parent ed168d0 commit 083f0b5

3 files changed

Lines changed: 54 additions & 6 deletions

File tree

tests/acceptance/clients.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Service client factories for acceptance tests.
2+
3+
Centralised here so that adding support for a new service in tests is
4+
just one new fixture line rather than copying provider/auth setup.
5+
6+
To add a client for a new service:
7+
8+
1. Add a fixture in your test's ``conftest.py`` (typically alongside the
9+
test files, e.g. ``tests/acceptance/services/<svc>/conftest.py``)::
10+
11+
from tests.acceptance.clients import make_service_client
12+
13+
@pytest.fixture
14+
def dns_client(provider):
15+
return make_service_client(provider, "dns")
16+
17+
2. Use it in tests like any other fixture::
18+
19+
def test_something(dns_client):
20+
...
21+
22+
If a service needs a custom region, microversion, or extra headers,
23+
pass them through to ``make_service_client`` - it forwards keyword
24+
arguments to ``ServiceClient``.
25+
"""
26+
27+
from __future__ import annotations
28+
29+
from sdk.core.provider import ProviderClient
30+
from sdk.core.service_client import ServiceClient
31+
32+
33+
def make_service_client(
34+
provider: ProviderClient,
35+
service_type: str,
36+
**kwargs,
37+
) -> ServiceClient:
38+
"""Build a :class:`ServiceClient` for the given service type.
39+
40+
Extra keyword arguments are forwarded to :class:`ServiceClient`
41+
(``region``, ``microversion``, ``endpoint_override``, ...).
42+
"""
43+
return ServiceClient(provider, service_type=service_type, **kwargs)

tests/acceptance/conftest.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ def provider() -> ProviderClient:
4545
return p
4646

4747

48-
@pytest.fixture
49-
def vpc_client(provider) -> ServiceClient:
50-
"""``ServiceClient`` configured for the VPC service."""
51-
return ServiceClient(provider, service_type="vpc")
52-
53-
5448
@pytest.fixture
5549
def cleanup() -> Generator[Callable[..., None], None, None]:
5650
"""LIFO cleanup registry backed by :class:`contextlib.ExitStack`.

tests/acceptance/services/vpc/v1/vpcs/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@
77
import pytest
88

99
from sdk.core.exceptions import HttpError
10+
from sdk.core.service_client import ServiceClient
1011
from sdk.services.vpc.v1.vpcs import CreateVpcOpts, Vpc, create, delete
12+
from tests.acceptance.clients import make_service_client
1113

1214
from tests.acceptance.conftest import unique_name
1315

1416

17+
@pytest.fixture
18+
def vpc_client(provider) -> ServiceClient:
19+
"""``ServiceClient`` for the VPC service.
20+
21+
Thin wrapper over :func:`tests.acceptance.clients.make_service_client`.
22+
"""
23+
return make_service_client(provider, "vpc")
24+
25+
1526
def _safe_delete(client, vpc_id: str) -> None:
1627
"""Idempotent delete used by cleanup hooks.
1728

0 commit comments

Comments
 (0)