Skip to content

Commit

Permalink
feat: add test for exporting reportview as CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra authored and akhilnarang committed Mar 20, 2024
1 parent 628ed7a commit 4eb31e0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions frappe/tests/test_reportview.py
@@ -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__()

0 comments on commit 4eb31e0

Please sign in to comment.