chore: Added tests for new ux

- Test for value based inspection
- tweaks in test for formula based inspection
- tweaks in create_quality_inspection as status in child row is auto set now
This commit is contained in:
marination 2020-12-21 12:24:45 +05:30
parent 0c4f97368d
commit 68f91c9640

View File

@ -44,24 +44,61 @@ class TestQualityInspection(unittest.TestCase):
qa.delete() qa.delete()
dn.delete() dn.delete()
def test_value_based_qi_readings(self):
# Test QI based on acceptance values (Non formula)
dn = create_delivery_note(item_code="_Test Item with QA", do_not_submit=True)
readings = [{
"specification": "Iron Content", # numeric reading
"min_value": 0.1,
"max_value": 0.9,
"reading_1": "0.4"
},
{
"specification": "Particle Inspection Needed", # non-numeric reading
"non_numeric": 1,
"value": "Yes",
"reading_value": "Yes"
}]
qa = create_quality_inspection(reference_type="Delivery Note", reference_name=dn.name,
readings=readings, do_not_save=True)
qa.save()
# status must be auto set as per formula
self.assertEqual(qa.readings[0].status, "Accepted")
self.assertEqual(qa.readings[1].status, "Accepted")
qa.delete()
dn.delete()
def test_formula_based_qi_readings(self): def test_formula_based_qi_readings(self):
dn = create_delivery_note(item_code="_Test Item with QA", do_not_submit=True) dn = create_delivery_note(item_code="_Test Item with QA", do_not_submit=True)
readings = [{ readings = [{
"specification": "Iron Content", "specification": "Iron Content", # numeric reading
"formula_based_criteria": 1,
"acceptance_formula": "reading_1 > 0.35 and reading_1 < 0.50", "acceptance_formula": "reading_1 > 0.35 and reading_1 < 0.50",
"reading_1": 0.4 "reading_1": "0.4"
}, },
{ {
"specification": "Calcium Content", "specification": "Calcium Content", # numeric reading
"formula_based_criteria": 1,
"acceptance_formula": "reading_1 > 0.20 and reading_1 < 0.50", "acceptance_formula": "reading_1 > 0.20 and reading_1 < 0.50",
"reading_1": 0.7 "reading_1": "0.7"
}, },
{ {
"specification": "Mg Content", "specification": "Mg Content", # numeric reading
"acceptance_formula": "(reading_1 + reading_2 + reading_3) / 3 < 0.9", "formula_based_criteria": 1,
"reading_1": 0.5, "acceptance_formula": "mean < 0.9",
"reading_2": 0.7, "reading_1": "0.5",
"reading_2": "0.7",
"reading_3": "random text" # check if random string input causes issues "reading_3": "random text" # check if random string input causes issues
},
{
"specification": "Calcium Content", # non-numeric reading
"formula_based_criteria": 1,
"non_numeric": 1,
"acceptance_formula": "reading_value in ('Grade A', 'Grade B', 'Grade C')",
"reading_value": "Grade B"
}] }]
qa = create_quality_inspection(reference_type="Delivery Note", reference_name=dn.name, qa = create_quality_inspection(reference_type="Delivery Note", reference_name=dn.name,
@ -72,6 +109,7 @@ class TestQualityInspection(unittest.TestCase):
self.assertEqual(qa.readings[0].status, "Accepted") self.assertEqual(qa.readings[0].status, "Accepted")
self.assertEqual(qa.readings[1].status, "Rejected") self.assertEqual(qa.readings[1].status, "Rejected")
self.assertEqual(qa.readings[2].status, "Accepted") self.assertEqual(qa.readings[2].status, "Accepted")
self.assertEqual(qa.readings[3].status, "Accepted")
qa.delete() qa.delete()
dn.delete() dn.delete()
@ -86,8 +124,11 @@ def create_quality_inspection(**args):
qa.item_code = args.item_code or "_Test Item with QA" qa.item_code = args.item_code or "_Test Item with QA"
qa.sample_size = 1 qa.sample_size = 1
qa.inspected_by = frappe.session.user qa.inspected_by = frappe.session.user
qa.status = args.status or "Accepted"
readings = args.readings or {"specification": "Size", "status": args.status} readings = args.readings or {"specification": "Size", "min_value": 0, "max_value": 10}
if args.status == "Rejected":
readings["reading_1"] = "12" # status is auto set in child on save
if isinstance(readings, list): if isinstance(readings, list):
for entry in readings: for entry in readings: