Files
AutoMarket/backend/test_lamoda_api.py

46 lines
1.4 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.lamoda_api import LamodaAPI
from backend.lamoda_api.exceptions import LamodaAPIError
def test_lamoda_api():
# Load environment variables
env_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(env_path)
# Check if key is loaded
api_key = os.getenv('LAMODA_API_KEY')
if not api_key:
print("Error: LAMODA_API_KEY must be in backend/.env")
return
print("Initializing LamodaAPI...")
api = LamodaAPI()
try:
# Test 1: Get Products
print("\n--- Testing Products API ---")
products_response = api.products.get_list(limit=5)
print("Success! Response keys:", products_response.keys())
# Depending on Lamoda's response wrapper, it might be in 'data' or 'items'
items = products_response.get("data", [])
if not items:
items = products_response.get("items", [])
print(f"Found {len(items)} products in catalog.")
except LamodaAPIError as e:
print(f"API Error: {e}")
except Exception as e:
print(f"Unexpected Error: {e}")
if __name__ == '__main__':
test_lamoda_api()