refactor(test): make manufacturing test idempotent
(cherry picked from commit f3be246df3)
This commit is contained in:
@@ -4,19 +4,28 @@ import frappe
|
|||||||
|
|
||||||
from erpnext.tests.utils import ReportFilters, ReportName, execute_script_report
|
from erpnext.tests.utils import ReportFilters, ReportName, execute_script_report
|
||||||
|
|
||||||
DEFAULT_FILTERS = {
|
|
||||||
|
class TestManufacturingReports(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.setup_default_filters()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
|
def setup_default_filters(self):
|
||||||
|
self.last_bom = frappe.get_last_doc("BOM").name
|
||||||
|
self.DEFAULT_FILTERS = {
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
"from_date": "2010-01-01",
|
"from_date": "2010-01-01",
|
||||||
"to_date": "2030-01-01",
|
"to_date": "2030-01-01",
|
||||||
"warehouse": "_Test Warehouse - _TC",
|
"warehouse": "_Test Warehouse - _TC",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.REPORT_FILTER_TEST_CASES: list[tuple[ReportName, ReportFilters]] = [
|
||||||
REPORT_FILTER_TEST_CASES: list[tuple[ReportName, ReportFilters]] = [
|
("BOM Explorer", {"bom": self.last_bom}),
|
||||||
("BOM Explorer", {"bom": frappe.get_last_doc("BOM").name}),
|
|
||||||
("BOM Operations Time", {}),
|
("BOM Operations Time", {}),
|
||||||
("BOM Stock Calculated", {"bom": frappe.get_last_doc("BOM").name, "qty_to_make": 2}),
|
("BOM Stock Calculated", {"bom": self.last_bom, "qty_to_make": 2}),
|
||||||
("BOM Stock Report", {"bom": frappe.get_last_doc("BOM").name, "qty_to_produce": 2}),
|
("BOM Stock Report", {"bom": self.last_bom, "qty_to_produce": 2}),
|
||||||
("Cost of Poor Quality Report", {"item": "_Test Item", "serial_no": "00"}),
|
("Cost of Poor Quality Report", {"item": "_Test Item", "serial_no": "00"}),
|
||||||
("Downtime Analysis", {}),
|
("Downtime Analysis", {}),
|
||||||
(
|
(
|
||||||
@@ -35,30 +44,27 @@ REPORT_FILTER_TEST_CASES: list[tuple[ReportName, ReportFilters]] = [
|
|||||||
("Process Loss Report", {}),
|
("Process Loss Report", {}),
|
||||||
("Work Order Stock Report", {}),
|
("Work Order Stock Report", {}),
|
||||||
("Work Order Summary", {"fiscal_year": "2021-2022", "age": 0}),
|
("Work Order Summary", {"fiscal_year": "2021-2022", "age": 0}),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if frappe.db.a_row_exists("Production Plan"):
|
||||||
if frappe.db.a_row_exists("Production Plan"):
|
self.REPORT_FILTER_TEST_CASES.append(
|
||||||
REPORT_FILTER_TEST_CASES.append(
|
|
||||||
("Production Plan Summary", {"production_plan": frappe.get_last_doc("Production Plan").name})
|
("Production Plan Summary", {"production_plan": frappe.get_last_doc("Production Plan").name})
|
||||||
)
|
)
|
||||||
|
|
||||||
OPTIONAL_FILTERS = {
|
self.OPTIONAL_FILTERS = {
|
||||||
"warehouse": "_Test Warehouse - _TC",
|
"warehouse": "_Test Warehouse - _TC",
|
||||||
"item": "_Test Item",
|
"item": "_Test Item",
|
||||||
"item_group": "_Test Item Group",
|
"item_group": "_Test Item Group",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class TestManufacturingReports(unittest.TestCase):
|
|
||||||
def test_execute_all_manufacturing_reports(self):
|
def test_execute_all_manufacturing_reports(self):
|
||||||
"""Test that all script report in manufacturing modules are executable with supported filters"""
|
"""Test that all script report in manufacturing modules are executable with supported filters"""
|
||||||
for report, filter in REPORT_FILTER_TEST_CASES:
|
for report, filter in self.REPORT_FILTER_TEST_CASES:
|
||||||
with self.subTest(report=report):
|
with self.subTest(report=report):
|
||||||
execute_script_report(
|
execute_script_report(
|
||||||
report_name=report,
|
report_name=report,
|
||||||
module="Manufacturing",
|
module="Manufacturing",
|
||||||
filters=filter,
|
filters=filter,
|
||||||
default_filters=DEFAULT_FILTERS,
|
default_filters=self.DEFAULT_FILTERS,
|
||||||
optional_filters=OPTIONAL_FILTERS if filter.get("_optional") else None,
|
optional_filters=self.OPTIONAL_FILTERS if filter.get("_optional") else None,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user