-
Notifications
You must be signed in to change notification settings - Fork 9
/
member_async_clients.py
97 lines (75 loc) · 2.94 KB
/
member_async_clients.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from typing import Any, AsyncGenerator
from unittest.mock import AsyncMock, Mock
import pytest
from fastapi import Response
from pytest_mock import MockerFixture
from app.models.tenants import CreateTenantResponse
from app.tests.util.client import (
get_governance_client,
get_tenant_admin_client,
get_tenant_client,
)
from shared import RichAsyncClient
from shared.constants import TRUST_REGISTRY_FASTAPI_ENDPOINT
@pytest.fixture
async def trust_registry_client() -> AsyncGenerator[RichAsyncClient, Any]:
async with RichAsyncClient(base_url=TRUST_REGISTRY_FASTAPI_ENDPOINT) as client:
yield client
@pytest.fixture(scope="function")
async def governance_client() -> AsyncGenerator[RichAsyncClient, Any]:
async with get_governance_client() as gov_async_client:
yield gov_async_client
@pytest.fixture(scope="function")
async def tenant_admin_client() -> AsyncGenerator[RichAsyncClient, Any]:
async with get_tenant_admin_client() as admin_async_client:
yield admin_async_client
@pytest.fixture(scope="function")
async def alice_member_client(
alice_tenant: CreateTenantResponse,
) -> AsyncGenerator[RichAsyncClient, Any]:
async with get_tenant_client(
token=alice_tenant.access_token, name="Alice"
) as alice_async_client:
yield alice_async_client
@pytest.fixture(scope="function")
async def bob_member_client(
bob_tenant: CreateTenantResponse,
) -> AsyncGenerator[RichAsyncClient, Any]:
async with get_tenant_client(
token=bob_tenant.access_token, name="Bob"
) as bob_async_client:
yield bob_async_client
@pytest.fixture(scope="session")
async def faber_client(
faber_issuer: CreateTenantResponse,
) -> AsyncGenerator[RichAsyncClient, Any]:
async with get_tenant_client(
token=faber_issuer.access_token, name="Faber"
) as faber_async_client:
yield faber_async_client
@pytest.fixture(scope="module")
async def acme_client(
acme_verifier: CreateTenantResponse,
) -> AsyncGenerator[RichAsyncClient, Any]:
async with get_tenant_client(
token=acme_verifier.access_token, name="Acme"
) as acme_async_client:
yield acme_async_client
@pytest.fixture(scope="session")
async def meld_co_client(
meld_co_issuer_verifier: CreateTenantResponse,
) -> AsyncGenerator[RichAsyncClient, Any]:
async with get_tenant_client(
token=meld_co_issuer_verifier.access_token, name="MeldCo"
) as meld_co_async_client:
yield meld_co_async_client
@pytest.fixture
def mock_async_client(mocker: MockerFixture, request) -> Mock:
"""Patching RichAsyncClient in variable modules"""
module_path = request.param
patch_async_client = mocker.patch(f"{module_path}.RichAsyncClient")
mocked_async_client = Mock()
response = Response(status_code=200)
mocked_async_client.get = AsyncMock(return_value=response)
patch_async_client.return_value.__aenter__.return_value = mocked_async_client
return mocked_async_client