test_models.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env python3
  2. """
  3. Test script to verify the models are correctly defined
  4. """
  5. # Test imports
  6. try:
  7. from models.user import User, UserModel, UserIDRequest, RegisterUserRequest
  8. print("✅ User models imported successfully")
  9. except ImportError as e:
  10. print(f"❌ Error importing user models: {e}")
  11. try:
  12. from models.items import Product, ProductWithQuantity
  13. print("✅ Product models imported successfully")
  14. except ImportError as e:
  15. print(f"❌ Error importing product models: {e}")
  16. try:
  17. from models.sells import Sale, SellItem, ItemWeb, OrderWeb
  18. print("✅ Sales models imported successfully")
  19. except ImportError as e:
  20. print(f"❌ Error importing sales models: {e}")
  21. try:
  22. from models.blacklist import Blacklist
  23. print("✅ Blacklist model imported successfully")
  24. except ImportError as e:
  25. print(f"❌ Error importing blacklist model: {e}")
  26. try:
  27. from models.chat import Message, ChatCompletionRequest
  28. print("✅ Chat models imported successfully")
  29. except ImportError as e:
  30. print(f"❌ Error importing chat models: {e}")
  31. # Test model creation
  32. try:
  33. user = User(
  34. id=1,
  35. email="test@example.com",
  36. nombre="Test User",
  37. rut="12345678-9",
  38. pin_hash="hashed_pin",
  39. kleincoins="100",
  40. created_at="2023-01-01T00:00:00"
  41. )
  42. print("✅ User model creation successful")
  43. print(f" User: {user.nombre} ({user.email})")
  44. except Exception as e:
  45. print(f"❌ Error creating user model: {e}")
  46. try:
  47. product = Product(
  48. id=1,
  49. name="Test Product",
  50. type="food",
  51. description="A test product",
  52. price=10.99,
  53. image="test.jpg",
  54. status=1
  55. )
  56. print("✅ Product model creation successful")
  57. print(f" Product: {product.name} - ${product.price}")
  58. except Exception as e:
  59. print(f"❌ Error creating product model: {e}")
  60. try:
  61. product_with_quantity = ProductWithQuantity(
  62. id=1,
  63. name="Test Product",
  64. type="food",
  65. description="A test product",
  66. price=10.99,
  67. image="test.jpg",
  68. status=1,
  69. cantidad=3
  70. )
  71. print("✅ ProductWithQuantity model creation successful")
  72. print(f" Product: {product_with_quantity.name} - Qty: {product_with_quantity.cantidad}")
  73. except Exception as e:
  74. print(f"❌ Error creating ProductWithQuantity model: {e}")
  75. try:
  76. sale = Sale(
  77. id=1,
  78. user_id=1,
  79. total=50.99,
  80. fudo_id="FUDO123",
  81. fecha="2023-01-01T12:00:00",
  82. table=5,
  83. user_name="Test User",
  84. user_email="test@example.com"
  85. )
  86. print("✅ Sale model creation successful")
  87. print(f" Sale: {sale.fudo_id} - Total: ${sale.total}")
  88. except Exception as e:
  89. print(f"❌ Error creating sale model: {e}")
  90. try:
  91. blacklist = Blacklist(
  92. id=1,
  93. user_id=1,
  94. email="blocked@example.com",
  95. nombre="Blocked User",
  96. rut="98765432-1"
  97. )
  98. print("✅ Blacklist model creation successful")
  99. print(f" Blacklisted: {blacklist.nombre} ({blacklist.email})")
  100. except Exception as e:
  101. print(f"❌ Error creating blacklist model: {e}")
  102. print("\n🎉 All model tests completed!")