Skip to content

Commit

Permalink
test: add timeout to all BOM related tests (backport #34446) (#34453)
Browse files Browse the repository at this point in the history
test: add timeout to all BOM related tests (#34446)

* Revert "chore: remove failing test (#34444)"

This reverts commit b89ecd4.

* test: add timeout to bom tests

(cherry picked from commit f95ad03)

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Mar 15, 2023
1 parent ba2fd71 commit 68f9863
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
29 changes: 28 additions & 1 deletion erpnext/manufacturing/doctype/bom/test_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import partial

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.tests.utils import FrappeTestCase, timeout
from frappe.utils import cstr, flt

from erpnext.controllers.tests.test_subcontracting_controller import (
Expand All @@ -27,6 +27,7 @@


class TestBOM(FrappeTestCase):
@timeout
def test_get_items(self):
from erpnext.manufacturing.doctype.bom.bom import get_bom_items_as_dict

Expand All @@ -37,6 +38,7 @@ def test_get_items(self):
self.assertTrue(test_records[2]["items"][1]["item_code"] in items_dict)
self.assertEqual(len(items_dict.values()), 2)

@timeout
def test_get_items_exploded(self):
from erpnext.manufacturing.doctype.bom.bom import get_bom_items_as_dict

Expand All @@ -49,11 +51,13 @@ def test_get_items_exploded(self):
self.assertTrue(test_records[0]["items"][1]["item_code"] in items_dict)
self.assertEqual(len(items_dict.values()), 3)

@timeout
def test_get_items_list(self):
from erpnext.manufacturing.doctype.bom.bom import get_bom_items

self.assertEqual(len(get_bom_items(bom=get_default_bom(), company="_Test Company")), 3)

@timeout
def test_default_bom(self):
def _get_default_bom_in_item():
return cstr(frappe.db.get_value("Item", "_Test FG Item 2", "default_bom"))
Expand All @@ -71,6 +75,7 @@ def _get_default_bom_in_item():

self.assertTrue(_get_default_bom_in_item(), bom.name)

@timeout
def test_update_bom_cost_in_all_boms(self):
# get current rate for '_Test Item 2'
bom_rates = frappe.db.get_values(
Expand Down Expand Up @@ -99,6 +104,7 @@ def test_update_bom_cost_in_all_boms(self):
):
self.assertEqual(d.base_rate, rm_base_rate + 10)

@timeout
def test_bom_cost(self):
bom = frappe.copy_doc(test_records[2])
bom.insert()
Expand Down Expand Up @@ -127,6 +133,7 @@ def test_bom_cost(self):
self.assertAlmostEqual(bom.base_raw_material_cost, base_raw_material_cost)
self.assertAlmostEqual(bom.base_total_cost, base_raw_material_cost + base_op_cost)

@timeout
def test_bom_cost_with_batch_size(self):
bom = frappe.copy_doc(test_records[2])
bom.docstatus = 0
Expand All @@ -145,6 +152,7 @@ def test_bom_cost_with_batch_size(self):
self.assertAlmostEqual(bom.operating_cost, op_cost / 2)
bom.delete()

@timeout
def test_bom_cost_multi_uom_multi_currency_based_on_price_list(self):
frappe.db.set_value("Price List", "_Test Price List", "price_not_uom_dependent", 1)
for item_code, rate in (("_Test Item", 3600), ("_Test Item Home Desktop Manufactured", 3000)):
Expand Down Expand Up @@ -181,6 +189,7 @@ def test_bom_cost_multi_uom_multi_currency_based_on_price_list(self):
self.assertEqual(bom.base_raw_material_cost, 27000)
self.assertEqual(bom.base_total_cost, 33000)

@timeout
def test_bom_cost_multi_uom_based_on_valuation_rate(self):
bom = frappe.copy_doc(test_records[2])
bom.set_rate_of_sub_assembly_item_based_on_bom = 0
Expand All @@ -202,6 +211,7 @@ def test_bom_cost_multi_uom_based_on_valuation_rate(self):

self.assertEqual(bom.items[0].rate, 20)

@timeout
def test_bom_cost_with_fg_based_operating_cost(self):
bom = frappe.copy_doc(test_records[4])
bom.insert()
Expand Down Expand Up @@ -229,6 +239,7 @@ def test_bom_cost_with_fg_based_operating_cost(self):
self.assertAlmostEqual(bom.base_raw_material_cost, base_raw_material_cost)
self.assertAlmostEqual(bom.base_total_cost, base_raw_material_cost + base_op_cost)

@timeout
def test_subcontractor_sourced_item(self):
item_code = "_Test Subcontracted FG Item 1"
set_backflush_based_on("Material Transferred for Subcontract")
Expand Down Expand Up @@ -310,6 +321,7 @@ def test_subcontractor_sourced_item(self):
supplied_items = sorted([d.rm_item_code for d in sco.supplied_items])
self.assertEqual(bom_items, supplied_items)

@timeout
def test_bom_tree_representation(self):
bom_tree = {
"Assembly": {
Expand All @@ -335,6 +347,7 @@ def test_bom_tree_representation(self):
for reqd_item, created_item in zip(reqd_order, created_order):
self.assertEqual(reqd_item, created_item.item_code)

@timeout
def test_generated_variant_bom(self):
from erpnext.controllers.item_variant import create_variant

Expand Down Expand Up @@ -375,6 +388,7 @@ def test_generated_variant_bom(self):
self.assertEqual(reqd_item.qty, created_item.qty)
self.assertEqual(reqd_item.exploded_qty, created_item.exploded_qty)

@timeout
def test_bom_recursion_1st_level(self):
"""BOM should not allow BOM item again in child"""
item_code = make_item(properties={"is_stock_item": 1}).name
Expand All @@ -387,6 +401,7 @@ def test_bom_recursion_1st_level(self):
bom.items[0].bom_no = bom.name
bom.save()

@timeout
def test_bom_recursion_transitive(self):
item1 = make_item(properties={"is_stock_item": 1}).name
item2 = make_item(properties={"is_stock_item": 1}).name
Expand All @@ -408,6 +423,7 @@ def test_bom_recursion_transitive(self):
bom1.save()
bom2.save()

@timeout
def test_bom_with_process_loss_item(self):
fg_item_non_whole, fg_item_whole, bom_item = create_process_loss_bom_items()

Expand All @@ -421,6 +437,7 @@ def test_bom_with_process_loss_item(self):
# Items with whole UOMs can't be PL Items
self.assertRaises(frappe.ValidationError, bom_doc.submit)

@timeout
def test_bom_item_query(self):
query = partial(
item_query,
Expand All @@ -440,6 +457,7 @@ def test_bom_item_query(self):
)
self.assertTrue(0 < len(filtered) <= 3, msg="Item filtering showing excessive results")

@timeout
def test_exclude_exploded_items_from_bom(self):
bom_no = get_default_bom()
new_bom = frappe.copy_doc(frappe.get_doc("BOM", bom_no))
Expand All @@ -458,6 +476,7 @@ def test_exclude_exploded_items_from_bom(self):

new_bom.delete()

@timeout
def test_valid_transfer_defaults(self):
bom_with_op = frappe.db.get_value(
"BOM", {"item": "_Test FG Item 2", "with_operations": 1, "is_active": 1}
Expand Down Expand Up @@ -489,11 +508,13 @@ def test_valid_transfer_defaults(self):
self.assertEqual(bom.transfer_material_against, "Work Order")
bom.delete()

@timeout
def test_bom_name_length(self):
"""test >140 char names"""
bom_tree = {"x" * 140: {" ".join(["abc"] * 35): {}}}
create_nested_bom(bom_tree, prefix="")

@timeout
def test_version_index(self):

bom = frappe.new_doc("BOM")
Expand All @@ -515,6 +536,7 @@ def test_version_index(self):
msg=f"Incorrect index for {existing_boms}",
)

@timeout
def test_bom_versioning(self):
bom_tree = {frappe.generate_hash(length=10): {frappe.generate_hash(length=10): {}}}
bom = create_nested_bom(bom_tree, prefix="")
Expand Down Expand Up @@ -547,6 +569,7 @@ def test_bom_versioning(self):
self.assertNotEqual(amendment.name, version.name)
self.assertEqual(int(version.name.split("-")[-1]), 2)

@timeout
def test_clear_inpection_quality(self):

bom = frappe.copy_doc(test_records[2], ignore_no_copy=True)
Expand All @@ -565,6 +588,7 @@ def test_clear_inpection_quality(self):

self.assertEqual(bom.quality_inspection_template, None)

@timeout
def test_bom_pricing_based_on_lpp(self):
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt

Expand All @@ -585,6 +609,7 @@ def test_bom_pricing_based_on_lpp(self):
bom.submit()
self.assertEqual(bom.items[0].rate, 42)

@timeout
def test_set_default_bom_for_item_having_single_bom(self):
from erpnext.stock.doctype.item.test_item import make_item

Expand Down Expand Up @@ -621,6 +646,7 @@ def test_set_default_bom_for_item_having_single_bom(self):
bom.reload()
self.assertEqual(frappe.get_value("Item", fg_item.item_code, "default_bom"), bom.name)

@timeout
def test_exploded_items_rate(self):
rm_item = make_item(
properties={"is_stock_item": 1, "valuation_rate": 99, "last_purchase_rate": 89}
Expand Down Expand Up @@ -649,6 +675,7 @@ def test_exploded_items_rate(self):
bom.submit()
self.assertEqual(bom.exploded_items[0].rate, bom.items[0].base_rate)

@timeout
def test_bom_cost_update_flag(self):
rm_item = make_item(
properties={"is_stock_item": 1, "valuation_rate": 99, "last_purchase_rate": 89}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License: GNU General Public License v3. See license.txt

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.tests.utils import FrappeTestCase, timeout

from erpnext.manufacturing.doctype.bom_update_log.test_bom_update_log import (
update_cost_in_all_boms_in_test,
Expand All @@ -20,6 +20,7 @@ class TestBOMUpdateTool(FrappeTestCase):
def tearDown(self):
frappe.db.rollback()

@timeout
def test_replace_bom(self):
current_bom = "BOM-_Test Item Home Desktop Manufactured-001"

Expand All @@ -33,6 +34,7 @@ def test_replace_bom(self):
self.assertFalse(frappe.db.exists("BOM Item", {"bom_no": current_bom, "docstatus": 1}))
self.assertTrue(frappe.db.exists("BOM Item", {"bom_no": bom_doc.name, "docstatus": 1}))

@timeout
def test_bom_cost(self):
for item in ["BOM Cost Test Item 1", "BOM Cost Test Item 2", "BOM Cost Test Item 3"]:
item_doc = create_item(item, valuation_rate=100)
Expand Down

0 comments on commit 68f9863

Please sign in to comment.