From 7e51f51f11c85101bdc3392fee2df980bb3f736c Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 14 Apr 2022 09:58:35 +0530 Subject: [PATCH] test: Added test for PrintFormat.export_doc Other Changes * Added return value for export_doc method --- .../doctype/print_format/print_format.py | 2 +- .../doctype/print_format/test_print_format.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/frappe/printing/doctype/print_format/print_format.py b/frappe/printing/doctype/print_format/print_format.py index e54f46b487..e1e043beae 100644 --- a/frappe/printing/doctype/print_format/print_format.py +++ b/frappe/printing/doctype/print_format/print_format.py @@ -96,7 +96,7 @@ class PrintFormat(Document): def export_doc(self): from frappe.modules.utils import export_module_json - export_module_json(self, self.standard == "Yes", self.module) + return export_module_json(self, self.standard == "Yes", self.module) def on_trash(self): if self.doc_type: diff --git a/frappe/printing/doctype/print_format/test_print_format.py b/frappe/printing/doctype/print_format/test_print_format.py index fbfeecb3ab..e97b07ed6e 100644 --- a/frappe/printing/doctype/print_format/test_print_format.py +++ b/frappe/printing/doctype/print_format/test_print_format.py @@ -1,10 +1,15 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: MIT. See LICENSE +import os import re import unittest +from typing import TYPE_CHECKING import frappe +if TYPE_CHECKING: + from frappe.printing.doctype.print_format.print_format import PrintFormat + test_records = frappe.get_test_records("Print Format") @@ -30,3 +35,20 @@ class TestPrintFormat(unittest.TestCase): def test_print_user_classic(self): print_html = self.test_print_user("Classic") self.assertTrue("/* classic format: for-test */" in print_html) + + def test_export_doc(self): + doc: "PrintFormat" = frappe.get_doc("Print Format", test_records[0]["name"]) + doc.standard = "Yes" # this is only to make export_doc happy + export_path = doc.export_doc() + exported_doc_path = f"{export_path}.json" + doc.reload() + doc_dict = doc.as_dict(no_nulls=True, convert_dates_to_str=True) + + self.assertTrue(os.path.exists(exported_doc_path)) + + with open(exported_doc_path, "r") as f: + exported_doc = frappe.parse_json(f.read()) + + for key, value in exported_doc.items(): + if key in doc_dict: + self.assertEqual(value, doc_dict[key])