"""
Test OneDrive MCP endpoints.
"""
import base64
import requests
BASE_URL = "http://localhost:8001"
def test_onedrive_upload_file():
"""Test uploading a file to OneDrive."""
print("\n=== Testing OneDrive Upload ===")
# Create test content
test_content = "This is a test file for IRIS MCP Server OneDrive testing.\nLine 2\nLine 3"
content_base64 = base64.b64encode(test_content.encode()).decode()
payload = {
"file_path": "/test_iris_upload.txt",
"content_base64": content_base64
}
response = requests.post(f"{BASE_URL}/onedrive/upload", json=payload)
print(f"Status: {response.status_code}")
assert response.status_code == 200, f"Expected 200, got {response.status_code}"
data = response.json()
assert data.get('success') is True, "Upload should succeed"
assert data.get('file') is not None, "Should return file info"
file_info = data['file']
assert file_info.get('id') is not None, "File should have ID"
assert file_info.get('name') == 'test_iris_upload.txt', "File name mismatch"
assert file_info.get('size') == len(test_content), "File size mismatch"
print(f"✓ File uploaded successfully: {file_info.get('id')}")
return file_info.get('id')
def test_onedrive_download_file():
"""Test downloading a file from OneDrive."""
print("\n=== Testing OneDrive Download ===")
# Use known path from upload test
response = requests.get(f"{BASE_URL}/onedrive/download?item_path=/test_iris_upload.txt")
print(f"Status: {response.status_code}")
assert response.status_code == 200, f"Expected 200, got {response.status_code}"
content = response.content
assert len(content) > 0, "Downloaded content should not be empty"
# Verify content
expected_content = b"This is a test file for IRIS MCP Server OneDrive testing.\nLine 2\nLine 3"
assert content == expected_content, "Downloaded content doesn't match uploaded content"
print(f"✓ File downloaded successfully: {len(content)} bytes")
return True
def test_onedrive_list_files():
"""Test listing files in OneDrive root."""
print("\n=== Testing OneDrive List Files ===")
response = requests.get(f"{BASE_URL}/onedrive/root")
print(f"Status: {response.status_code}")
assert response.status_code == 200, f"Expected 200, got {response.status_code}"
data = response.json()
assert 'items' in data, "Response should contain items"
items = data['items']
print(f"✓ Found {len(items)} items in OneDrive root")
# Check if our test file is there
test_file = next((item for item in items if item.get('name') == 'test_iris_upload.txt'), None)
if test_file:
print(f"✓ Test file found: {test_file.get('name')}")
return True
if __name__ == "__main__":
print("=" * 60)
print("IRIS MCP Server - OneDrive Tests")
print("=" * 60)
results = {}
try:
file_id = test_onedrive_upload_file()
results['upload'] = True
except AssertionError as e:
print(f"✗ Upload failed: {e}")
results['upload'] = False
file_id = None
try:
results['download'] = test_onedrive_download_file()
except AssertionError as e:
print(f"✗ Download failed: {e}")
results['download'] = False
try:
results['list'] = test_onedrive_list_files()
except AssertionError as e:
print(f"✗ List failed: {e}")
results['list'] = False
# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
passed = sum(1 for v in results.values() if v)
total = len(results)
for test, result in results.items():
status = "✓ PASS" if result else "✗ FAIL"
print(f"{status} - {test}")
print(f"\nPassed: {passed}/{total} ({passed/total*100:.0f}%)")
print("=" * 60)
exit(0 if passed == total else 1)