* 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
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
from collections.abc import Callable
|
|
|
|
import frappe
|
|
from frappe.model import child_table_fields
|
|
from frappe.tests import IntegrationTestCase
|
|
|
|
|
|
class TestChildTable(IntegrationTestCase):
|
|
def tearDown(self) -> None:
|
|
try:
|
|
frappe.delete_doc("DocType", self.doctype_name, force=1)
|
|
except Exception:
|
|
pass
|
|
|
|
def test_child_table_doctype_creation_and_transitioning(self) -> None:
|
|
"""
|
|
This method tests the creation of child table doctype
|
|
as well as it's transitioning from child table to normal and normal to child table doctype
|
|
"""
|
|
|
|
self.doctype_name = "Test Newy Child Table"
|
|
|
|
try:
|
|
doc = frappe.get_doc(
|
|
{
|
|
"doctype": "DocType",
|
|
"name": self.doctype_name,
|
|
"istable": 1,
|
|
"custom": 1,
|
|
"module": "Integrations",
|
|
"fields": [
|
|
{"label": "Some Field", "fieldname": "some_fieldname", "fieldtype": "Data", "reqd": 1}
|
|
],
|
|
}
|
|
).insert(ignore_permissions=True)
|
|
except Exception:
|
|
self.fail("Not able to create Child Table Doctype")
|
|
|
|
for column in child_table_fields:
|
|
self.assertTrue(frappe.db.has_column(self.doctype_name, column))
|
|
|
|
# check transitioning from child table to normal doctype
|
|
doc.istable = 0
|
|
try:
|
|
doc.save(ignore_permissions=True)
|
|
except Exception:
|
|
self.fail("Not able to transition from Child Table Doctype to Normal Doctype")
|
|
|
|
self.check_valid_columns(self.assertFalse)
|
|
|
|
# check transitioning from normal to child table doctype
|
|
doc.istable = 1
|
|
try:
|
|
doc.save(ignore_permissions=True)
|
|
except Exception:
|
|
self.fail("Not able to transition from Normal Doctype to Child Table Doctype")
|
|
|
|
self.check_valid_columns(self.assertTrue)
|
|
|
|
def check_valid_columns(self, assertion_method: Callable) -> None:
|
|
valid_columns = frappe.get_meta(self.doctype_name).get_valid_columns()
|
|
for column in child_table_fields:
|
|
assertion_method(column in valid_columns)
|