Add test script for JSON extraction functionality

This commit introduces a new test script, `test_json_extraction.py`, which verifies the correctness of the JSON extraction logic. The script includes a function to extract the first valid JSON object from raw input and a series of test cases covering various scenarios, such as clean JSON, JSON with extra text, nested JSON, and escaped quotes. The tests ensure that the extraction function behaves as expected and handles edge cases appropriately.
This commit is contained in:
2025-10-09 19:56:22 +00:00
parent 2e020437a8
commit 3559cbe19d
5 changed files with 769 additions and 891 deletions
+12 -1
View File
@@ -30,7 +30,8 @@ from services.document_processor import DocumentProcessor
from services.matching_engine import MatchingEngine
from sqlalchemy.orm import Session
create_db_tables()
# Don't create tables at import time - do it on startup
# create_db_tables()
logging.basicConfig(
level=logging.INFO,
@@ -54,6 +55,15 @@ app.add_middleware(
allow_headers=["*"],
)
@app.on_event("startup")
async def startup_event():
"""Initialize database on startup"""
logger.info("Starting up application...")
create_db_tables()
logger.info("Application startup complete")
# Initialize DS Engine components
matching_engine = MatchingEngine()
document_processor = DocumentProcessor()
@@ -384,6 +394,7 @@ async def process_document(
- ai_rules: Custom categorization rules to override default logic
(e.g., [{"condition": "vendor is Starbucks", "action": "Food"}])
"""
logger.info(f"Request: {request}")
try:
# Get file info from database
db_uploaded_file = get_uploaded_file_from_db(db, file_id)