chore: Rollback after each test, due to premature commit via remove_user_permission (backport #29964) (#29967)
* chore: Rollback after each test, due to premature commit via `remove_user_permission` - `remove_user_permission` in `test_warehouse_user` calls delete_doc that enqueues dynamic link deletion - Execution of background job eventually commits - While in the test suite it runs sequentially in the same thread and commits whatever was done until then - Which is why the rollback in `tearDownClass` is quite useless here - This premature commit causes many illegal transactions caught by `assertRaises` to be committed in the db - This creates faulty/dirty ledgers and breaks reports, as outiside the test suite this shouldn't/wouldn't happen - Rollback after each test, and for `test_warehouse_user` in particular, manually cancel transaction (cherry picked from commitbf8743713d) # Conflicts: # erpnext/stock/doctype/stock_entry/test_stock_entry.py * test: Make Variant if absent in `test_variant_work_order`, keep test atomic (cherry picked from commit5ff3705872) * fix: Merge conflicts Co-authored-by: marination <maricadsouza221197@gmail.com>
This commit is contained in:
@@ -45,6 +45,7 @@ def get_sle(**args):
|
||||
|
||||
class TestStockEntry(ERPNextTestCase):
|
||||
def tearDown(self):
|
||||
frappe.db.rollback()
|
||||
frappe.set_user("Administrator")
|
||||
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "0")
|
||||
|
||||
@@ -566,6 +567,7 @@ class TestStockEntry(ERPNextTestCase):
|
||||
st1.set_stock_entry_type()
|
||||
st1.insert()
|
||||
st1.submit()
|
||||
st1.cancel()
|
||||
|
||||
frappe.set_user("Administrator")
|
||||
remove_user_permission("Warehouse", "_Test Warehouse 1 - _TC", "test@example.com")
|
||||
@@ -690,6 +692,8 @@ class TestStockEntry(ERPNextTestCase):
|
||||
bom_no = frappe.db.get_value("BOM", {"item": "_Test Variant Item",
|
||||
"is_default": 1, "docstatus": 1})
|
||||
|
||||
make_item_variant() # make variant of _Test Variant Item if absent
|
||||
|
||||
work_order = frappe.new_doc("Work Order")
|
||||
work_order.update({
|
||||
"company": "_Test Company",
|
||||
@@ -1101,13 +1105,10 @@ class TestStockEntry(ERPNextTestCase):
|
||||
|
||||
# Check if FG cost is calculated based on RM total cost
|
||||
# RM total cost = 200, FG rate = 200/4(FG qty) = 50
|
||||
self.assertEqual(se.items[1].basic_rate, 50)
|
||||
self.assertEqual(se.items[1].basic_rate, flt(se.items[0].basic_rate/4))
|
||||
self.assertEqual(se.value_difference, 0.0)
|
||||
self.assertEqual(se.total_incoming_value, se.total_outgoing_value)
|
||||
|
||||
# teardown
|
||||
se.delete()
|
||||
|
||||
def make_serialized_item(**args):
|
||||
args = frappe._dict(args)
|
||||
se = frappe.copy_doc(test_records[0])
|
||||
|
||||
Reference in New Issue
Block a user