aquabarrier / tests /unit /test_customer_fix.py
rajeshbms's picture
Add validation report for AquaBarrier project implementation
d5f727d
#!/usr/bin/env python3
"""
Test script to verify the customer endpoint fix works.
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
def test_imports():
"""Test if all imports work correctly"""
try:
from app.schemas.customer import CustomerOut, CustomerCreate
from app.services.customer_list_service import CustomerListService
from app.db.repositories.customer_sp_repo import CustomerRepository
from app.controllers.customers import router
print("βœ… All imports successful")
return True
except Exception as e:
print(f"❌ Import error: {e}")
return False
def test_customer_schema():
"""Test if CustomerOut schema works correctly"""
try:
from app.schemas.customer import CustomerOut
# Test creating a CustomerOut instance
customer_data = {
'id': 1,
'name': 'Test Company',
'address': '123 Test St',
'city': 'Test City',
'postal_code': '12345',
'web_address': 'http://test.com',
'referral': 'YES',
'company_type_id': 1,
'state_id': 1,
'country_id': 1,
'lead_generated_from_id': 1,
'specific_source': 'Test Source',
'priority_id': 1,
'followup_date': None,
'purchase': 'Test',
'vendor_id': 'V001',
'enabled': True,
'rental_type': 'AB'
}
customer = CustomerOut(**customer_data)
print(f"βœ… CustomerOut schema works: {customer.id}, {customer.name}")
return True
except Exception as e:
print(f"❌ CustomerOut schema error: {e}")
return False
def test_repository_structure():
"""Test if repository structure is correct"""
try:
from app.db.repositories.customer_sp_repo import CustomerRepository
# Test if the class has the expected method
if hasattr(CustomerRepository, 'list_customers_via_sp'):
print("βœ… CustomerRepository has list_customers_via_sp method")
return True
else:
print("❌ CustomerRepository missing list_customers_via_sp method")
return False
except Exception as e:
print(f"❌ Repository structure error: {e}")
return False
def main():
"""Run all tests"""
print("πŸ”§ Testing customer endpoint fixes...")
tests = [
test_imports,
test_customer_schema,
test_repository_structure
]
passed = 0
for test in tests:
if test():
passed += 1
print(f"\nπŸ“Š Test Results: {passed}/{len(tests)} tests passed")
if passed == len(tests):
print("πŸŽ‰ All tests passed! The customer endpoint fix should work.")
else:
print("⚠️ Some tests failed. Please review the issues above.")
if __name__ == "__main__":
main()