2025-11-10 15:46:40 +01:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
def test_billing_module_imports():
|
2025-11-13 20:42:43 +01:00
|
|
|
from mywebdav.billing import models, stripe_client, usage_tracker, invoice_generator, scheduler
|
2025-11-10 15:46:40 +01:00
|
|
|
assert models is not None
|
|
|
|
|
assert stripe_client is not None
|
|
|
|
|
assert usage_tracker is not None
|
|
|
|
|
assert invoice_generator is not None
|
|
|
|
|
assert scheduler is not None
|
|
|
|
|
|
|
|
|
|
def test_billing_models_exist():
|
2025-11-13 20:42:43 +01:00
|
|
|
from mywebdav.billing.models import (
|
2025-11-10 15:46:40 +01:00
|
|
|
SubscriptionPlan, UserSubscription, UsageRecord, UsageAggregate,
|
|
|
|
|
Invoice, InvoiceLineItem, PricingConfig, PaymentMethod, BillingEvent
|
|
|
|
|
)
|
|
|
|
|
assert SubscriptionPlan is not None
|
|
|
|
|
assert UserSubscription is not None
|
|
|
|
|
assert UsageRecord is not None
|
|
|
|
|
assert UsageAggregate is not None
|
|
|
|
|
assert Invoice is not None
|
|
|
|
|
assert InvoiceLineItem is not None
|
|
|
|
|
assert PricingConfig is not None
|
|
|
|
|
assert PaymentMethod is not None
|
|
|
|
|
assert BillingEvent is not None
|
|
|
|
|
|
|
|
|
|
def test_stripe_client_exists():
|
2025-11-13 20:42:43 +01:00
|
|
|
from mywebdav.billing.stripe_client import StripeClient
|
2025-11-10 15:46:40 +01:00
|
|
|
assert StripeClient is not None
|
|
|
|
|
assert hasattr(StripeClient, 'create_customer')
|
|
|
|
|
assert hasattr(StripeClient, 'create_invoice')
|
|
|
|
|
assert hasattr(StripeClient, 'finalize_invoice')
|
|
|
|
|
|
|
|
|
|
def test_usage_tracker_exists():
|
2025-11-13 20:42:43 +01:00
|
|
|
from mywebdav.billing.usage_tracker import UsageTracker
|
2025-11-10 15:46:40 +01:00
|
|
|
assert UsageTracker is not None
|
|
|
|
|
assert hasattr(UsageTracker, 'track_storage')
|
|
|
|
|
assert hasattr(UsageTracker, 'track_bandwidth')
|
|
|
|
|
assert hasattr(UsageTracker, 'aggregate_daily_usage')
|
|
|
|
|
assert hasattr(UsageTracker, 'get_current_storage')
|
|
|
|
|
assert hasattr(UsageTracker, 'get_monthly_usage')
|
|
|
|
|
|
|
|
|
|
def test_invoice_generator_exists():
|
2025-11-13 20:42:43 +01:00
|
|
|
from mywebdav.billing.invoice_generator import InvoiceGenerator
|
2025-11-10 15:46:40 +01:00
|
|
|
assert InvoiceGenerator is not None
|
|
|
|
|
assert hasattr(InvoiceGenerator, 'generate_monthly_invoice')
|
|
|
|
|
assert hasattr(InvoiceGenerator, 'finalize_invoice')
|
|
|
|
|
assert hasattr(InvoiceGenerator, 'mark_invoice_paid')
|
|
|
|
|
|
|
|
|
|
def test_scheduler_exists():
|
2025-11-13 20:42:43 +01:00
|
|
|
from mywebdav.billing.scheduler import scheduler, start_scheduler, stop_scheduler
|
2025-11-10 15:46:40 +01:00
|
|
|
assert scheduler is not None
|
|
|
|
|
assert callable(start_scheduler)
|
|
|
|
|
assert callable(stop_scheduler)
|
|
|
|
|
|
|
|
|
|
def test_routers_exist():
|
2025-11-13 20:42:43 +01:00
|
|
|
from mywebdav.routers import billing, admin_billing
|
2025-11-10 15:46:40 +01:00
|
|
|
assert billing is not None
|
|
|
|
|
assert admin_billing is not None
|
|
|
|
|
assert hasattr(billing, 'router')
|
|
|
|
|
assert hasattr(admin_billing, 'router')
|
|
|
|
|
|
|
|
|
|
def test_middleware_exists():
|
2025-11-13 20:42:43 +01:00
|
|
|
from mywebdav.middleware.usage_tracking import UsageTrackingMiddleware
|
2025-11-10 15:46:40 +01:00
|
|
|
assert UsageTrackingMiddleware is not None
|
|
|
|
|
|
|
|
|
|
def test_settings_updated():
|
2025-11-13 20:42:43 +01:00
|
|
|
from mywebdav.settings import settings
|
2025-11-10 15:46:40 +01:00
|
|
|
assert hasattr(settings, 'STRIPE_SECRET_KEY')
|
|
|
|
|
assert hasattr(settings, 'STRIPE_PUBLISHABLE_KEY')
|
|
|
|
|
assert hasattr(settings, 'STRIPE_WEBHOOK_SECRET')
|
|
|
|
|
assert hasattr(settings, 'BILLING_ENABLED')
|
|
|
|
|
|
|
|
|
|
def test_main_includes_billing():
|
2025-11-13 20:42:43 +01:00
|
|
|
from mywebdav.main import app
|
2025-11-10 15:46:40 +01:00
|
|
|
routes = [route.path for route in app.routes]
|
|
|
|
|
billing_routes = [r for r in routes if '/billing' in r]
|
|
|
|
|
assert len(billing_routes) > 0
|