#!/bin/bash # Color Palette API Test Script # Usage: ./test_color_api.sh [server_ip] SERVER=${1:-localhost} PORT=8765 API_URL="http://${SERVER}:${PORT}/api/color-palette" echo "Testing Color Palette API at ${API_URL}" echo "==========================================" echo "" # Test 1: GET current palette echo "Test 1: GET current palette" echo "----------------------------" curl -s "${API_URL}" | python3 -m json.tool echo "" echo "" # Test 2: Update selected colors to slots 0 and 2 (Red and Blue) echo "Test 2: Update selected colors to [0, 2] (Red and Blue)" echo "--------------------------------------------------------" curl -s -X POST "${API_URL}" \ -H "Content-Type: application/json" \ -d '{"selected_indices": [0, 2]}' | python3 -m json.tool echo "" echo "" # Test 3: Update slot 3 to purple (128, 0, 128) echo "Test 3: Update slot 3 to purple (128, 0, 128)" echo "----------------------------------------------" curl -s -X POST "${API_URL}" \ -H "Content-Type: application/json" \ -d '{"palette": [ {"r": 255, "g": 0, "b": 0}, {"r": 0, "g": 255, "b": 0}, {"r": 0, "g": 0, "b": 255}, {"r": 128, "g": 0, "b": 128}, {"r": 255, "g": 179, "b": 255}, {"r": 0, "g": 255, "b": 255}, {"r": 255, "g": 255, "b": 255}, {"r": 128, "g": 128, "b": 128} ]}' | python3 -m json.tool echo "" echo "" # Test 4: Select the new purple color (slots 3 and 5) echo "Test 4: Select slots 3 and 5 (Purple and Cyan)" echo "-----------------------------------------------" curl -s -X POST "${API_URL}" \ -H "Content-Type: application/json" \ -d '{"selected_indices": [3, 5]}' | python3 -m json.tool echo "" echo "" # Test 5: GET final state echo "Test 5: GET final state" echo "-----------------------" curl -s "${API_URL}" | python3 -m json.tool echo "" echo "" # Test 6: Test backup port (8766) echo "Test 6: Test backup port 8766" echo "------------------------------" curl -s "http://${SERVER}:8766/api/color-palette" | python3 -m json.tool | head -15 echo "..." echo "" echo "==========================================" echo "All tests completed!" echo "" echo "Config file location: lighting_config.json" echo "To view: cat lighting_config.json | python3 -m json.tool"