ifixkart-backend/test_notifications.py
adithiyan 10bfba7d58 feat: add warranties, refunds, notifications, CRM calendar, system config & delivery modules
- New models: WarrantyModel, WalletModel, SystemConfigModel
- New schemas: WarrantySchema, RefundSchema, SystemConfig, CrmTaskCalendar, NotificationTemplate, NotificationGateway, RepairErp, ReviewModeration, InventoryPos, MultiDashboard, BillingFinance
- New services: WarrantyService, RefundService, CrmService, CrmTaskCalendarService, DeliveryService, EmailTemplateService, InventoryPosService, MultiDashboardService, NotificationGatewayService, RepairErpService, ReviewModerationService, SystemConfigService, TemplateService, CreditService
- Updated routers: AdminOrder, BillingFinance, Cart, Catalog, Checkout, Crm, InventoryPos, NotificationGateway, RolePermission, ServiceJob, Settings, Storefront, UserCreation
- Updated models: Inventory, Notification, Order, Product, Service, Setting, SystemConfig, User
- Updated core: database init, invoice generator, main app
- Added WarrantyRouter with full CRUD and claim flow
2026-10-13 22:05:16 +05:30

63 lines
2.5 KiB
Python

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from app.core.database.db_session import SessionLocal
from app.services.NotificationGatewayService import NotificationGatewayService
from app.services.TemplateService import TemplateService, EVENT_REGISTRY
from app.schemas.NotificationGateway import NotificationDispatchCreate
def run_tests():
db = SessionLocal()
tenant_id = "tenant_default"
for event_key, data in EVENT_REGISTRY.items():
print(f"Triggering {event_key}...")
# Build mock context
mock_context = {}
for var in data["variables"]:
if var["name"] == "items":
mock_context["items"] = [{"product_name": "Test Item 1", "sku": "SKU-1", "quantity": 1, "unit_price": 500}]
else:
name_val = var.get("name")
mock_context[var["name"]] = var.get("example", f"[{name_val}]")
# Try for EMAIL
rendered_email = TemplateService.render_template(db, event_key, "EMAIL", mock_context, tenant_id)
if not rendered_email:
rendered_email = (f"Test Subject: {event_key}", f"<p>This is a test fallback email for {event_key}. Context: {mock_context}</p>")
subj, body = rendered_email
payload = NotificationDispatchCreate(
recipient="adithiyan.elan@gmail.com",
channel="EMAIL",
subject=subj,
message_body=body
)
try:
NotificationGatewayService.dispatch_notification(db, tenant_id, payload)
print(f" -> Dispatched EMAIL (rerouted to Adithiyan)")
except Exception as e:
print(f" -> EMAIL failed: {e}")
# Try for WHATSAPP
rendered_wa = TemplateService.render_template(db, event_key, "WHATSAPP", mock_context, tenant_id)
if not rendered_wa:
rendered_wa = (None, f"[Test {event_key}] Context: {mock_context}")
subj, body = rendered_wa
payload = NotificationDispatchCreate(
recipient="919080323589",
channel="WHATSAPP",
subject=subj,
message_body=body
)
try:
NotificationGatewayService.dispatch_notification(db, tenant_id, payload)
print(f" -> Dispatched WHATSAPP (rerouted to Adithiyan)")
except Exception as e:
print(f" -> WHATSAPP failed: {e}")
if __name__ == "__main__":
run_tests()