test: Added test for PrintFormat.export_doc

Other Changes
* Added return value for export_doc method
This commit is contained in:
Gavin D'souza 2022-04-14 09:58:35 +05:30
parent 0a854ddd2a
commit 7e51f51f11
2 changed files with 23 additions and 1 deletions

View file

@ -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:

View file

@ -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])