* 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
62 lines
2 KiB
Python
62 lines
2 KiB
Python
import frappe
|
|
from frappe.core.doctype.doctype.test_doctype import new_doctype
|
|
from frappe.database.schema import DBTable
|
|
from frappe.tests import IntegrationTestCase
|
|
|
|
|
|
class TestNonNullableDocfield(IntegrationTestCase):
|
|
def setUp(self):
|
|
doc = new_doctype(
|
|
fields=[
|
|
{
|
|
"fieldname": "test_field",
|
|
"fieldtype": "Data",
|
|
"label": "test_field",
|
|
"not_nullable": 1,
|
|
},
|
|
],
|
|
)
|
|
doc.insert()
|
|
self.doctype_name = doc.name
|
|
|
|
nullable_doc = new_doctype(
|
|
fields=[
|
|
{
|
|
"fieldname": "test_field",
|
|
"fieldtype": "Data",
|
|
"label": "test_field",
|
|
}
|
|
]
|
|
)
|
|
nullable_doc.insert()
|
|
self.nullable_doctype_name = nullable_doc.name
|
|
|
|
def test_non_nullable_field(self):
|
|
doc = frappe.new_doc(doctype=self.doctype_name)
|
|
doc.insert()
|
|
inserted_doc = frappe.db.get(self.doctype_name, {"name": doc.name})
|
|
self.assertEqual(inserted_doc.test_field, "")
|
|
|
|
def test_edit_field_nullable_status(self):
|
|
doc = frappe.new_doc(doctype=self.nullable_doctype_name)
|
|
doc.insert()
|
|
inserted_doc = frappe.db.get(self.nullable_doctype_name, {"name": doc.name})
|
|
self.assertEqual(inserted_doc.test_field, None)
|
|
table = DBTable(self.nullable_doctype_name)
|
|
query = "SELECT column_name AS name, column_default is NULL AS default_null,is_nullable = 'NO' AS not_nullable FROM information_schema.columns WHERE table_name=%s"
|
|
for column in frappe.db.sql(query, table.table_name, as_dict=True):
|
|
if column.name == "test_field":
|
|
self.assertFalse(column.not_nullable)
|
|
|
|
doctype_doc = frappe.get_doc("DocType", self.nullable_doctype_name)
|
|
for field in doctype_doc.fields:
|
|
if field.fieldname == "test_field":
|
|
field.not_nullable = 1
|
|
break
|
|
doctype_doc.save()
|
|
for column in frappe.db.sql(query, table.table_name, as_dict=True):
|
|
if column.name == "test_field":
|
|
self.assertFalse(column.default_null)
|
|
self.assertTrue(column.not_nullable)
|
|
inserted_doc = frappe.db.get(self.nullable_doctype_name, {"name": doc.name})
|
|
self.assertEqual(inserted_doc.test_field, "")
|