-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_app.py
More file actions
67 lines (56 loc) · 2.49 KB
/
test_app.py
File metadata and controls
67 lines (56 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
"""
Simple test script to verify the Flask application works correctly.
This can be run locally to test the containerized application.
"""
import requests
import time
import sys
import os
def test_application(base_url="http://localhost:8000"):
"""Test the Flask application endpoints."""
print(f"Testing application at {base_url}")
try:
# Test 1: Health check - GET /
print("1. Testing home page...")
response = requests.get(f"{base_url}/", timeout=10)
assert response.status_code == 200, f"Expected 200, got {response.status_code}"
assert "Upload a File" in response.text, "Home page should contain upload form"
print(" ✅ Home page accessible")
# Test 2: Files listing page
print("2. Testing files listing...")
response = requests.get(f"{base_url}/files", timeout=10)
assert response.status_code == 200, f"Expected 200, got {response.status_code}"
print(" ✅ Files page accessible")
# Test 3: Upload test (this will fail without proper Azure credentials, but tests the endpoint)
print("3. Testing file upload endpoint...")
try:
response = requests.post(
f"{base_url}/upload",
data={
"filename": "test.txt",
"file_content": "Hello, Container Apps!"
},
timeout=10
)
# We expect either a redirect (302) or an error page, but not a 404 or 500
assert response.status_code in [200, 302, 400], f"Upload endpoint returned {response.status_code}"
print(" ✅ Upload endpoint responding")
except Exception as e:
print(f" ⚠️ Upload test failed (expected without Azure credentials): {e}")
print("\n🎉 All basic tests passed! Application is working correctly.")
return True
except requests.exceptions.ConnectionError:
print(f" ❌ Cannot connect to {base_url}. Is the application running?")
return False
except Exception as e:
print(f" ❌ Test failed: {e}")
return False
if __name__ == "__main__":
# Allow custom URL from command line
url = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:8000"
# Wait a moment for the server to start up
print("Waiting for server to start...")
time.sleep(5)
success = test_application(url)
sys.exit(0 if success else 1)