diff --git a/frappe/core/doctype/doctype/test_doctype.py b/frappe/core/doctype/doctype/test_doctype.py index 17a56b5336..c766295ee2 100644 --- a/frappe/core/doctype/doctype/test_doctype.py +++ b/frappe/core/doctype/doctype/test_doctype.py @@ -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() \ No newline at end of file + frappe.db.commit()