-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_ucp600_test_rules.py
More file actions
126 lines (116 loc) · 3.79 KB
/
create_ucp600_test_rules.py
File metadata and controls
126 lines (116 loc) · 3.79 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
#!/usr/bin/env python3
"""
Create UCP600 test rules for letter of credit validation
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from app.models.rules import Rule
from app.db import get_db
import json
# UCP600 test rules that match the test document structure
test_rules = [
{
"rule_id": "UCP600-1",
"source": "UCP600",
"article": "14",
"domain": "icc",
"jurisdiction": "global",
"document_type": "lc",
"version": "UCP600:2007",
"title": "Credit Amount Range Check",
"text": "Credit amount must be within reasonable limits for commercial transactions",
"condition": [
{
"type": "numeric_range",
"path": "credit_amount",
"min": 10000,
"max": 1000000
}
],
"expected_outcome": "PASS if credit_amount is between 10,000 and 1,000,000",
"severity": "fail",
"deterministic": True,
"requires_llm": False
},
{
"rule_id": "UCP600-2",
"source": "UCP600",
"article": "14",
"domain": "icc",
"jurisdiction": "global",
"document_type": "lc",
"version": "UCP600:2007",
"title": "Presentation Date vs Expiry Date",
"text": "Presentation date must not be after the expiry date of the credit",
"condition": [
{
"type": "date_order",
"first_path": "presentation_date",
"second_path": "expiry_date"
}
],
"expected_outcome": "FAIL if presentation_date > expiry_date",
"severity": "fail",
"deterministic": True,
"requires_llm": False
},
{
"rule_id": "UCP600-3",
"source": "UCP600",
"article": "14",
"domain": "icc",
"jurisdiction": "global",
"document_type": "lc",
"version": "UCP600:2007",
"title": "Required Documents Check",
"text": "All required documents must be present for presentation",
"condition": [
{
"type": "doc_required",
"doc_name": "commercial_invoice",
"documents_path": "required_documents"
}
],
"expected_outcome": "FAIL if commercial_invoice is not in required_documents",
"severity": "fail",
"deterministic": True,
"requires_llm": False
}
]
def create_test_rules():
"""Create UCP600 test rules in database"""
db = next(get_db())
try:
# Clear existing UCP600 test rules
db.query(Rule).filter(Rule.source == "UCP600").delete()
# Create new test rules
for rule_data in test_rules:
rule = Rule(
rule_id=rule_data["rule_id"],
source=rule_data["source"],
article=rule_data["article"],
title=rule_data["title"],
text=rule_data["text"],
condition=rule_data["condition"],
expected_outcome=rule_data["expected_outcome"],
severity=rule_data["severity"],
deterministic=rule_data["deterministic"],
requires_llm=rule_data["requires_llm"],
version="1.0"
)
db.add(rule)
db.commit()
print(f"Created {len(test_rules)} UCP600 test rules successfully!")
# Verify creation
created_rules = db.query(Rule).filter(Rule.source == "UCP600").all()
for rule in created_rules:
print(f" - {rule.rule_id}: {rule.title}")
except Exception as e:
db.rollback()
print(f"Error creating test rules: {e}")
raise
finally:
db.close()
if __name__ == "__main__":
create_test_rules()