-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: link between parent and child procedure (cherry picked from commit 05f24ed) * chore: add missing filters for `Parent Procedure` (cherry picked from commit 8fbd4ce) * test: add test case for Quality Procedure` (cherry picked from commit 30c6b83) --------- Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
- Loading branch information
1 parent
e156564
commit a065f22
Showing
3 changed files
with
138 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 88 additions & 37 deletions
125
erpnext/quality_management/doctype/quality_procedure/test_quality_procedure.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,107 @@ | ||
# Copyright (c) 2018, Frappe and Contributors | ||
# See license.txt | ||
|
||
import unittest | ||
|
||
import frappe | ||
from frappe.tests.utils import FrappeTestCase | ||
|
||
from .quality_procedure import add_node | ||
|
||
|
||
class TestQualityProcedure(unittest.TestCase): | ||
class TestQualityProcedure(FrappeTestCase): | ||
def test_add_node(self): | ||
try: | ||
procedure = frappe.get_doc( | ||
dict( | ||
doctype="Quality Procedure", | ||
quality_procedure_name="Test Procedure 1", | ||
processes=[dict(process_description="Test Step 1")], | ||
) | ||
).insert() | ||
procedure = create_procedure( | ||
{ | ||
"quality_procedure_name": "Test Procedure 1", | ||
"is_group": 1, | ||
"processes": [dict(process_description="Test Step 1")], | ||
} | ||
) | ||
|
||
frappe.local.form_dict = frappe._dict( | ||
doctype="Quality Procedure", | ||
quality_procedure_name="Test Child 1", | ||
parent_quality_procedure=procedure.name, | ||
cmd="test", | ||
is_root="false", | ||
) | ||
node = add_node() | ||
|
||
frappe.local.form_dict = frappe._dict( | ||
doctype="Quality Procedure", | ||
quality_procedure_name="Test Child 1", | ||
parent_quality_procedure=procedure.name, | ||
cmd="test", | ||
is_root="false", | ||
) | ||
node = add_node() | ||
procedure.reload() | ||
|
||
procedure.reload() | ||
self.assertEqual(procedure.is_group, 1) | ||
|
||
self.assertEqual(procedure.is_group, 1) | ||
# child row created | ||
self.assertTrue([d for d in procedure.processes if d.procedure == node.name]) | ||
|
||
# child row created | ||
self.assertTrue([d for d in procedure.processes if d.procedure == node.name]) | ||
node.delete() | ||
procedure.reload() | ||
|
||
node.delete() | ||
procedure.reload() | ||
# child unset | ||
self.assertFalse([d for d in procedure.processes if d.name == node.name]) | ||
|
||
# child unset | ||
self.assertFalse([d for d in procedure.processes if d.name == node.name]) | ||
def test_remove_parent_from_old_child(self): | ||
child_qp = create_procedure( | ||
{ | ||
"quality_procedure_name": "Test Child 1", | ||
"is_group": 0, | ||
} | ||
) | ||
group_qp = create_procedure( | ||
{ | ||
"quality_procedure_name": "Test Group", | ||
"is_group": 1, | ||
"processes": [dict(procedure=child_qp.name)], | ||
} | ||
) | ||
|
||
finally: | ||
procedure.delete() | ||
child_qp.reload() | ||
self.assertEqual(child_qp.parent_quality_procedure, group_qp.name) | ||
|
||
group_qp.reload() | ||
del group_qp.processes[0] | ||
group_qp.save() | ||
|
||
def create_procedure(): | ||
return frappe.get_doc( | ||
dict( | ||
doctype="Quality Procedure", | ||
quality_procedure_name="Test Procedure 1", | ||
is_group=1, | ||
processes=[dict(process_description="Test Step 1")], | ||
child_qp.reload() | ||
self.assertEqual(child_qp.parent_quality_procedure, None) | ||
|
||
def remove_child_from_old_parent(self): | ||
child_qp = create_procedure( | ||
{ | ||
"quality_procedure_name": "Test Child 1", | ||
"is_group": 0, | ||
} | ||
) | ||
group_qp = create_procedure( | ||
{ | ||
"quality_procedure_name": "Test Group", | ||
"is_group": 1, | ||
"processes": [dict(procedure=child_qp.name)], | ||
} | ||
) | ||
).insert() | ||
|
||
group_qp.reload() | ||
self.assertTrue([d for d in group_qp.processes if d.procedure == child_qp.name]) | ||
|
||
child_qp.reload() | ||
self.assertEqual(child_qp.parent_quality_procedure, group_qp.name) | ||
|
||
child_qp.parent_quality_procedure = None | ||
child_qp.save() | ||
|
||
group_qp.reload() | ||
self.assertFalse([d for d in group_qp.processes if d.procedure == child_qp.name]) | ||
|
||
|
||
def create_procedure(kwargs=None): | ||
kwargs = frappe._dict(kwargs or {}) | ||
|
||
doc = frappe.new_doc("Quality Procedure") | ||
doc.quality_procedure_name = kwargs.quality_procedure_name or "_Test Procedure" | ||
doc.is_group = kwargs.is_group or 0 | ||
|
||
for process in kwargs.processes or []: | ||
doc.append("processes", process) | ||
|
||
doc.insert() | ||
|
||
return doc |