import requests
import json

# Configuration
BASE_URL = "http://localhost:5000" # Adjust if running on a different port
API_URL = f"{BASE_URL}/api/submit_job"

# Test Data
payload = {
    "username": "admin",
    "password": "admin123", # Default password from __init__.py
    "branch_name": "test_branch",
    "scenarios": ["scenario1", "scenario2"]
}

try:
    print(f"Sending POST request to {API_URL}...")
    response = requests.post(API_URL, json=payload)
    
    print(f"Status Code: {response.status_code}")
    print("Response JSON:")
    print(json.dumps(response.json(), indent=2))
    
    if response.status_code == 200:
        print("\nSUCCESS: Job submitted successfully.")
        job_id = response.json().get('job_id')
        
        # Test Status API
        if job_id:
            STATUS_URL = f"{BASE_URL}/api/job/{job_id}"
            print(f"\nTesting Status API: {STATUS_URL}")
            status_resp = requests.get(STATUS_URL)
            print(f"Status Code: {status_resp.status_code}")
            print("Status Response:")
            print(json.dumps(status_resp.json(), indent=2))
    else:
        print("\nFAILURE: Job submission failed.")
        
except Exception as e:
    print(f"\nERROR: Could not connect to server. Is it running? {e}")
