Skip to content

Commit

Permalink
tests: simplifying test_data_field_options
Browse files Browse the repository at this point in the history
Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>
  • Loading branch information
gavindsouza and surajshetty3416 committed Apr 1, 2020
1 parent 9393c05 commit b5a9250
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions frappe/core/doctype/doctype/test_doctype.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,30 @@ def test_all_depends_on_fields_conditions(self):
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))

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()
invalid_data_field_options = ("Invalid Option 1", frappe.utils.random_string(5))

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
Expand Down Expand Up @@ -374,4 +375,4 @@ def test_cancel_link_doctype(self):
# delete doctype
link_doc.delete()
doc.delete()
frappe.db.commit()
frappe.db.commit()

0 comments on commit b5a9250

Please sign in to comment.