Merge pull request #15561 from ruthra-kumar/data_exporter_bug
fix: data exporter throwing exception
This commit is contained in:
commit
1313d66fae
2 changed files with 106 additions and 1 deletions
|
|
@ -314,7 +314,7 @@ class DataExporter:
|
|||
.where(child_doctype_table.parentfield == c["parentfield"])
|
||||
.orderby(child_doctype_table.idx)
|
||||
)
|
||||
for ci, child in enumerate(data_row.run()):
|
||||
for ci, child in enumerate(data_row.run(as_dict=True)):
|
||||
self.add_data_row(rows, c['doctype'], c['parentfield'], child, ci)
|
||||
|
||||
for row in rows:
|
||||
|
|
|
|||
105
frappe/core/doctype/data_export/test_data_exporter.py
Normal file
105
frappe/core/doctype/data_export/test_data_exporter.py
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2019, Frappe Technologies and Contributors
|
||||
# License: MIT. See LICENSE
|
||||
import unittest
|
||||
import frappe
|
||||
from frappe.core.doctype.data_export.exporter import DataExporter
|
||||
|
||||
class TestDataExporter(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.doctype_name = 'Test DocType for Export Tool'
|
||||
self.doc_name = 'Test Data for Export Tool'
|
||||
self.create_doctype_if_not_exists(doctype_name=self.doctype_name)
|
||||
self.create_test_data()
|
||||
|
||||
def create_doctype_if_not_exists(self, doctype_name, force=False):
|
||||
"""
|
||||
Helper Function for setting up doctypes
|
||||
"""
|
||||
if force:
|
||||
frappe.delete_doc_if_exists('DocType', doctype_name)
|
||||
frappe.delete_doc_if_exists('DocType', 'Child 1 of ' + doctype_name)
|
||||
|
||||
if frappe.db.exists('DocType', doctype_name):
|
||||
return
|
||||
|
||||
# Child Table 1
|
||||
table_1_name = 'Child 1 of ' + doctype_name
|
||||
frappe.get_doc({
|
||||
'doctype': 'DocType',
|
||||
'name': table_1_name,
|
||||
'module': 'Custom',
|
||||
'custom': 1,
|
||||
'istable': 1,
|
||||
'fields': [
|
||||
{'label': 'Child Title', 'fieldname': 'child_title', 'reqd': 1, 'fieldtype': 'Data'},
|
||||
{'label': 'Child Number', 'fieldname': 'child_number', 'fieldtype': 'Int'},
|
||||
]
|
||||
}).insert()
|
||||
|
||||
# Main Table
|
||||
frappe.get_doc({
|
||||
'doctype': 'DocType',
|
||||
'name': doctype_name,
|
||||
'module': 'Custom',
|
||||
'custom': 1,
|
||||
'autoname': 'field:title',
|
||||
'fields': [
|
||||
{'label': 'Title', 'fieldname': 'title', 'reqd': 1, 'fieldtype': 'Data'},
|
||||
{'label': 'Number', 'fieldname': 'number', 'fieldtype': 'Int'},
|
||||
{'label': 'Table Field 1', 'fieldname': 'table_field_1', 'fieldtype': 'Table', 'options': table_1_name},
|
||||
],
|
||||
'permissions': [
|
||||
{'role': 'System Manager'}
|
||||
]
|
||||
}).insert()
|
||||
|
||||
def create_test_data(self, force=False):
|
||||
"""
|
||||
Helper Function creating test data
|
||||
"""
|
||||
if force:
|
||||
frappe.delete_doc(self.doctype_name, self.doc_name)
|
||||
|
||||
if not frappe.db.exists(self.doctype_name, self.doc_name):
|
||||
self.doc = frappe.get_doc(
|
||||
doctype=self.doctype_name,
|
||||
title=self.doc_name,
|
||||
number="100",
|
||||
table_field_1=[
|
||||
{"child_title": "Child Title 1", "child_number": "50"},
|
||||
{"child_title": "Child Title 2", "child_number": "51"},
|
||||
]
|
||||
).insert()
|
||||
else:
|
||||
self.doc = frappe.get_doc(self.doctype_name, self.doc_name)
|
||||
|
||||
def test_export_content(self):
|
||||
exp = DataExporter(doctype=self.doctype_name, file_type='CSV')
|
||||
exp.build_response()
|
||||
|
||||
self.assertEqual(frappe.response['type'],'csv')
|
||||
self.assertEqual(frappe.response['doctype'], self.doctype_name)
|
||||
self.assertTrue(frappe.response['result'])
|
||||
self.assertIn('Child Title 1\",50',frappe.response['result'])
|
||||
self.assertIn('Child Title 2\",51',frappe.response['result'])
|
||||
|
||||
def test_export_type(self):
|
||||
for type in ['csv', 'Excel']:
|
||||
with self.subTest(type=type):
|
||||
exp = DataExporter(doctype=self.doctype_name, file_type=type)
|
||||
exp.build_response()
|
||||
|
||||
self.assertEqual(frappe.response['doctype'], self.doctype_name)
|
||||
self.assertTrue(frappe.response['result'])
|
||||
|
||||
if type == 'csv':
|
||||
self.assertEqual(frappe.response['type'],'csv')
|
||||
elif type == 'Excel':
|
||||
self.assertEqual(frappe.response['type'],'binary')
|
||||
self.assertEqual(frappe.response['filename'], self.doctype_name+'.xlsx') # 'Test DocType for Export Tool.xlsx')
|
||||
self.assertTrue(frappe.response['filecontent'])
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
Loading…
Add table
Reference in a new issue