58 lines
2.6 KiB
Python
58 lines
2.6 KiB
Python
import requests
|
|
import os
|
|
|
|
def test_file_upload():
|
|
# Test the upload endpoint
|
|
file_path = 'data/sample-data.xlsx'
|
|
|
|
if not os.path.exists(file_path):
|
|
print("Error: Sample file not found")
|
|
return
|
|
|
|
print("=== FILE UPLOAD TEST ===")
|
|
print(f"Testing upload of: {file_path}")
|
|
|
|
# Test upload endpoint
|
|
with open(file_path, 'rb') as f:
|
|
files = {'file': f}
|
|
try:
|
|
response = requests.post('http://localhost:8080/upload', files=files, timeout=30)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
if data.get('success'):
|
|
print("✓ File upload successful!")
|
|
print(f" Uploaded filename: {data['filename']}")
|
|
print(f" Server file path: {data['file_path']}")
|
|
|
|
# Test analysis of uploaded file
|
|
print("✓ Testing analysis of uploaded file...")
|
|
analyze_response = requests.post('http://localhost:8080/analyze',
|
|
json={'file_path': data['file_path']},
|
|
timeout=30)
|
|
|
|
if analyze_response.status_code == 200:
|
|
analyze_data = analyze_response.json()
|
|
if analyze_data.get('success'):
|
|
print("✓ Analysis of uploaded file successful!")
|
|
results = analyze_data['results']
|
|
print(f" Sheets found: {results['sheet_names']}")
|
|
print(f" Matched items: {results['matched_items_count']}")
|
|
print(f" Different items: {results['mismatches']['kst_only_count'] + results['mismatches']['coordi_only_count']}")
|
|
else:
|
|
print(f"✗ Analysis failed: {analyze_data.get('error')}")
|
|
else:
|
|
print(f"✗ Analysis request failed: {analyze_response.status_code}")
|
|
|
|
else:
|
|
print(f"✗ Upload failed: {data.get('error')}")
|
|
else:
|
|
print(f"✗ Upload request failed: {response.status_code}")
|
|
print(f"Response: {response.text}")
|
|
|
|
except requests.exceptions.RequestException as e:
|
|
print(f"✗ Request failed: {e}")
|
|
print("Make sure the Flask server is running at http://localhost:8080")
|
|
|
|
if __name__ == "__main__":
|
|
test_file_upload() |