瀏覽代碼

Merge pull request #15561 from ruthra-kumar/data_exporter_bug

fix: data exporter throwing exception
version-14
mergify[bot] 3 年之前
committed by GitHub
父節點
當前提交
1313d66fae
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 2 個檔案被更改,包括 106 行新增1 行删除
  1. +1
    -1
      frappe/core/doctype/data_export/exporter.py
  2. +105
    -0
      frappe/core/doctype/data_export/test_data_exporter.py

+ 1
- 1
frappe/core/doctype/data_export/exporter.py 查看文件

@@ -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
- 0
frappe/core/doctype/data_export/test_data_exporter.py 查看文件

@@ -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…
取消
儲存