-
Notifications
You must be signed in to change notification settings - Fork 9
/
member_connections.py
159 lines (138 loc) · 6.07 KB
/
member_connections.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import pytest
from app.models.tenants import CreateTenantResponse
from app.routes.connections import router as conn_router
from app.tests.util.connections import (
AcmeAliceConnect,
BobAliceConnect,
FaberAliceConnect,
MeldCoAliceConnect,
connect_using_trust_registry_invite,
create_connection_by_test_mode,
fetch_or_create_trust_registry_connection,
)
from app.tests.util.regression_testing import RegressionTestConfig, TestMode
from shared import RichAsyncClient
CONNECTIONS_BASE_PATH = conn_router.prefix
# Fixture for passing test mode params. Assists with mixing direct and indirect request
@pytest.fixture(scope="module", params=TestMode.fixture_params)
async def test_mode(request) -> str:
return request.param
@pytest.fixture(scope="function")
async def bob_and_alice_connection(
bob_member_client: RichAsyncClient,
alice_member_client: RichAsyncClient,
test_mode: str, # pylint: disable=redefined-outer-name
) -> BobAliceConnect:
return await create_connection_by_test_mode(
test_mode=test_mode,
alice_member_client=alice_member_client,
bob_member_client=bob_member_client,
alias="AliceBobConnection",
)
@pytest.fixture(scope="function")
async def faber_and_alice_connection(
alice_member_client: RichAsyncClient,
faber_client: RichAsyncClient,
test_mode: str, # pylint: disable=redefined-outer-name
) -> FaberAliceConnect:
bob_alice_connection = await create_connection_by_test_mode(
test_mode=test_mode,
alice_member_client=alice_member_client,
bob_member_client=faber_client,
alias="AliceFaberConnection",
)
return FaberAliceConnect(
alice_connection_id=bob_alice_connection.alice_connection_id,
faber_connection_id=bob_alice_connection.bob_connection_id,
)
@pytest.fixture(scope="function")
async def acme_and_alice_connection(
request,
alice_member_client: RichAsyncClient,
alice_tenant: CreateTenantResponse,
acme_client: RichAsyncClient,
acme_verifier: CreateTenantResponse,
test_mode: str, # pylint: disable=redefined-outer-name
) -> AcmeAliceConnect:
# Check if request param comes indirectly from higher fixture to establish trust registry connection instead
if hasattr(request, "param") and request.param == "trust_registry":
connection_alias = "AliceAcmeTrustRegistryConnection"
if test_mode == TestMode.clean_run:
acme_alice_connect = await connect_using_trust_registry_invite(
alice_member_client=alice_member_client,
alice_tenant=alice_tenant,
verifier_client=acme_client,
verifier=acme_verifier,
connection_alias=connection_alias,
)
elif test_mode == TestMode.regression_run:
connection_alias_prefix = RegressionTestConfig.reused_connection_alias
acme_alice_connect = await fetch_or_create_trust_registry_connection(
alice_member_client=alice_member_client,
alice_tenant=alice_tenant,
verifier_client=acme_client,
verifier=acme_verifier,
connection_alias=f"{connection_alias_prefix}-{connection_alias}",
)
else:
assert False, f"unknown test mode: {test_mode}"
return acme_alice_connect
else:
# No indirect request param for trust registry connection; establish normal connection:
bob_alice_connection = await create_connection_by_test_mode(
test_mode=test_mode,
alice_member_client=alice_member_client,
bob_member_client=acme_client,
alias="AliceAcmeConnection",
)
return AcmeAliceConnect(
alice_connection_id=bob_alice_connection.alice_connection_id,
acme_connection_id=bob_alice_connection.bob_connection_id,
)
# Create fixture to handle parameters and return either meld_co-alice connection fixture
@pytest.fixture(scope="function")
async def meld_co_and_alice_connection(
request,
alice_tenant: CreateTenantResponse,
alice_member_client: RichAsyncClient,
meld_co_client: RichAsyncClient,
meld_co_issuer_verifier: CreateTenantResponse,
test_mode: str, # pylint: disable=redefined-outer-name
) -> MeldCoAliceConnect:
if hasattr(request, "param") and request.param == "trust_registry":
connection_alias = "AliceMeldCoTrustRegistryConnection"
if test_mode == TestMode.clean_run:
acme_alice_connect = await connect_using_trust_registry_invite(
alice_member_client=alice_member_client,
alice_tenant=alice_tenant,
verifier_client=meld_co_client,
verifier=meld_co_issuer_verifier,
connection_alias=connection_alias,
)
elif test_mode == TestMode.regression_run:
connection_alias_prefix = RegressionTestConfig.reused_connection_alias
acme_alice_connect = await fetch_or_create_trust_registry_connection(
alice_member_client=alice_member_client,
alice_tenant=alice_tenant,
verifier_client=meld_co_client,
verifier=meld_co_issuer_verifier,
connection_alias=f"{connection_alias_prefix}-{connection_alias}",
)
else:
assert False, f"unknown test mode: {test_mode}"
return MeldCoAliceConnect(
alice_connection_id=acme_alice_connect.alice_connection_id,
meld_co_connection_id=acme_alice_connect.acme_connection_id,
)
else:
# No indirect request param for trust registry connection; establish normal connection:
bob_alice_connection = await create_connection_by_test_mode(
test_mode=test_mode,
alice_member_client=alice_member_client,
bob_member_client=meld_co_client,
alias="AliceMeldCoConnection",
)
return MeldCoAliceConnect(
alice_connection_id=bob_alice_connection.alice_connection_id,
meld_co_connection_id=bob_alice_connection.bob_connection_id,
)