first commit
This commit is contained in:
65
test_plans_endpoint.py
Normal file
65
test_plans_endpoint.py
Normal file
@@ -0,0 +1,65 @@
|
||||
"""
|
||||
Test script to diagnose the subscription plans endpoint issue.
|
||||
"""
|
||||
|
||||
from database import SessionLocal
|
||||
from models import SubscriptionPlan, Subscription, SubscriptionStatus
|
||||
|
||||
def test_plans_query():
|
||||
"""Test the same query that the endpoint uses"""
|
||||
db = SessionLocal()
|
||||
|
||||
try:
|
||||
print("Testing subscription plans query...\n")
|
||||
|
||||
# Step 1: Get all plans
|
||||
plans = db.query(SubscriptionPlan).order_by(SubscriptionPlan.created_at.desc()).all()
|
||||
print(f"✅ Found {len(plans)} plan(s)")
|
||||
|
||||
# Step 2: For each plan, get subscriber count (same as endpoint)
|
||||
result = []
|
||||
for plan in plans:
|
||||
print(f"\nProcessing plan: {plan.name}")
|
||||
|
||||
try:
|
||||
subscriber_count = db.query(Subscription).filter(
|
||||
Subscription.plan_id == plan.id,
|
||||
Subscription.status == SubscriptionStatus.active
|
||||
).count()
|
||||
print(f" ✓ Subscriber count: {subscriber_count}")
|
||||
except Exception as e:
|
||||
print(f" ❌ Error counting subscribers: {e}")
|
||||
raise
|
||||
|
||||
result.append({
|
||||
"id": str(plan.id),
|
||||
"name": plan.name,
|
||||
"description": plan.description,
|
||||
"price_cents": plan.price_cents,
|
||||
"billing_cycle": plan.billing_cycle,
|
||||
"stripe_price_id": plan.stripe_price_id,
|
||||
"active": plan.active,
|
||||
"subscriber_count": subscriber_count,
|
||||
"created_at": plan.created_at,
|
||||
"updated_at": plan.updated_at
|
||||
})
|
||||
|
||||
print("\n" + "="*50)
|
||||
print("✅ Query completed successfully!")
|
||||
print("="*50)
|
||||
for plan in result:
|
||||
print(f"\n{plan['name']}")
|
||||
print(f" Price: ${plan['price_cents']/100:.2f}")
|
||||
print(f" Cycle: {plan['billing_cycle']}")
|
||||
print(f" Active: {plan['active']}")
|
||||
print(f" Subscribers: {plan['subscriber_count']}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ ERROR: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_plans_query()
|
||||
Reference in New Issue
Block a user