54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
import os
|
|
import sys
|
|
from dotenv import load_dotenv
|
|
|
|
# Add parent dir to path so we can import backend packages
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from backend.ae_api import AliExpressAPI
|
|
from backend.ae_api.exceptions import AEAPIError
|
|
|
|
def test_ae_api():
|
|
# Load environment variables
|
|
env_path = os.path.join(os.path.dirname(__file__), '.env')
|
|
load_dotenv(env_path)
|
|
|
|
# Check if key is loaded
|
|
api_token = os.getenv('AE_API_TOKEN')
|
|
user_id = os.getenv('AE_USER_ID')
|
|
|
|
if not api_token:
|
|
print("Error: AE_API_TOKEN must be in backend/.env")
|
|
return
|
|
|
|
print(f"Initializing AliExpressAPI...")
|
|
if not user_id:
|
|
print("Warning: AE_USER_ID not provided. Transactions API might fail.")
|
|
|
|
api = AliExpressAPI()
|
|
|
|
try:
|
|
# Test 1: Get Products Feeds (doesn't require user_id in URL)
|
|
print("\n--- Testing Products Feeds API ---")
|
|
feeds_response = api.products.get_products_feeds(limit=5)
|
|
print("Success! Response keys:", feeds_response.keys())
|
|
|
|
data = feeds_response.get("data", [])
|
|
print(f"Found {len(data)} feeds.")
|
|
|
|
if user_id:
|
|
# Test 2: Get Transactions
|
|
print("\n--- Testing Transactions API ---")
|
|
transactions_response = api.transactions.get_list(params={"limit": 5})
|
|
|
|
t_data = transactions_response.get("data", [])
|
|
print(f"Found {len(t_data)} transactions.")
|
|
|
|
except AEAPIError as e:
|
|
print(f"API Error: {e}")
|
|
except Exception as e:
|
|
print(f"Unexpected Error: {e}")
|
|
|
|
if __name__ == '__main__':
|
|
test_ae_api()
|