-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
243 lines (218 loc) · 6.67 KB
/
test.py
File metadata and controls
243 lines (218 loc) · 6.67 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
"""
Test script for Plausibility Check API
Uses real data from your OCR results
"""
import requests
import json
# Base URL
BASE_URL = "http://localhost:8001"
# Your actual OCR results
test_data = {
"pos": {
"certificate": {
"pos_id": "EU-ISCC-Cert-DE123-2025-0001-A",
"scheme": "ISCC EU (RFNBO)",
"issuer": "Control Union Certifications",
"issue_date": "2025-05-01",
"validity": None
},
"parties": {
"supplier": "GreenHydro Methanol GmbH",
"recipient": "Valenz Chemicals GmbH"
},
"batch": {
"batch_id": "BATCH-2025-06-A",
"batch_volume": "59.7",
"batch_volume_unit": "t",
"energy_content": "328.35",
"energy_content_unit": "MWh"
},
"ghg": {
"ci_lca": "-51.2",
"ci_limit": "-49.5",
"unit": "gCO2e/MJ"
},
"chain_of_custody": {
"model": "Mass Balance",
"no_double_counting": True
}
},
"termsheet": {
"identifiers": {
"ts_id": "TS-VALENZ-EMEOH-2025",
"date": "2025-02-01",
"expiry": "2025-04-30"
},
"parties": {
"seller": "GreenHydro Methanol GmbH",
"buyer": "Valenz Chemicals GmbH"
},
"commercial": {
"acq": "3600",
"acq_unit": "t/yr",
"delivery": "DAP Steyerberg (Incoterms 2020)",
"pricing": "Fixed Y1-Y5 (see PPA), indexed post-Y5 (Argus MeOH)"
},
"sustainability": {
"ci_target": "≤ -49.5 gCO2/MJ",
"scheme": "ISCC EU / REDcert EU"
},
"timing": {
"commencement": "post COD",
"long_stop": "2028-03-30"
}
},
"ppa": {
"parties": {
"seller": {
"name": "GreenHydro Methanol GmbH",
"registration": "HRB 913245"
},
"buyer": {
"name": "Valenz Chemicals GmbH",
"registration": "HRB 118223"
}
},
"key_terms": {
"project_id": "VALENZ-EMEOH-2025",
"commodity": "e-Methanol (RFNBO)",
"effective_date": "2025-05-01",
"duration": "10 years",
"acq": "3600",
"acq_unit": "t/yr",
"monthly_plan": "300.0",
"monthly_tolerance": "±5%",
"delivery": "DAP Steyerberg (Incoterms 2020)",
"customs": "T2 by Supplier"
},
"pricing": {
"price_y1_y5": "1500",
"currency": "EUR"
},
"sustainability_compliance": {
"ci_limit": "≤ −49.5 gCO2/MJ",
"certification": "ISCC EU / REDcert EU (RFNBO scope)",
"audit_required": True,
"auditor_signature": "anchored on-chain"
},
"commencement": {
"commencement_rule": "First delivery must be COD − 1 month",
"long_stop_date": "2028-03-30"
}
},
"invoice": {
"identifiers": {
"invoice_no": "INV-000187",
"issue_date": "2025-07-01",
"payment_due": "2025-07-31"
},
"parties": {
"supplier": "GreenHydro Methanol GmbH",
"buyer": "Valenz Chemicals GmbH"
},
"billing_period": {
"period_start": "2025-06-01",
"period_end": "2025-06-30"
},
"product_amount": {
"product": "e-Methanol (RFNBO)",
"quantity": "298.5",
"unit": "t",
"unit_price": "1500.00",
"unit_price_currency": "€",
"amount_excl_vat": "447750.00",
"amount_currency": "€"
},
"logistics": {
"incoterm": "DAP Steyerberg (Incoterms 2020)",
"customs": "T2 by Supplier"
}
},
"plant_id": "PLANT-001"
}
def test_health():
"""Test health endpoint"""
print("=" * 80)
print("Testing Health Endpoint")
print("=" * 80)
response = requests.get(f"{BASE_URL}/health")
print(f"Status: {response.status_code}")
print(f"Response: {response.json()}")
print()
def test_plausibility_check():
"""Test plausibility check with real data"""
print("=" * 80)
print("Testing Plausibility Check")
print("=" * 80)
response = requests.post(
f"{BASE_URL}/api/v1/plausibility/check",
json=test_data,
headers={"Content-Type": "application/json"}
)
print(f"Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"\n{'=' * 80}")
print("PLAUSIBILITY CHECK RESULT")
print("=" * 80)
print(f"\n✅ Valid: {result['is_valid']}")
print(f"📅 Invoice Expiry: {result['invoice_expiry_date']}")
if result['seal_hash']:
print(f"🔒 Seal Hash: {result['seal_hash']}")
print(f"\n{'=' * 80}")
print("INDIVIDUAL CHECKS")
print("=" * 80)
for check in result['checks']:
status = "✅" if check['passed'] else "❌"
print(f"\n{status} {check['check_name']}")
print(f" Expected: {check.get('expected', 'N/A')}")
print(f" Actual: {check.get('actual', 'N/A')}")
if check.get('details'):
print(f" Details: {check['details']}")
if result.get('proof'):
print(f"\n{'=' * 80}")
print("PROOF MESSAGE")
print("=" * 80)
print(result['proof'])
if result.get('hcs_data'):
print(f"\n{'=' * 80}")
print("HCS DATA (for Hedera Consensus Service)")
print("=" * 80)
print(json.dumps(result['hcs_data'], indent=2))
else:
print(f"Error: {response.text}")
def test_invalid_data():
"""Test with invalid data (wrong parties)"""
print("\n" + "=" * 80)
print("Testing Invalid Data (Wrong Supplier)")
print("=" * 80)
invalid_data = test_data.copy()
invalid_data['invoice']['parties']['supplier'] = "Wrong Company GmbH"
response = requests.post(
f"{BASE_URL}/api/v1/plausibility/check",
json=invalid_data,
headers={"Content-Type": "application/json"}
)
print(f"Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"Valid: {result['is_valid']}")
print(f"Seal Hash: {result.get('seal_hash', 'None - Invalid')}")
print("\nFailed Checks:")
for check in result['checks']:
if not check['passed']:
print(f" ❌ {check['check_name']}: {check.get('details', '')}")
if __name__ == "__main__":
print("\n🚀 Starting Plausibility Check API Tests\n")
try:
test_health()
test_plausibility_check()
test_invalid_data()
print("\n" + "=" * 80)
print("✅ All tests completed!")
print("=" * 80)
except requests.exceptions.ConnectionError:
print("\n❌ Cannot connect to API. Make sure it's running:")
print(" python plausibility_check_main.py")
except Exception as e:
print(f"\n❌ Test failed: {e}")