Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add test for exporting reportview as CSV
- Loading branch information
1 parent
628ed7a
commit 4eb31e0
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors | ||
# License: MIT. See LICENSE | ||
|
||
import frappe | ||
from frappe.desk.reportview import export_query | ||
from frappe.tests.utils import FrappeTestCase | ||
|
||
|
||
class TestReportview(FrappeTestCase): | ||
def test_csv(self): | ||
from csv import QUOTE_ALL, QUOTE_MINIMAL, QUOTE_NONE, QUOTE_NONNUMERIC, DictReader | ||
from io import StringIO | ||
|
||
frappe.local.form_dict = frappe._dict( | ||
doctype="DocType", | ||
title="Test Report", | ||
file_format_type="CSV", | ||
) | ||
|
||
for delimiter in (",", ";", "\t", "|"): | ||
for quoting in (QUOTE_ALL, QUOTE_MINIMAL, QUOTE_NONE, QUOTE_NONNUMERIC): | ||
frappe.local.form_dict.update( | ||
{ | ||
"csv_quoting": quoting, | ||
"csv_delimiter": delimiter, | ||
} | ||
) | ||
export_query() | ||
|
||
self.assertTrue(frappe.response["filename"].endswith(".csv")) | ||
self.assertEqual(frappe.response["type"], "binary") | ||
with StringIO(frappe.response["filecontent"].decode("utf-8")) as result: | ||
reader = DictReader(result, delimiter=delimiter, quoting=quoting) | ||
reader.__next__() |