Merge pull request #13879 from ankush/fix_child_validation

fix: validate code fields of children too
This commit is contained in:
mergify[bot] 2021-08-09 07:07:42 +00:00 committed by GitHub
commit dbcf05481f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View file

@ -109,3 +109,13 @@ class TestServerScript(unittest.TestCase):
"""Raise AttributeError if method not found in Namespace"""
note = frappe.get_doc({"doctype": "Note", "title": "Test Note: Server Script"})
self.assertRaises(AttributeError, note.insert)
def test_syntax_validation(self):
server_script = scripts[0]
server_script["script"] = "js || code.?"
with self.assertRaises(frappe.ValidationError) as se:
frappe.get_doc(doctype="Server Script", **server_script).insert()
self.assertTrue("invalid python code" in str(se.exception).lower(),
msg="Python code validation not working")

View file

@ -507,6 +507,7 @@ class Document(BaseDocument):
d._validate_selects()
d._validate_non_negative()
d._validate_length()
d._validate_code_fields()
d._extract_images_from_text_editor()
d._sanitize_content()
d._save_passwords()

View file

@ -121,6 +121,16 @@ class TestWorkflow(unittest.TestCase):
self.workflow.states[1].doc_status = 0
self.workflow.save()
def test_syntax_error_in_transition_rule(self):
self.workflow.transitions[0].condition = 'doc.status =! "Closed"'
with self.assertRaises(frappe.ValidationError) as se:
self.workflow.save()
self.assertTrue("invalid python code" in str(se.exception).lower(),
msg="Python code validation not working")
def create_todo_workflow():
if frappe.db.exists('Workflow', 'Test ToDo'):
frappe.delete_doc('Workflow', 'Test ToDo')