test_export_order_to_xlsx.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import os
  2. from fastapi.testclient import TestClient
  3. from app.db import export_order_to_xlsx, fetch_order_product_list
  4. from app.main import app
  5. from app.parser import read_file
  6. from app.read_settings import read_settings
  7. from app.schema import ProductShippingMeta
  8. client = TestClient(app)
  9. def test_export_order_to_xlsx(capsys):
  10. """This test does not test anything in here, but simply makes sure
  11. that the expected xlsx output file is produced and written to
  12. disk.
  13. """
  14. settings = read_settings("settings.toml")
  15. filename = "orders"
  16. orders = read_file(
  17. settings.git_repo, filename, settings.document_match, settings.block_types
  18. )
  19. order = orders.blocks[-1]
  20. product_list = fetch_order_product_list(
  21. order.order_id, settings.git_repo, settings.local_db.filepath
  22. )
  23. products_shipping_meta = []
  24. for product_info in product_list:
  25. product = read_file(settings.git_repo, f"products/{product_info.filename}", settings.document_match, settings.block_types)
  26. products_shipping_meta.append(
  27. ProductShippingMeta(
  28. weight=product.meta.weight,
  29. customs_tariff_code=product.meta.customs_tariff_code,
  30. origin_country_iso=product.meta.origin_country_iso,
  31. )
  32. )
  33. email_from = os.getenv("MAIL_FROM")
  34. export_order_to_xlsx(
  35. order,
  36. products_shipping_meta,
  37. settings.order_upload.filepath,
  38. settings.currency.default,
  39. settings.git_repo,
  40. email_from,
  41. )