| |
| """ |
| Test script for Gift Card Template API endpoints. |
| This script demonstrates the usage of the gift card template endpoints. |
| """ |
|
|
| import asyncio |
| import sys |
| import os |
|
|
| |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) |
|
|
| from app.schemas.gift_card_schema import ( |
| GiftCardTemplateCreate, |
| GiftCardTemplateUpdate, |
| DesignTemplate |
| ) |
|
|
| def test_gift_card_schemas(): |
| """Test gift card schema validation.""" |
| print("Testing Gift Card Template Schemas...") |
| |
| |
| try: |
| digital_template = GiftCardTemplateCreate( |
| name="Digital Birthday Card", |
| description="Special digital card for birthdays", |
| delivery_type="digital", |
| currency="INR", |
| validity_days=365, |
| allow_custom_amount=True, |
| predefined_amounts=[500, 1000, 2000], |
| reloadable=False, |
| allow_partial_redemption=True, |
| requires_pin=True, |
| requires_otp=False, |
| status="active", |
| design_template=DesignTemplate( |
| theme="blue", |
| image_url="https://example.com/birthday.png" |
| ), |
| created_by="admin_123" |
| ) |
| print("β Digital template schema validation passed") |
| print(f" Template name: {digital_template.name}") |
| print(f" Delivery type: {digital_template.delivery_type}") |
| print(f" Currency: {digital_template.currency}") |
| except Exception as e: |
| print(f"β Digital template schema validation failed: {e}") |
| return False |
| |
| |
| try: |
| physical_template = GiftCardTemplateCreate( |
| name="Physical Premium βΉ1000", |
| description="Premium physical plastic card with fixed denomination", |
| delivery_type="physical", |
| currency="INR", |
| validity_days=730, |
| allow_custom_amount=False, |
| predefined_amounts=[1000], |
| reloadable=False, |
| allow_partial_redemption=True, |
| requires_pin=True, |
| requires_otp=False, |
| status="active", |
| max_issues=500, |
| design_template=DesignTemplate( |
| theme="gold", |
| image_url="https://example.com/physical.png" |
| ), |
| branch_ids=["branch_1", "branch_2"], |
| campaign_id="campaign_holiday_2025", |
| metadata={"batch": "2025_holiday"}, |
| created_by="marketing_mgr" |
| ) |
| print("β Physical template schema validation passed") |
| print(f" Template name: {physical_template.name}") |
| print(f" Max issues: {physical_template.max_issues}") |
| print(f" Branch IDs: {physical_template.branch_ids}") |
| except Exception as e: |
| print(f"β Physical template schema validation failed: {e}") |
| return False |
| |
| |
| try: |
| update_template = GiftCardTemplateUpdate( |
| status="inactive", |
| predefined_amounts=[1000, 2000] |
| ) |
| print("β Update template schema validation passed") |
| print(f" Status update: {update_template.status}") |
| print(f" Amounts update: {update_template.predefined_amounts}") |
| except Exception as e: |
| print(f"β Update template schema validation failed: {e}") |
| return False |
| |
| |
| try: |
| |
| GiftCardTemplateCreate( |
| name="Invalid Physical Card", |
| delivery_type="physical", |
| currency="INR", |
| allow_custom_amount=True, |
| reloadable=False, |
| allow_partial_redemption=True, |
| requires_pin=True, |
| requires_otp=False, |
| status="active", |
| created_by="admin_123" |
| ) |
| print("β Validation error test failed - should have caught missing max_issues") |
| return False |
| except ValueError as e: |
| print("β Validation error correctly caught:", str(e)) |
| |
| try: |
| |
| GiftCardTemplateCreate( |
| name="Invalid Amounts Card", |
| delivery_type="digital", |
| currency="INR", |
| allow_custom_amount=False, |
| reloadable=False, |
| allow_partial_redemption=True, |
| requires_pin=True, |
| requires_otp=False, |
| status="active", |
| created_by="admin_123" |
| ) |
| print("β Validation error test failed - should have caught missing amounts config") |
| return False |
| except ValueError as e: |
| print("β Validation error correctly caught:", str(e)) |
| |
| return True |
|
|
| def test_models_import(): |
| """Test that all models can be imported successfully.""" |
| try: |
| from app.models.gift_card_models import GiftCardTemplateModel |
| from app.repositories.gift_card_repository import GiftCardRepository |
| from app.services.gift_card_service import GiftCardService |
| from app.routers.gift_card_router import router |
| |
| print("β All modules imported successfully") |
| print(f" Model: {GiftCardTemplateModel.__name__}") |
| print(f" Repository: {GiftCardRepository.__name__}") |
| print(f" Service: {GiftCardService.__name__}") |
| print(f" Router: {router.__class__.__name__}") |
| return True |
| except ImportError as e: |
| print(f"β Import error: {e}") |
| return False |
|
|
| def main(): |
| """Run all tests.""" |
| print("π― Gift Card Template Implementation Test\n") |
| |
| |
| print("1. Testing module imports...") |
| import_success = test_models_import() |
| print() |
| |
| |
| print("2. Testing schema validation...") |
| schema_success = test_gift_card_schemas() |
| print() |
| |
| |
| print("π Test Summary:") |
| print(f" Module imports: {'β PASS' if import_success else 'β FAIL'}") |
| print(f" Schema validation: {'β PASS' if schema_success else 'β FAIL'}") |
| |
| if import_success and schema_success: |
| print("\nπ All tests passed! Gift Card Template implementation is working correctly.") |
| print("\nπ Available endpoints:") |
| print(" POST /api/v1/giftcard/ - Create gift card template") |
| print(" GET /api/v1/giftcard/ - List gift card templates") |
| print(" GET /api/v1/giftcard/{id} - Get specific template") |
| print(" PUT /api/v1/giftcard/{id} - Update template") |
| print(" DELETE /api/v1/giftcard/{id} - Delete template") |
| print(" GET /api/v1/giftcard/{id}/stock - Check stock availability") |
| print(" GET /api/v1/giftcard/active/list - Get active templates") |
| return True |
| else: |
| print("\nβ Some tests failed. Please check the implementation.") |
| return False |
|
|
| if __name__ == "__main__": |
| main() |