ab-ms-core / tests /unit /test_create_project.py
PupaClic
Add comprehensive unit tests for various endpoints and features
7ff20d3
#!/usr/bin/env python3
"""
Test script for the create_project endpoint using the spProjectsInsert stored procedure
"""
import requests
import json
from datetime import datetime
from decimal import Decimal
# API endpoint
BASE_URL = "http://localhost:8000"
ENDPOINT = f"{BASE_URL}/api/v1/projects/"
def test_create_project():
"""Test creating a project with the new stored procedure implementation"""
# Sample project data matching the stored procedure parameters
project_data = {
"project_name": "Test Aqua Barrier Project",
"project_location": "Los Angeles, CA",
"project_type": "Commercial",
"bid_date": "2024-01-15T10:00:00",
"start_date": "2024-02-01T08:00:00",
"is_awarded": True,
"notes": "Test project for SP validation",
"barrier_size": "50ft x 100ft",
"lease_term": "12 months",
"purchase_option": False,
"lead_source": "Website",
"rep": "John Doe",
"engineer_company_id": 1,
"engineer_notes": "Standard installation required",
"engineer_company": "ABC Engineering",
"status": 1,
"customer_type_id": 1,
# Billing address
"bill_name": "Test Company Inc",
"bill_address1": "123 Main Street",
"bill_address2": "Suite 100",
"bill_city": "Los Angeles",
"bill_state": "CA",
"bill_zip": "90210",
"bill_email": "billing@testcompany.com",
"bill_phone": "555-123-4567",
# Shipping address
"ship_name": "Test Company Inc",
"ship_address1": "456 Oak Avenue",
"ship_city": "Los Angeles",
"ship_state": "CA",
"ship_zip": "90211",
"ship_email": "shipping@testcompany.com",
"ship_phone": "555-234-5678",
"ship_office_phone": "555-345-6789",
# Payment and project details
"acct_payable": "AP Department",
"payment_term_id": 1,
"payment_note": "Net 30",
"rental_price_id": 1,
"purchase_price_id": 1,
"est_ship_date_id": 1,
"fob_id": 1,
"expedite_fee": "500.00",
"est_freight_id": 1,
"est_freight_fee": "250.00",
"tax_rate": "8.25",
"weekly_charge": "1500.00",
"crew_members": 3,
"tack_hoes": 2,
"water_pump": 1,
"water_pump2": 1,
"pipes": 10,
"timpers": 5,
"est_installation_time": 8,
"repair_kits": "Standard Kit",
"installation_advisor": "Installation notes here...",
"employee_id": "EMP001",
"install_date": "2024-02-15T09:00:00",
"commission": "1000.00",
"advisor_id": "ADV001",
"ship_via": "UPS Ground",
"valid_for": "Quote valid for 30 days",
"fas_dam": False
}
print("Testing project creation via stored procedure...")
print(f"POST {ENDPOINT}")
print(f"Payload: {json.dumps(project_data, indent=2)}")
try:
# Make the API call
response = requests.post(
ENDPOINT,
json=project_data,
headers={"Content-Type": "application/json"}
)
print(f"\nResponse Status: {response.status_code}")
print(f"Response Headers: {dict(response.headers)}")
if response.status_code == 201:
result = response.json()
print(f"\n✅ Project created successfully!")
print(f"ProjectNo: {result.get('project_no')}")
print(f"Project Name: {result.get('project_name')}")
print(f"Response: {json.dumps(result, indent=2, default=str)}")
return True
else:
print(f"\n❌ Error creating project")
print(f"Error: {response.text}")
return False
except requests.exceptions.RequestException as e:
print(f"\n❌ Network error: {e}")
return False
except Exception as e:
print(f"\n❌ Unexpected error: {e}")
return False
if __name__ == "__main__":
success = test_create_project()
if success:
print("\n🎉 Test completed successfully!")
else:
print("\n💥 Test failed!")