diff --git a/.gitignore b/.gitignore index 684131f..ad30117 100644 --- a/.gitignore +++ b/.gitignore @@ -54,11 +54,16 @@ pytestdebug.log *.mo *.pot -# Django stuff: +# Database stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal +storyline.db + +# Test scripts +test_*.py +debug_db.py # Flask stuff: instance/ diff --git a/debug_db.py b/debug_db.py deleted file mode 100644 index bfdd5f7..0000000 --- a/debug_db.py +++ /dev/null @@ -1,18 +0,0 @@ -import psycopg2 -import os -from dotenv import load_dotenv - -load_dotenv() - -def test_db(): - url = os.getenv("DATABASE_URL") - print(f"Testing connection to: {url.split('@')[-1]}") - try: - conn = psycopg2.connect(url) - print("Raw psycopg2 connection successful!") - conn.close() - except Exception as e: - print(f"Raw psycopg2 connection failed: {e}") - -if __name__ == "__main__": - test_db() diff --git a/storyline.db b/storyline.db deleted file mode 100644 index 4b175b9..0000000 Binary files a/storyline.db and /dev/null differ diff --git a/test_api.py b/test_api.py deleted file mode 100644 index cb3e881..0000000 --- a/test_api.py +++ /dev/null @@ -1,96 +0,0 @@ -import httpx -import time - -BASE_URL = "http://127.0.0.1:8000/api/v1" -API_KEY = "storyline-secret-key-123" - -client = httpx.Client(timeout=30.0) - -def test_health(): - print("Testing Health Check...") - response = client.get(f"{BASE_URL}/storyline/health") - print(f"Status: {response.status_code}, Body: {response.json()}") - -def test_chat_unauthorized(): - print("\nTesting Chat (No Auth)...") - response = client.post(f"{BASE_URL}/storyline/chat", json={"prompt": "Hello"}) - print(f"Status: {response.status_code}, Body: {response.json()}") - -def test_chat_authorized(): - print("\nTesting Chat (Authorized)...") - headers = {"X-API-Key": API_KEY} - response = client.post( - f"{BASE_URL}/storyline/chat", - json={"prompt": "How do I use Storyline?", "context": "Module 1"}, - headers=headers - ) - print(f"Status: {response.status_code}, Body: {response.json()}") - -def test_rate_limit(): - print("\nTesting Rate Limit (making multiple calls)...") - headers = {"X-API-Key": API_KEY} - for i in range(22): - response = httpx.post( - f"{BASE_URL}/storyline/chat", - json={"prompt": f"Test {i}"}, - headers=headers - ) - if response.status_code == 429: - print(f"Rate limit hit at call {i+1}!") - return - print("Rate limit not hit (this is unexpected if limit is 20).") - -def test_gemini(): - print("\nTesting Gemini Endpoint...") - headers = {"X-API-Key": API_KEY} - response = client.post(f"{BASE_URL}/gemini/chat", json={"prompt": "Hello Gemini"}, headers=headers) - print(f"Status: {response.status_code}, Body: {response.json()}") - -def test_openai(): - print("\nTesting OpenAI Endpoint...") - headers = {"X-API-Key": API_KEY} - response = client.post(f"{BASE_URL}/openai/chat", json={"prompt": "Hello OpenAI"}, headers=headers) - print(f"Status: {response.status_code}, Body: {response.json()}") - -def test_module_management(): - print("\nTesting Module Management...") - headers = {"X-API-Key": API_KEY} - - # 1. Create a module - print("Creating module 'Articulate 101'...") - response = client.post( - f"{BASE_URL}/admin/modules", - json={"name": "Articulate 101"}, - headers=headers - ) - if response.status_code == 400: - print("Module already exists, getting list...") - response = client.get(f"{BASE_URL}/admin/modules", headers=headers) - module_data = response.json()[0] - else: - module_data = response.json() - - new_module_key = module_data["secret_key"] - print(f"Module created/found. Secret Key: {new_module_key}") - - # 2. Use the new module key to call Gemini - print("\nTesting Gemini with NEW module key...") - module_headers = {"X-API-Key": new_module_key} - response = client.post( - f"{BASE_URL}/gemini/chat", - json={"prompt": "Can you see this with my module key?"}, - headers=module_headers - ) - print(f"Status: {response.status_code}, Body: {response.json()}") - -if __name__ == "__main__": - try: - test_health() - test_chat_unauthorized() - test_chat_authorized() - test_gemini() - test_openai() - test_module_management() - # test_rate_limit() - except Exception as e: - print(f"Error: {e}") diff --git a/test_supabase.py b/test_supabase.py deleted file mode 100644 index 7c84d73..0000000 --- a/test_supabase.py +++ /dev/null @@ -1,47 +0,0 @@ -import httpx - -BASE_URL = "http://127.0.0.1:8000" -USERNAME = "admin" -PASSWORD = "Spear0yale!" - -def test_supabase_integration(): - client = httpx.Client(timeout=30.0) - - print("1. Logging into Admin Panel...") - login_data = {"username": USERNAME, "password": PASSWORD} - response = client.post(f"{BASE_URL}/auth/login", data=login_data) - - if response.status_code != 200: - print(f"Login failed: {response.status_code} - {response.text}") - return - - token = response.json()["access_token"] - headers = {"Authorization": f"Bearer {token}"} - print("Login successful.") - - print("\n2. Creating a module...") - module_name = "Supabase_Integration_Live" - response = client.post( - f"{BASE_URL}/internal/admin/modules", - json={"name": "Supabase_Integration_Live"}, - headers=headers - ) - - if response.status_code == 400 and "already exists" in response.text: - print("Module already exists, testing rotation...") - # Get modules to find the ID - get_res = client.get(f"{BASE_URL}/internal/admin/modules", headers=headers) - modules = get_res.json() - target = next(m for m in modules if m["name"] == "Supabase_Integration_Live") - - rotate_res = client.post(f"{BASE_URL}/internal/admin/modules/{target['id']}/rotate", headers=headers) - print(f"Rotation status: {rotate_res.status_code}") - print(f"New Key Sample: {rotate_res.json()['secret_key'][:10]}...") - elif response.status_code == 201 or response.status_code == 200: - print("Module created successfully on Supabase!") - print(f"Key: {response.json()['secret_key']}") - else: - print(f"Failed to create module: {response.status_code} - {response.text}") - -if __name__ == "__main__": - test_supabase_integration()