tests: simplifying test_data_field_options
Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>
This commit is contained in:
parent
9393c05b13
commit
b5a9250574
1 changed files with 23 additions and 22 deletions
|
|
@ -114,29 +114,30 @@ class TestDocType(unittest.TestCase):
|
|||
self.assertFalse(re.match(pattern, condition))
|
||||
|
||||
def test_data_field_options(self):
|
||||
doctype_name = "Test Data Fields"
|
||||
valid_data_field_options = frappe.model.data_field_options + ("",)
|
||||
invalid_data_field_options = ("Invalid Option 1", "Invalid Option 2", frappe.utils.random_string(5))
|
||||
invalid_data_field_options = ("Invalid Option 1", frappe.utils.random_string(5))
|
||||
|
||||
for options_set in [valid_data_field_options, invalid_data_field_options]:
|
||||
for field in options_set:
|
||||
test_doctype = frappe.get_doc({
|
||||
"doctype": "DocType",
|
||||
"name": "Test Data Fields",
|
||||
"module": "Core",
|
||||
"custom": 1,
|
||||
"fields": [{
|
||||
"fieldname": "{0}_field".format(field),
|
||||
"fieldtype": "Data",
|
||||
"options": field
|
||||
}]
|
||||
})
|
||||
if options_set == invalid_data_field_options:
|
||||
# assert that only data options in frappe.model.data_field_options are valid
|
||||
self.assertRaises(frappe.ValidationError, test_doctype.insert)
|
||||
else:
|
||||
test_doctype.insert()
|
||||
self.assertEqual(test_doctype.name, doctype_name)
|
||||
test_doctype.delete()
|
||||
for field_option in (valid_data_field_options + invalid_data_field_options):
|
||||
test_doctype = frappe.get_doc({
|
||||
"doctype": "DocType",
|
||||
"name": doctype_name,
|
||||
"module": "Core",
|
||||
"custom": 1,
|
||||
"fields": [{
|
||||
"fieldname": "{0}_field".format(field_option),
|
||||
"fieldtype": "Data",
|
||||
"options": field_option
|
||||
}]
|
||||
})
|
||||
|
||||
if field_option in invalid_data_field_options:
|
||||
# assert that only data options in frappe.model.data_field_options are valid
|
||||
self.assertRaises(frappe.ValidationError, test_doctype.insert)
|
||||
else:
|
||||
test_doctype.insert()
|
||||
self.assertEqual(test_doctype.name, doctype_name)
|
||||
test_doctype.delete()
|
||||
|
||||
def test_sync_field_order(self):
|
||||
from frappe.modules.import_file import get_file_path
|
||||
|
|
@ -374,4 +375,4 @@ class TestDocType(unittest.TestCase):
|
|||
# delete doctype
|
||||
link_doc.delete()
|
||||
doc.delete()
|
||||
frappe.db.commit()
|
||||
frappe.db.commit()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue