Files
Comparison_Project/test_ra_bills.py
2026-02-02 12:27:27 +05:30

69 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify RA bill fetching from both client and subcontractor tables
"""
import sys
import os
sys.path.insert(0, os.path.dirname(__file__))
from app import create_app, db
from app.models.trench_excavation_model import TrenchExcavation
from app.models.tr_ex_client_model import TrenchExcavationClient
app = create_app()
with app.app_context():
print("=" * 70)
print("RA BILL FETCHING TEST")
print("=" * 70)
# Test 1: Count total records
print("\n✓ TEST 1: Total Records in Both Tables")
subcon_count = db.session.query(TrenchExcavation).count()
client_count = db.session.query(TrenchExcavationClient).count()
print(f" Subcontractor (TrenchExcavation): {subcon_count} records")
print(f" Client (TrenchExcavationClient): {client_count} records")
# Test 2: Check RA bills in Subcontractor table
print("\n✓ TEST 2: RA Bills in Subcontractor Table")
subcon_bills = db.session.query(TrenchExcavation.RA_Bill_No)\
.filter(TrenchExcavation.RA_Bill_No != None)\
.filter(TrenchExcavation.RA_Bill_No != "")\
.distinct().all()
print(f" Distinct RA Bills found: {len(subcon_bills)}")
print(f" Bills: {[str(r[0]) for r in subcon_bills]}")
# Test 3: Check RA bills in Client table
print("\n✓ TEST 3: RA Bills in Client Table")
client_bills = db.session.query(TrenchExcavationClient.RA_Bill_No)\
.filter(TrenchExcavationClient.RA_Bill_No != None)\
.filter(TrenchExcavationClient.RA_Bill_No != "")\
.distinct().all()
print(f" Distinct RA Bills found: {len(client_bills)}")
print(f" Bills: {[str(r[0]) for r in client_bills]}")
# Test 4: Combined unique RA bills
print("\n✓ TEST 4: Combined Unique RA Bills (Union)")
combined_bills = db.session.query(TrenchExcavation.RA_Bill_No)\
.filter(TrenchExcavation.RA_Bill_No != None)\
.filter(TrenchExcavation.RA_Bill_No != "")\
.union(
db.session.query(TrenchExcavationClient.RA_Bill_No)\
.filter(TrenchExcavationClient.RA_Bill_No != None)\
.filter(TrenchExcavationClient.RA_Bill_No != "")
).order_by(TrenchExcavation.RA_Bill_No).all()
print(f" Total unique RA Bills: {len(combined_bills)}")
print(f" Bills: {[str(r[0]) for r in combined_bills]}")
# Test 5: Sample data from both tables
print("\n✓ TEST 5: Sample RA Bills from Tables")
sample_subcon = db.session.query(TrenchExcavation.RA_Bill_No).limit(5).all()
sample_client = db.session.query(TrenchExcavationClient.RA_Bill_No).limit(5).all()
print(f" Subcontractor samples: {[str(r[0]) for r in sample_subcon]}")
print(f" Client samples: {[str(r[0]) for r in sample_client]}")
print("\n" + "=" * 70)
print("✅ TEST COMPLETE")
print("=" * 70)