Skip to content

Commit

Permalink
fix(test): Handle explicit commit in create_custom_field
Browse files Browse the repository at this point in the history
- `create_custom_field` cannot be used arbitrarily in tests since it explicitly commits to make sure schema changes are reflected
- Call it during setUpClass since 2 tests need it
- Call it first so that after the commit, the following test setup can be rolled back on class cleanup
- Rollback to the post setup state after each test so that there is no test-run data shared between tests
  • Loading branch information
marination committed Nov 26, 2024
1 parent 335fd81 commit 199d04e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/helper/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bench get-app erpnext --branch version-15
bench get-app hrms --branch version-15
bench get-app banking "${GITHUB_WORKSPACE}"

bench start &> bench_run_logs.txt &
bench start &> bench_start.log &
bench new-site --db-root-password root --admin-password admin test_site --install-app erpnext
bench --site test_site install-app hrms
bench --site test_site install-app banking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,28 @@


class TestBankReconciliationToolBeta(AccountsTestMixin, FrappeTestCase):
def setUp(self) -> None:
@classmethod
def setUpClass(cls) -> None:
super().setUpClass()

create_custom_field(
"Sales Invoice", dict(fieldname="custom_ref_no", label="Ref No", fieldtype="Data")
) # commits to db internally

create_bank()
self.gl_account = create_gl_account("_Test Bank Reco Tool")
self.bank_account = create_bank_account(gl_account=self.gl_account)
self.customer = create_customer(customer_name="ABC Inc.")
cls.gl_account = create_gl_account("_Test Bank Reco Tool")
cls.bank_account = create_bank_account(gl_account=cls.gl_account)
cls.customer = create_customer(customer_name="ABC Inc.")

self.create_item(
item_name="Reco Item", company="_Test Company", warehouse="Finished Goods - _TC"
cls.create_item(
cls, item_name="Reco Item", company="_Test Company", warehouse="Finished Goods - _TC"
)
frappe.db.savepoint(save_point="bank_reco_beta_before_tests")

def tearDown(self) -> None:
"""Runs after each test."""
# Make sure invoices are rolled back to not affect invoice count assertions
frappe.db.rollback()
frappe.db.rollback(save_point="bank_reco_beta_before_tests")

def test_unpaid_invoices_more_than_transaction(self):
"""
Expand Down Expand Up @@ -562,10 +570,6 @@ def test_multi_party_reconciliation(self):

def test_configurable_reference_field(self):
"""Test if configured reference field is considered."""
create_custom_field(
"Sales Invoice", dict(fieldname="custom_ref_no", label="Ref No", fieldtype="Data")
)

settings = frappe.get_single("Banking Settings")
settings.append(
"reference_fields", {"document_type": "Sales Invoice", "field_name": "custom_ref_no"}
Expand Down Expand Up @@ -622,9 +626,6 @@ def test_configurable_reference_field(self):

def test_no_configurable_reference_field(self):
"""Test if Name is considered as the reference field if not configured."""
create_custom_field(
"Sales Invoice", dict(fieldname="custom_ref_no", label="Ref No", fieldtype="Data")
)
bt = create_bank_transaction(
date=getdate(),
deposit=300,
Expand Down

0 comments on commit 199d04e

Please sign in to comment.