test_pdf.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import os
  2. import sys
  3. # Ensure we can import from the current directory
  4. sys.path.append(os.getcwd())
  5. import config
  6. from services.invoice_service import InvoiceService
  7. # Mock order data
  8. order_data = {
  9. 'id': 999,
  10. 'first_name': 'Test',
  11. 'last_name': 'User',
  12. 'total_price': 100.0,
  13. 'is_company': False,
  14. 'shipping_address': 'Test Address 123'
  15. }
  16. print("--- START TEST GENERATION ---")
  17. try:
  18. path = InvoiceService.generate_document(order_data, doc_type="faktura")
  19. print(f"SUCCESS! Service returned path: {path}")
  20. # Check if file exists physically
  21. abs_path = os.path.abspath(os.path.join(config.UPLOAD_DIR, "invoices", "faktura_order_999.pdf"))
  22. if os.path.exists(abs_path):
  23. print(f"CONFIRMED: File exists at {abs_path}")
  24. else:
  25. print(f"FAIL: File NOT FOUND at {abs_path}")
  26. # Let's see what IS in the upload dir
  27. print(f"Contents of {config.UPLOAD_DIR}: {os.listdir(config.UPLOAD_DIR) if os.path.exists(config.UPLOAD_DIR) else 'DIR NOT FOUND'}")
  28. except Exception as e:
  29. print(f"CRASH: {e}")
  30. import traceback
  31. traceback.print_exc()
  32. print("--- END TEST GENERATION ---")