Spaces:
Paused
Paused
| # Test script for the update_project endpoint using curl | |
| echo "Testing update_project endpoint via stored procedure..." | |
| PROJECT_ID=15865 | |
| echo "" | |
| echo "=== Test 1: Get current project data (ID: $PROJECT_ID) ===" | |
| echo "GET /api/v1/projects/$PROJECT_ID" | |
| current_project=$(curl -s -X GET -H "Content-Type: application/json" \ | |
| http://localhost:8000/api/v1/projects/$PROJECT_ID) | |
| echo "Current project name: $(echo "$current_project" | grep -o '"project_name":"[^"]*"' | cut -d'"' -f4)" | |
| echo "Current project location: $(echo "$current_project" | grep -o '"project_location":"[^"]*"' | cut -d'"' -f4)" | |
| echo "" | |
| echo "=== Test 2: Update project (ID: $PROJECT_ID) ===" | |
| echo "PUT /api/v1/projects/$PROJECT_ID" | |
| # Create update payload with some changes | |
| cat > update_project.json << 'EOF' | |
| { | |
| "project_name": "UPDATED: Test Aqua Barrier Project", | |
| "project_location": "UPDATED: San Francisco, CA", | |
| "project_type": "Commercial - Updated", | |
| "bid_date": "2024-01-20T10:00:00", | |
| "start_date": "2024-02-05T08:00:00", | |
| "is_awarded": true, | |
| "notes": "UPDATED: Test project for SP validation", | |
| "barrier_size": "UPDATED: 60ft x 120ft", | |
| "lease_term": "18 months", | |
| "purchase_option": false, | |
| "lead_source": "Website - Updated", | |
| "rep": "Jane Doe", | |
| "engineer_company_id": 2, | |
| "engineer_notes": "UPDATED: Advanced installation required", | |
| "engineer_company": "XYZ Engineering", | |
| "status": 2, | |
| "customer_type_id": 1, | |
| "bill_name": "UPDATED: Test Company Inc", | |
| "bill_address1": "456 Updated Street", | |
| "bill_address2": "Suite 200", | |
| "bill_city": "San Francisco", | |
| "bill_state": "CA", | |
| "bill_zip": "94102", | |
| "bill_email": "updated-billing@testcompany.com", | |
| "bill_phone": "555-999-8888", | |
| "ship_name": "UPDATED: Test Company Inc", | |
| "ship_address1": "789 New Avenue", | |
| "ship_city": "San Francisco", | |
| "ship_state": "CA", | |
| "ship_zip": "94103", | |
| "ship_email": "updated-shipping@testcompany.com", | |
| "ship_phone": "555-888-7777", | |
| "ship_office_phone": "555-777-6666", | |
| "acct_payable": "Updated AP Department", | |
| "payment_term_id": 2, | |
| "payment_note": "Net 45", | |
| "rental_price_id": 2, | |
| "purchase_price_id": 2, | |
| "est_ship_date_id": 2, | |
| "fob_id": 2, | |
| "expedite_fee": "750.00", | |
| "est_freight_id": 2, | |
| "est_freight_fee": "350.00", | |
| "tax_rate": "9.50", | |
| "weekly_charge": "2000.00", | |
| "crew_members": 4, | |
| "tack_hoes": 3, | |
| "water_pump": 2, | |
| "water_pump2": 2, | |
| "pipes": 15, | |
| "timpers": 8, | |
| "est_installation_time": 12, | |
| "repair_kits": "Premium Kit", | |
| "installation_advisor": "UPDATED: Special installation notes here...", | |
| "employee_id": "EMP002", | |
| "install_date": "2024-02-20T09:00:00", | |
| "commission": "1500.00", | |
| "advisor_id": "ADV002", | |
| "ship_via": "FedEx Express", | |
| "valid_for": "Quote valid for 60 days", | |
| "fas_dam": true | |
| } | |
| EOF | |
| echo "Making PUT request to update project..." | |
| response=$(curl -s -w "\nHTTP_STATUS:%{http_code}\n" \ | |
| -X PUT \ | |
| -H "Content-Type: application/json" \ | |
| -d @update_project.json \ | |
| http://localhost:8000/api/v1/projects/$PROJECT_ID) | |
| # Parse response | |
| http_status=$(echo "$response" | grep "HTTP_STATUS" | cut -d: -f2) | |
| response_body=$(echo "$response" | sed '/HTTP_STATUS/d') | |
| echo "HTTP Status: $http_status" | |
| if [ "$http_status" = "200" ]; then | |
| echo "β Project updated successfully!" | |
| echo "Updated project name: $(echo "$response_body" | grep -o '"project_name":"[^"]*"' | cut -d'"' -f4)" | |
| echo "Updated project location: $(echo "$response_body" | grep -o '"project_location":"[^"]*"' | cut -d'"' -f4)" | |
| echo "Updated barrier size: $(echo "$response_body" | grep -o '"barrier_size":"[^"]*"' | cut -d'"' -f4)" | |
| echo "" | |
| echo "Full Response (formatted):" | |
| echo "$response_body" | python -m json.tool 2>/dev/null || echo "$response_body" | |
| else | |
| echo "β Error updating project" | |
| echo "Response:" | |
| echo "$response_body" | |
| fi | |
| echo "" | |
| echo "=== Test 3: Verify update by fetching project again ===" | |
| echo "GET /api/v1/projects/$PROJECT_ID" | |
| updated_project=$(curl -s -X GET -H "Content-Type: application/json" \ | |
| http://localhost:8000/api/v1/projects/$PROJECT_ID) | |
| echo "Verified project name: $(echo "$updated_project" | grep -o '"project_name":"[^"]*"' | cut -d'"' -f4)" | |
| echo "Verified project location: $(echo "$updated_project" | grep -o '"project_location":"[^"]*"' | cut -d'"' -f4)" | |
| echo "" | |
| echo "=== Test 4: Update non-existent project (ID: 999999) ===" | |
| echo "PUT /api/v1/projects/999999" | |
| response_not_found=$(curl -s -w "\nHTTP_STATUS:%{http_code}\n" \ | |
| -X PUT \ | |
| -H "Content-Type: application/json" \ | |
| -d @update_project.json \ | |
| http://localhost:8000/api/v1/projects/999999) | |
| # Parse response | |
| http_status_not_found=$(echo "$response_not_found" | grep "HTTP_STATUS" | cut -d: -f2) | |
| response_body_not_found=$(echo "$response_not_found" | sed '/HTTP_STATUS/d') | |
| echo "HTTP Status: $http_status_not_found" | |
| if [ "$http_status_not_found" = "404" ]; then | |
| echo "β Correctly returned 404 for non-existent project" | |
| echo "Error message: $response_body_not_found" | |
| else | |
| echo "β Unexpected response for non-existent project" | |
| echo "$response_body_not_found" | |
| fi | |
| # Clean up | |
| rm -f update_project.json | |
| echo "" | |
| echo "π Update project tests completed!" |