-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_verifier.py
135 lines (119 loc) · 4.58 KB
/
test_verifier.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
import pytest
from aries_cloudcontroller import DIFProofRequest, PresentationDefinition
from app.models.verifier import (
AcceptProofRequest,
AnoncredsPresentationRequest,
DIFPresSpec,
IndyPresSpec,
IndyProofRequest,
ProofRequestBase,
ProofRequestType,
RejectProofRequest,
)
from shared.exceptions.cloudapi_value_error import CloudApiValueError
def test_proof_request_base_model():
with pytest.raises(CloudApiValueError) as exc:
ProofRequestBase(type=ProofRequestType.INDY, indy_proof_request=None)
assert exc.value.detail == (
"indy_proof_request must be populated if `indy` type is selected"
)
with pytest.raises(CloudApiValueError) as exc:
ProofRequestBase(type=ProofRequestType.ANONCREDS, anoncreds_proof_request=None)
assert exc.value.detail == (
"anoncreds_proof_request must be populated if `anoncreds` type is selected"
)
with pytest.raises(CloudApiValueError) as exc:
ProofRequestBase(
type=ProofRequestType.LD_PROOF,
indy_proof_request=IndyProofRequest(
requested_attributes={}, requested_predicates={}
),
dif_proof_request=DIFProofRequest(
presentation_definition=PresentationDefinition()
),
)
assert exc.value.detail == (
"Only dif_proof_request must not be populated if `ld_proof` type is selected"
)
with pytest.raises(CloudApiValueError) as exc:
ProofRequestBase(
type=ProofRequestType.INDY,
indy_proof_request=IndyProofRequest(
requested_attributes={}, requested_predicates={}
),
dif_proof_request=DIFProofRequest(
presentation_definition=PresentationDefinition()
),
)
assert exc.value.detail == (
"Only indy_proof_request must not be populated if `indy` type is selected"
)
with pytest.raises(CloudApiValueError) as exc:
ProofRequestBase(
type=ProofRequestType.ANONCREDS,
anoncreds_proof_request=AnoncredsPresentationRequest(
requested_attributes={}, requested_predicates={}
),
dif_proof_request=DIFProofRequest(
presentation_definition=PresentationDefinition()
),
)
assert exc.value.detail == (
"Only anoncreds_proof_request must not be populated if `anoncreds` type is selected"
)
with pytest.raises(CloudApiValueError) as exc:
ProofRequestBase(type=ProofRequestType.LD_PROOF, dif_proof_request=None)
assert exc.value.detail == (
"dif_proof_request must be populated if `ld_proof` type is selected"
)
ProofRequestBase.check_proof_request(
values=ProofRequestBase(
indy_proof_request=IndyProofRequest(
requested_attributes={}, requested_predicates={}
)
)
)
def test_accept_proof_request_model():
AcceptProofRequest(
proof_id="abc",
indy_presentation_spec=IndyPresSpec(
requested_attributes={},
requested_predicates={},
self_attested_attributes={},
),
)
AcceptProofRequest(
proof_id="abc",
type=ProofRequestType.LD_PROOF,
dif_presentation_spec=DIFPresSpec(),
)
AcceptProofRequest(
proof_id="abc",
anoncreds_presentation_spec=IndyPresSpec(
requested_attributes={},
requested_predicates={},
self_attested_attributes={},
),
)
with pytest.raises(CloudApiValueError) as exc:
AcceptProofRequest(type=ProofRequestType.INDY, indy_presentation_spec=None)
assert exc.value.detail == (
"indy_presentation_spec must be populated if `indy` type is selected"
)
with pytest.raises(CloudApiValueError) as exc:
AcceptProofRequest(type=ProofRequestType.LD_PROOF, dif_presentation_spec=None)
assert exc.value.detail == (
"dif_presentation_spec must be populated if `ld_proof` type is selected"
)
with pytest.raises(CloudApiValueError) as exc:
AcceptProofRequest(
type=ProofRequestType.ANONCREDS, anoncreds_presentation_spec=None
)
assert exc.value.detail == (
"anoncreds_proof_request must be populated if `anoncreds` type is selected"
)
def test_reject_proof_request_model():
RejectProofRequest(proof_id="abc", problem_report="valid message")
with pytest.raises(CloudApiValueError) as exc:
RejectProofRequest(proof_id="abc", problem_report="")
assert exc.value.detail == "problem_report cannot be an empty string"