-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
62 lines (55 loc) · 2.12 KB
/
test_api.py
File metadata and controls
62 lines (55 loc) · 2.12 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
"""
Simple script to test the Flask API with EJ log files
"""
import requests
import json
from pathlib import Path
# Test health endpoint
print("Testing health endpoint...")
try:
response = requests.get("http://127.0.0.1:5000/health", timeout=5)
print(f"Health Status: {response.status_code}")
print(f"Response: {response.json()}")
except Exception as e:
print(f"Health check failed: {e}")
# Test EJ controller health
print("\nTesting EJ controller health...")
try:
response = requests.get("http://127.0.0.1:5000/api/ej/health", timeout=5)
print(f"EJ Health Status: {response.status_code}")
print(f"Response: {response.json()}")
except Exception as e:
print(f"EJ health check failed: {e}")
# Test load_logs endpoint with an EJ file
print("\nTesting load_logs endpoint with EJ file...")
try:
# Get the first EJ log file
ej_files_dir = Path("F:/NW/NetCon/NetCon/ej-logs/CRM-EJBackups")
ej_files = list(ej_files_dir.glob("EJCRM*.0*"))
if ej_files:
test_file = ej_files[0]
print(f"Using test file: {test_file}")
with open(test_file, 'rb') as f:
files = {'files': (test_file.name, f, 'application/octet-stream')}
response = requests.post(
"http://127.0.0.1:5000/api/ej/load_logs",
files=files,
timeout=30
)
print(f"Load logs Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"\nSummary:")
print(json.dumps(result.get('summary', {}), indent=2))
print(f"\nTransactions extracted: {len(result.get('transactions', []))}")
if result.get('transactions'):
print(f"\nFirst transaction sample:")
print(json.dumps(result['transactions'][0], indent=2))
else:
print(f"Response: {response.text}")
else:
print("No EJ files found in the directory")
except Exception as e:
print(f"Load logs test failed: {e}")
import traceback
traceback.print_exc()