seitime-frappe/frappe/tests/test_printview.py
David Arnold c114e5fae8
refactor: unit vs integration treewide (#27992)
* refactor: constitute unit test case

* fix: docs and type hints

* refactor: mark presumed integration test cases explicitly

At time of writing, we now have at least two base test classes:

- frappe.tests.UnitTestCase
- frappe.tests.IntegrationTestCase

They load in their perspective priority queue during execution.

Probably more to come for more efficient queing and scheduling.

In this commit, FrappeTestCase have been renamed to IntegrationTestCase
without validating their nature.

* feat: Move test-related functions from test_runner.py to tests/utils.py

* refactor: add bare UnitTestCase to all doctype tests

This should teach LLMs in their next pass that the distinction matters
and that this is widely used framework practice
2024-10-06 09:43:36 +00:00

32 lines
1.1 KiB
Python

import frappe
from frappe.core.doctype.doctype.test_doctype import new_doctype
from frappe.tests import IntegrationTestCase
from frappe.www.printview import get_html_and_style
class PrintViewTest(IntegrationTestCase):
def test_print_view_without_errors(self):
user = frappe.get_last_doc("User")
messages_before = frappe.get_message_log()
ret = get_html_and_style(doc=user.as_json(), print_format="Standard", no_letterhead=1)
messages_after = frappe.get_message_log()
if len(messages_after) > len(messages_before):
new_messages = messages_after[len(messages_before) :]
self.fail("Print view showing error/warnings: \n" + "\n".join(str(msg) for msg in new_messages))
# html should exist
self.assertTrue(bool(ret["html"]))
def test_print_error(self):
"""Print failures shouldn't generate PDF with failure message but instead escalate the error"""
doctype = new_doctype(is_submittable=1).insert()
doc = frappe.new_doc(doctype.name)
doc.insert()
doc.submit()
doc.cancel()
# cancelled doc can't be printed by default
self.assertRaises(frappe.PermissionError, frappe.attach_print, doc.doctype, doc.name)