mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-21 01:11:09 -05:00
Add comprehensive tests for Parks API and models
- Implemented extensive test cases for the Parks API, covering endpoints for listing, retrieving, creating, updating, and deleting parks. - Added tests for filtering, searching, and ordering parks in the API. - Created tests for error handling in the API, including malformed JSON and unsupported methods. - Developed model tests for Park, ParkArea, Company, and ParkReview models, ensuring validation and constraints are enforced. - Introduced utility mixins for API and model testing to streamline assertions and enhance test readability. - Included integration tests to validate complete workflows involving park creation, retrieval, updating, and deletion.
This commit is contained in:
@@ -15,11 +15,17 @@ show_help() {
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " $0 Set up or update ThrillWiki automation"
|
||||
echo " $0 -y Non-interactive mode, use saved configuration"
|
||||
echo " $0 --reset Delete VM and config, start completely fresh"
|
||||
echo " $0 --reset-vm Delete VM only, keep configuration"
|
||||
echo " $0 --reset-config Delete config only, keep VM"
|
||||
echo " $0 --help Show this help message"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -y, --yes Non-interactive mode - use saved configuration"
|
||||
echo " and passwords without prompting. Requires existing"
|
||||
echo " configuration file with saved settings."
|
||||
echo ""
|
||||
echo "Reset Options:"
|
||||
echo " --reset Completely removes existing VM, disks, and config"
|
||||
echo " before starting fresh installation"
|
||||
@@ -31,6 +37,7 @@ show_help() {
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 # Normal setup/update"
|
||||
echo " $0 -y # Non-interactive setup with saved config"
|
||||
echo " $0 --reset # Complete fresh installation"
|
||||
echo " $0 --reset-vm # Fresh VM with saved settings"
|
||||
echo " $0 --reset-config # Re-configure existing VM"
|
||||
@@ -42,21 +49,44 @@ if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
show_help
|
||||
fi
|
||||
|
||||
# Parse reset flags
|
||||
# Parse command line flags
|
||||
RESET_ALL=false
|
||||
RESET_VM_ONLY=false
|
||||
RESET_CONFIG_ONLY=false
|
||||
NON_INTERACTIVE=false
|
||||
|
||||
if [[ "$1" == "--reset" ]]; then
|
||||
RESET_ALL=true
|
||||
echo "🔄 COMPLETE RESET MODE: Will delete VM and configuration"
|
||||
elif [[ "$1" == "--reset-vm" ]]; then
|
||||
RESET_VM_ONLY=true
|
||||
echo "🔄 VM RESET MODE: Will delete VM only, keep configuration"
|
||||
elif [[ "$1" == "--reset-config" ]]; then
|
||||
RESET_CONFIG_ONLY=true
|
||||
echo "🔄 CONFIG RESET MODE: Will delete configuration only, keep VM"
|
||||
fi
|
||||
# Process all arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-y|--yes)
|
||||
NON_INTERACTIVE=true
|
||||
echo "🤖 NON-INTERACTIVE MODE: Using saved configuration only"
|
||||
shift
|
||||
;;
|
||||
--reset)
|
||||
RESET_ALL=true
|
||||
echo "🔄 COMPLETE RESET MODE: Will delete VM and configuration"
|
||||
shift
|
||||
;;
|
||||
--reset-vm)
|
||||
RESET_VM_ONLY=true
|
||||
echo "🔄 VM RESET MODE: Will delete VM only, keep configuration"
|
||||
shift
|
||||
;;
|
||||
--reset-config)
|
||||
RESET_CONFIG_ONLY=true
|
||||
echo "🔄 CONFIG RESET MODE: Will delete configuration only, keep VM"
|
||||
shift
|
||||
;;
|
||||
--help|-h)
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
show_help
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
set -e
|
||||
|
||||
@@ -148,8 +178,75 @@ load_config() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function for non-interactive configuration loading
|
||||
load_non_interactive_config() {
|
||||
log "=== Non-Interactive Configuration Loading ==="
|
||||
|
||||
# Load saved configuration
|
||||
if ! load_config; then
|
||||
log_error "No saved configuration found. Cannot run in non-interactive mode."
|
||||
log_error "Please run the script without -y flag first to create initial configuration."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_success "Loaded saved configuration successfully"
|
||||
|
||||
# Check for required environment variables for passwords
|
||||
if [ -z "${UNRAID_PASSWORD:-}" ]; then
|
||||
log_error "UNRAID_PASSWORD environment variable not set."
|
||||
log_error "For non-interactive mode, set: export UNRAID_PASSWORD='your_password'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Handle GitHub authentication based on saved method
|
||||
if [ -n "$GITHUB_USERNAME" ] && [ "$GITHUB_API_ENABLED" = "true" ]; then
|
||||
if [ "$GITHUB_AUTH_METHOD" = "oauth" ]; then
|
||||
# Check if OAuth token is still valid
|
||||
if python3 "$SCRIPT_DIR/../github-auth.py" validate 2>/dev/null; then
|
||||
GITHUB_TOKEN=$(python3 "$SCRIPT_DIR/../github-auth.py" token)
|
||||
log "Using existing OAuth token"
|
||||
else
|
||||
log_error "OAuth token expired and cannot refresh in non-interactive mode"
|
||||
log_error "Please run without -y flag to re-authenticate with GitHub"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Personal access token method
|
||||
if [ -z "${GITHUB_TOKEN:-}" ]; then
|
||||
log_error "GITHUB_TOKEN environment variable not set."
|
||||
log_error "For non-interactive mode, set: export GITHUB_TOKEN='your_token'"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Handle webhook secret
|
||||
if [ "$WEBHOOK_ENABLED" = "true" ]; then
|
||||
if [ -z "${WEBHOOK_SECRET:-}" ]; then
|
||||
log_error "WEBHOOK_SECRET environment variable not set."
|
||||
log_error "For non-interactive mode, set: export WEBHOOK_SECRET='your_secret'"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
log_success "All required credentials loaded from environment variables"
|
||||
log "Configuration summary:"
|
||||
echo " Unraid Host: $UNRAID_HOST"
|
||||
echo " VM Name: $VM_NAME"
|
||||
echo " VM IP: $VM_IP"
|
||||
echo " Repository: $REPO_URL"
|
||||
echo " GitHub Auth: $GITHUB_AUTH_METHOD"
|
||||
echo " Webhook Enabled: $WEBHOOK_ENABLED"
|
||||
}
|
||||
|
||||
# Function to prompt for configuration
|
||||
prompt_unraid_config() {
|
||||
# In non-interactive mode, use saved config only
|
||||
if [ "$NON_INTERACTIVE" = "true" ]; then
|
||||
load_non_interactive_config
|
||||
return 0
|
||||
fi
|
||||
|
||||
log "=== Unraid VM Configuration ==="
|
||||
echo
|
||||
|
||||
@@ -315,22 +412,49 @@ prompt_unraid_config() {
|
||||
save_config
|
||||
log "Webhook configuration saved"
|
||||
|
||||
# Get VM IP address with proper range validation
|
||||
while true; do
|
||||
read -p "Enter VM IP address (192.168.20.10-192.168.20.100): " VM_IP
|
||||
if [[ "$VM_IP" =~ ^192\.168\.20\.([1-9][0-9]|100)$ ]]; then
|
||||
local ip_last_octet="${BASH_REMATCH[1]}"
|
||||
if [ "$ip_last_octet" -ge 10 ] && [ "$ip_last_octet" -le 100 ]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
echo "Invalid IP address. Please enter an IP in the range 192.168.20.10-192.168.20.100"
|
||||
done
|
||||
# Get VM network configuration preference
|
||||
echo
|
||||
log "=== Network Configuration ==="
|
||||
echo "Choose network configuration method:"
|
||||
echo "1. DHCP (automatic IP assignment - recommended)"
|
||||
echo "2. Static IP (manual IP configuration)"
|
||||
|
||||
# Set network configuration
|
||||
VM_GATEWAY="192.168.20.1"
|
||||
VM_NETMASK="255.255.255.0"
|
||||
VM_NETWORK="192.168.20.0/24"
|
||||
while true; do
|
||||
read -p "Select option (1-2): " network_choice
|
||||
case $network_choice in
|
||||
1)
|
||||
log "Using DHCP network configuration..."
|
||||
VM_IP="dhcp"
|
||||
VM_GATEWAY="192.168.20.1"
|
||||
VM_NETMASK="255.255.255.0"
|
||||
VM_NETWORK="192.168.20.0/24"
|
||||
NETWORK_MODE="dhcp"
|
||||
break
|
||||
;;
|
||||
2)
|
||||
log "Using static IP network configuration..."
|
||||
# Get VM IP address with proper range validation
|
||||
while true; do
|
||||
read -p "Enter VM IP address (192.168.20.10-192.168.20.100): " VM_IP
|
||||
if [[ "$VM_IP" =~ ^192\.168\.20\.([1-9][0-9]|100)$ ]]; then
|
||||
local ip_last_octet="${BASH_REMATCH[1]}"
|
||||
if [ "$ip_last_octet" -ge 10 ] && [ "$ip_last_octet" -le 100 ]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
echo "Invalid IP address. Please enter an IP in the range 192.168.20.10-192.168.20.100"
|
||||
done
|
||||
VM_GATEWAY="192.168.20.1"
|
||||
VM_NETMASK="255.255.255.0"
|
||||
VM_NETWORK="192.168.20.0/24"
|
||||
NETWORK_MODE="static"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option. Please select 1 or 2."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Save final network configuration
|
||||
save_config
|
||||
@@ -545,25 +669,14 @@ create_vm() {
|
||||
source "$PROJECT_DIR/***REMOVED***.unraid"
|
||||
set +a # turn off automatic export
|
||||
|
||||
# Run VM creation/update
|
||||
# Run complete VM setup (builds ISO, creates VM, starts VM)
|
||||
cd "$PROJECT_DIR"
|
||||
python3 scripts/unraid/vm-manager.py setup
|
||||
python3 scripts/unraid/main.py setup
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
log_success "VM created/updated successfully"
|
||||
|
||||
# Start the VM
|
||||
log "Starting VM..."
|
||||
python3 scripts/unraid/vm-manager.py start
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
log_success "VM started successfully"
|
||||
else
|
||||
log_error "VM failed to start"
|
||||
exit 1
|
||||
fi
|
||||
log_success "VM setup completed successfully"
|
||||
else
|
||||
log_error "VM creation/update failed"
|
||||
log_error "VM setup failed"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -581,7 +694,7 @@ wait_for_vm() {
|
||||
local attempt=1
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
VM_IP=$(python3 scripts/unraid/vm-manager.py ip 2>/dev/null | grep "VM IP:" | cut -d' ' -f3)
|
||||
VM_IP=$(python3 scripts/unraid/main.py ip 2>/dev/null | grep "VM IP:" | cut -d' ' -f3)
|
||||
|
||||
if [ -n "$VM_IP" ]; then
|
||||
log_success "VM is ready with IP: $VM_IP"
|
||||
@@ -894,7 +1007,7 @@ main() {
|
||||
source "$PROJECT_DIR/***REMOVED***.unraid" 2>/dev/null || true
|
||||
set +a
|
||||
|
||||
if python3 "$(dirname "$0")/vm-manager.py" delete; then
|
||||
if python3 "$SCRIPT_DIR/vm-manager.py" delete; then
|
||||
log_success "VM deleted successfully"
|
||||
else
|
||||
log "⚠️ VM deletion failed or VM didn't exist"
|
||||
@@ -935,7 +1048,7 @@ main() {
|
||||
source "$PROJECT_DIR/***REMOVED***.unraid" 2>/dev/null || true
|
||||
set +a
|
||||
|
||||
if python3 "$(dirname "$0")/vm-manager.py" delete; then
|
||||
if python3 "$SCRIPT_DIR/vm-manager.py" delete; then
|
||||
log_success "VM deleted successfully"
|
||||
else
|
||||
log "⚠️ VM deletion failed or VM didn't exist"
|
||||
|
||||
Reference in New Issue
Block a user