-
Notifications
You must be signed in to change notification settings - Fork 9
/
mock_agent_controller.py
86 lines (67 loc) · 2.12 KB
/
mock_agent_controller.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
import pytest
from aries_cloudcontroller import (
AcaPyClient,
ConnectionApi,
CredentialsApi,
EndorseTransactionApi,
IssueCredentialV20Api,
LedgerApi,
OutOfBandApi,
PresentProofV20Api,
RevocationApi,
SchemaApi,
WalletApi,
)
from mockito import mock
from app.dependencies.auth import AcaPyAuth, AcaPyAuthVerified
from app.dependencies.role import Role
from shared.constants import GOVERNANCE_AGENT_API_KEY, GOVERNANCE_LABEL
async def noop():
return None
def get_mock_agent_controller() -> AcaPyClient:
controller = mock(AcaPyClient)
controller.__aexit__ = noop
controller.connection = mock(ConnectionApi)
controller.credentials = mock(CredentialsApi)
controller.endorse_transaction = mock(EndorseTransactionApi)
controller.issue_credential_v2_0 = mock(IssueCredentialV20Api)
controller.ledger = mock(LedgerApi)
controller.out_of_band = mock(OutOfBandApi)
controller.present_proof_v2_0 = mock(PresentProofV20Api)
controller.revocation = mock(RevocationApi)
controller.schema = mock(SchemaApi)
controller.wallet = mock(WalletApi)
return controller
class MockContextManagedController:
def __init__(self, controller):
self.controller = controller
async def __aenter__(self):
return self.controller
async def __aexit__(self, exc_type, exc, tb):
pass
@pytest.fixture
def mock_agent_controller():
return get_mock_agent_controller()
@pytest.fixture
def mock_context_managed_controller():
return MockContextManagedController
@pytest.fixture(scope="session")
def mock_governance_auth():
auth = mock(AcaPyAuthVerified)
auth.role = Role.GOVERNANCE
auth.token = GOVERNANCE_AGENT_API_KEY
auth.wallet_id = GOVERNANCE_LABEL
return auth
@pytest.fixture
def mock_admin_auth() -> AcaPyAuthVerified:
auth = mock(AcaPyAuthVerified)
auth.role = Role.TENANT_ADMIN
auth.token = GOVERNANCE_AGENT_API_KEY
auth.wallet_id = "admin"
return auth
@pytest.fixture
def mock_tenant_auth():
auth = mock(AcaPyAuth)
auth.role = Role.TENANT
auth.token = "tenant.test_token"
return auth