File size: 4,213 Bytes
4bd3006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
126
127
#!/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!")