feat: implement backend API clients for multi-marketplace integration and frontend service layer
This commit is contained in:
53
backend/test_ae_api.py
Normal file
53
backend/test_ae_api.py
Normal file
@@ -0,0 +1,53 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user