test: reset session user if test errors in test_sle (#25042)

This commit is contained in:
Walstan Baptista 2021-03-27 18:30:07 +05:30 committed by GitHub
parent 868c0bf45b
commit d6c7d8e631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -312,29 +312,31 @@ class TestStockLedgerEntry(unittest.TestCase):
"role_allowed_to_create_edit_back_dated_transactions", "Stock Manager")
# Set User with Stock User role but not Stock Manager
frappe.set_user("test@example.com")
user = frappe.get_doc("User", "test@example.com")
user.add_roles("Stock User")
user.remove_roles("Stock Manager")
try:
frappe.set_user("test@example.com")
user = frappe.get_doc("User", "test@example.com")
user.add_roles("Stock User")
user.remove_roles("Stock Manager")
stock_entry_on_today = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100)
back_dated_se_1 = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100,
posting_date=add_days(today(), -1), do_not_submit=True)
stock_entry_on_today = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100)
back_dated_se_1 = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100,
posting_date=add_days(today(), -1), do_not_submit=True)
# Block back-dated entry
self.assertRaises(BackDatedStockTransaction, back_dated_se_1.submit)
# Block back-dated entry
self.assertRaises(BackDatedStockTransaction, back_dated_se_1.submit)
user.add_roles("Stock Manager")
user.add_roles("Stock Manager")
# Back dated entry allowed to Stock Manager
back_dated_se_2 = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100,
posting_date=add_days(today(), -1))
# Back dated entry allowed to Stock Manager
back_dated_se_2 = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100,
posting_date=add_days(today(), -1))
back_dated_se_2.cancel()
stock_entry_on_today.cancel()
back_dated_se_2.cancel()
stock_entry_on_today.cancel()
frappe.db.set_value("Stock Settings", None, "role_allowed_to_create_edit_back_dated_transactions", None)
frappe.set_user("Administrator")
finally:
frappe.db.set_value("Stock Settings", None, "role_allowed_to_create_edit_back_dated_transactions", None)
frappe.set_user("Administrator")
def create_repack_entry(**args):