78 lines
2.9 KiB
Python
78 lines
2.9 KiB
Python
|
|
import pytest
|
||
|
|
|
||
|
|
def test_billing_module_imports():
|
||
|
|
from rbox.billing import models, stripe_client, usage_tracker, invoice_generator, scheduler
|
||
|
|
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():
|
||
|
|
from rbox.billing.models import (
|
||
|
|
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():
|
||
|
|
from rbox.billing.stripe_client import StripeClient
|
||
|
|
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():
|
||
|
|
from rbox.billing.usage_tracker import UsageTracker
|
||
|
|
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():
|
||
|
|
from rbox.billing.invoice_generator import InvoiceGenerator
|
||
|
|
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():
|
||
|
|
from rbox.billing.scheduler import scheduler, start_scheduler, stop_scheduler
|
||
|
|
assert scheduler is not None
|
||
|
|
assert callable(start_scheduler)
|
||
|
|
assert callable(stop_scheduler)
|
||
|
|
|
||
|
|
def test_routers_exist():
|
||
|
|
from rbox.routers import billing, admin_billing
|
||
|
|
assert billing is not None
|
||
|
|
assert admin_billing is not None
|
||
|
|
assert hasattr(billing, 'router')
|
||
|
|
assert hasattr(admin_billing, 'router')
|
||
|
|
|
||
|
|
def test_middleware_exists():
|
||
|
|
from rbox.middleware.usage_tracking import UsageTrackingMiddleware
|
||
|
|
assert UsageTrackingMiddleware is not None
|
||
|
|
|
||
|
|
def test_settings_updated():
|
||
|
|
from rbox.settings import settings
|
||
|
|
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():
|
||
|
|
from rbox.main import app
|
||
|
|
routes = [route.path for route in app.routes]
|
||
|
|
billing_routes = [r for r in routes if '/billing' in r]
|
||
|
|
assert len(billing_routes) > 0
|