Files
OSIT-AE-API-FastAPI/tests/e2e/test_e2e_v3_action_download.py

72 lines
2.2 KiB
Python

import requests
import json
# Configuration
BASE_URL = "https://dev-api.oneskyit.com/v3/action/hosted_file"
API_KEY = "IDF68Em5X4HTZlswRNgepQ"
ACCOUNT_ID = "Q8lR8Ai8hx2FjbQ3C_EH1Q"
# This file was created during our earlier upload tests
VALID_FILE_ID = "2R06T6yuQLw"
# Use a known site key from the DB for the bypass test
# SITE_KEY = "..."
def test_download_standard():
print(f"--- Testing Standard Download via V3 Action: {VALID_FILE_ID} ---")
url = f"{BASE_URL}/{VALID_FILE_ID}/download"
headers = {
"X-Aether-API-Key": API_KEY,
"x-account-id": ACCOUNT_ID
}
try:
# We don't want to download the whole binary in a test, so we'll check headers
response = requests.get(url, headers=headers, stream=True)
print(f"Status: {response.status_code}")
print(f"Content-Type: {response.headers.get('Content-Type')}")
print(f"Content-Length: {response.headers.get('Content-Length')}")
if response.status_code == 200:
print("✅ Success: Standard download works.")
return True
else:
print(f"❌ Failed: {response.text}")
return False
except Exception as e:
print(f"💥 Exception: {e}")
return False
def test_download_streaming():
print(f"\n--- Testing Byte-Range Streaming: {VALID_FILE_ID} ---")
url = f"{BASE_URL}/{VALID_FILE_ID}/download"
headers = {
"X-Aether-API-Key": API_KEY,
"x-account-id": ACCOUNT_ID,
"Range": "bytes=0-10"
}
try:
response = requests.get(url, headers=headers)
print(f"Status: {response.status_code} (Expected 206)")
print(f"Content-Range: {response.headers.get('Content-Range')}")
if response.status_code == 206:
print("✅ Success: Byte-range streaming works.")
return True
else:
print(f"❌ Failed: {response.status_code}")
return False
except Exception as e:
print(f"💥 Exception: {e}")
return False
if __name__ == "__main__":
s1 = test_download_standard()
s2 = test_download_streaming()
if s1 and s2:
print("\n🎉 ALL DOWNLOAD ACTION TESTS PASSED!")
else:
print("\n❌ SOME TESTS FAILED.")