Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

42 rader
1.3 KiB

  1. # Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
  2. # License: MIT. See LICENSE
  3. import unittest
  4. import frappe
  5. from frappe.desk.query_report import build_xlsx_data
  6. import frappe.utils
  7. class TestQueryReport(unittest.TestCase):
  8. def test_xlsx_data_with_multiple_datatypes(self):
  9. """Test exporting report using rows with multiple datatypes (list, dict)"""
  10. # Create mock data
  11. data = frappe._dict()
  12. data.columns = [
  13. {"label": "Column A", "fieldname": "column_a", "fieldtype": "Float"},
  14. {"label": "Column B", "fieldname": "column_b", "width": 100, "fieldtype": "Float"},
  15. {"label": "Column C", "fieldname": "column_c", "width": 150, "fieldtype": "Duration"},
  16. ]
  17. data.result = [
  18. [1.0, 3.0, 600],
  19. {"column_a": 22.1, "column_b": 21.8, "column_c": 86412},
  20. {"column_b": 5.1, "column_c": 53234, "column_a": 11.1},
  21. [3.0, 1.5, 333],
  22. ]
  23. # Define the visible rows
  24. visible_idx = [0, 2, 3]
  25. # Build the result
  26. xlsx_data, column_widths = build_xlsx_data(data, visible_idx, include_indentation=0)
  27. self.assertEqual(type(xlsx_data), list)
  28. self.assertEqual(len(xlsx_data), 4) # columns + data
  29. # column widths are divided by 10 to match the scale that is supported by openpyxl
  30. self.assertListEqual(column_widths, [0, 10, 15])
  31. for row in xlsx_data:
  32. self.assertEqual(type(row), list)