Fix jwt-token
This commit is contained in:
20
.env.test.example
Normal file
20
.env.test.example
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Environment configuration for test scripts
|
||||||
|
# Copy this to .env in the project root or set these as environment variables
|
||||||
|
|
||||||
|
# API Base URL - Update this to your deployment
|
||||||
|
API_BASE_URL=http://localhost:3002/api
|
||||||
|
|
||||||
|
# For production deployment, use your domain:
|
||||||
|
# API_BASE_URL=https://your-domain.com/uggla/api
|
||||||
|
|
||||||
|
# Base path (should match VITE_BASE_PATH)
|
||||||
|
VITE_BASE_PATH=/uggla
|
||||||
|
|
||||||
|
# Alternative configurations:
|
||||||
|
# For local development:
|
||||||
|
# API_BASE_URL=http://localhost:3002/api
|
||||||
|
# VITE_BASE_PATH=
|
||||||
|
|
||||||
|
# For production with different base path:
|
||||||
|
# API_BASE_URL=https://your-domain.com
|
||||||
|
# VITE_BASE_PATH=/your-custom-path
|
||||||
103
run-tests.sh
Normal file
103
run-tests.sh
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Test runner script for Uggla Drone Detection System
|
||||||
|
# Automatically sets up environment and runs test scripts
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
echo -e "${BLUE}======================================${NC}"
|
||||||
|
echo -e "${BLUE} Uggla Test Runner${NC}"
|
||||||
|
echo -e "${BLUE}======================================${NC}"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Check if .env exists, if not suggest creating it
|
||||||
|
if [ ! -f ".env" ]; then
|
||||||
|
echo -e "${YELLOW}Warning: .env file not found.${NC}"
|
||||||
|
echo "You can:"
|
||||||
|
echo "1. Copy .env.test.example to .env and customize it"
|
||||||
|
echo "2. Set environment variables manually"
|
||||||
|
echo "3. Use default localhost settings"
|
||||||
|
echo
|
||||||
|
read -p "Continue with default localhost settings? (y/N): " CONTINUE
|
||||||
|
if [[ ! $CONTINUE =~ ^[Yy]$ ]]; then
|
||||||
|
echo "Please create .env file and try again."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set default environment variables
|
||||||
|
export API_BASE_URL="http://localhost:3002/api"
|
||||||
|
export VITE_BASE_PATH=""
|
||||||
|
echo -e "${GREEN}Using default localhost configuration${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}Loading environment from .env file${NC}"
|
||||||
|
# Load environment variables from .env file
|
||||||
|
export $(grep -v '^#' .env | xargs)
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${BLUE}Current configuration:${NC}"
|
||||||
|
echo "API_BASE_URL: ${API_BASE_URL:-http://localhost:3002/api}"
|
||||||
|
echo "VITE_BASE_PATH: ${VITE_BASE_PATH:-<empty>}"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Check which test to run
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
echo "Available tests:"
|
||||||
|
echo "1. test_drone_data.py - Comprehensive drone simulation"
|
||||||
|
echo "2. test_orlan_scenario.py - Military drone approach scenario"
|
||||||
|
echo "3. test_orlan_detection.py - Long-range Orlan detection test"
|
||||||
|
echo "4. test_drone_curl.sh - Simple curl-based API test"
|
||||||
|
echo
|
||||||
|
read -p "Select test (1-4): " TEST_CHOICE
|
||||||
|
|
||||||
|
case $TEST_CHOICE in
|
||||||
|
1) TEST_SCRIPT="test_drone_data.py" ;;
|
||||||
|
2) TEST_SCRIPT="test_orlan_scenario.py" ;;
|
||||||
|
3) TEST_SCRIPT="test_orlan_detection.py" ;;
|
||||||
|
4) TEST_SCRIPT="test_drone_curl.sh" ;;
|
||||||
|
*) echo "Invalid choice"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
TEST_SCRIPT=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${YELLOW}Running test: $TEST_SCRIPT${NC}"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Check if script exists
|
||||||
|
if [ ! -f "$TEST_SCRIPT" ]; then
|
||||||
|
echo "Error: Test script $TEST_SCRIPT not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run the test script
|
||||||
|
if [[ $TEST_SCRIPT == *.py ]]; then
|
||||||
|
# Check if Python and required packages are available
|
||||||
|
if ! command -v python3 &> /dev/null; then
|
||||||
|
echo "Error: Python 3 is required to run Python test scripts"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if requests module is available
|
||||||
|
python3 -c "import requests" 2>/dev/null || {
|
||||||
|
echo "Error: 'requests' module is required. Install with: pip install requests"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
python3 "$TEST_SCRIPT"
|
||||||
|
elif [[ $TEST_SCRIPT == *.sh ]]; then
|
||||||
|
# Make sure the script is executable
|
||||||
|
chmod +x "$TEST_SCRIPT"
|
||||||
|
./"$TEST_SCRIPT"
|
||||||
|
else
|
||||||
|
echo "Error: Unknown script type for $TEST_SCRIPT"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -e "${GREEN}Test completed!${NC}"
|
||||||
@@ -1,15 +1,30 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Simple bash script to test drone detection API with curl
|
# Simple bash script to test drone detection API with curl
|
||||||
|
|
||||||
API_BASE="http://selfservice.cqers.com/drones/api"
|
# Load environment variables from .env file if it exists
|
||||||
# Alternative for local testing: "http://localhost:3002/api"
|
if [ -f ".env" ]; then
|
||||||
|
export $(grep -v '^#' .env | xargs)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Configuration from environment variables
|
||||||
|
API_BASE_URL=${API_BASE_URL:-"http://localhost:3002/api"}
|
||||||
|
BASE_PATH=${VITE_BASE_PATH:-""}
|
||||||
|
|
||||||
|
# If BASE_PATH is set, construct the full URL
|
||||||
|
if [ ! -z "$BASE_PATH" ] && [[ ! "$API_BASE_URL" == *"/api" ]]; then
|
||||||
|
# Remove any existing path suffixes and add base path
|
||||||
|
DOMAIN=$(echo "$API_BASE_URL" | sed 's|/api$||' | sed 's|/drones/api$||' | sed 's|/uggla/api$||')
|
||||||
|
API_BASE_URL="${DOMAIN}${BASE_PATH}/api"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "🚁 Drone Detection API Test Script"
|
echo "🚁 Drone Detection API Test Script"
|
||||||
echo "=================================="
|
echo "=================================="
|
||||||
|
echo "🔗 Using API Base URL: $API_BASE_URL"
|
||||||
|
echo ""
|
||||||
|
|
||||||
# Test API health
|
# Test API health
|
||||||
echo "🔍 Testing API health..."
|
echo "🔍 Testing API health..."
|
||||||
curl -s "$API_BASE/health" | jq '.' || echo "Health check failed"
|
curl -s "$API_BASE_URL/health" | jq '.' || echo "Health check failed"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Send test detection data
|
# Send test detection data
|
||||||
@@ -39,7 +54,7 @@ echo ""
|
|||||||
# Send the detection
|
# Send the detection
|
||||||
echo "Sending detection..."
|
echo "Sending detection..."
|
||||||
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
|
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
|
||||||
-X POST "$API_BASE/detections" \
|
-X POST "$API_BASE_URL/detectors" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "$DETECTION_DATA")
|
-d "$DETECTION_DATA")
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,20 @@ import time
|
|||||||
import random
|
import random
|
||||||
import math
|
import math
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
# Configuration
|
# Configuration from environment variables
|
||||||
API_BASE_URL = "https://selfservice.cqers.com/drones/api"
|
API_BASE_URL = os.getenv('API_BASE_URL', 'http://localhost:3002/api')
|
||||||
# Alternative for local testing: "http://localhost:3002/api"
|
BASE_PATH = os.getenv('VITE_BASE_PATH', '').rstrip('/')
|
||||||
|
|
||||||
|
# If BASE_PATH is set, construct the full URL
|
||||||
|
if BASE_PATH and not API_BASE_URL.endswith('/api'):
|
||||||
|
# Extract domain from API_BASE_URL and add base path
|
||||||
|
domain = API_BASE_URL.replace('/api', '').replace('/drones/api', '').replace('/uggla/api', '')
|
||||||
|
API_BASE_URL = f"{domain}{BASE_PATH}/api"
|
||||||
|
|
||||||
|
print(f"🔗 Using API Base URL: {API_BASE_URL}")
|
||||||
|
|
||||||
# Debug configuration
|
# Debug configuration
|
||||||
DEBUG_MODE = False # Set to True to enable payload debugging
|
DEBUG_MODE = False # Set to True to enable payload debugging
|
||||||
|
|||||||
@@ -15,10 +15,20 @@ import requests
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# Configuration
|
# Configuration from environment variables
|
||||||
API_BASE_URL = "http://selfservice.cqers.com/drones/api"
|
API_BASE_URL = os.getenv('API_BASE_URL', 'http://localhost:3002/api')
|
||||||
|
BASE_PATH = os.getenv('VITE_BASE_PATH', '').rstrip('/')
|
||||||
|
|
||||||
|
# If BASE_PATH is set, construct the full URL
|
||||||
|
if BASE_PATH and not API_BASE_URL.endswith('/api'):
|
||||||
|
# Extract domain from API_BASE_URL and add base path
|
||||||
|
domain = API_BASE_URL.replace('/api', '').replace('/drones/api', '').replace('/uggla/api', '')
|
||||||
|
API_BASE_URL = f"{domain}{BASE_PATH}/api"
|
||||||
|
|
||||||
|
print(f"🔗 Using API Base URL: {API_BASE_URL}")
|
||||||
|
|
||||||
# Detection range parameters (approximate)
|
# Detection range parameters (approximate)
|
||||||
MAX_DETECTION_RANGE_KM = 25.0 # Maximum range for drone detection
|
MAX_DETECTION_RANGE_KM = 25.0 # Maximum range for drone detection
|
||||||
|
|||||||
@@ -9,10 +9,20 @@ import requests
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# Configuration
|
# Configuration from environment variables
|
||||||
API_BASE_URL = "http://selfservice.cqers.com/drones/api"
|
API_BASE_URL = os.getenv('API_BASE_URL', 'http://localhost:3002/api')
|
||||||
|
BASE_PATH = os.getenv('VITE_BASE_PATH', '').rstrip('/')
|
||||||
|
|
||||||
|
# If BASE_PATH is set, construct the full URL
|
||||||
|
if BASE_PATH and not API_BASE_URL.endswith('/api'):
|
||||||
|
# Extract domain from API_BASE_URL and add base path
|
||||||
|
domain = API_BASE_URL.replace('/api', '').replace('/drones/api', '').replace('/uggla/api', '')
|
||||||
|
API_BASE_URL = f"{domain}{BASE_PATH}/api"
|
||||||
|
|
||||||
|
print(f"🔗 Using API Base URL: {API_BASE_URL}")
|
||||||
|
|
||||||
def haversine_distance(lat1, lon1, lat2, lon2):
|
def haversine_distance(lat1, lon1, lat2, lon2):
|
||||||
"""Calculate distance between two points in kilometers"""
|
"""Calculate distance between two points in kilometers"""
|
||||||
|
|||||||
Reference in New Issue
Block a user