Merge pull request #54406 from ruthra-kumar/remove_dead_test_code

refactor(test): move contact and address creation to bootstrap
This commit is contained in:
ruthra kumar
2026-04-20 14:16:04 +05:30
committed by GitHub
5 changed files with 36 additions and 118 deletions

View File

@@ -320,72 +320,6 @@ class TestAccount(ERPNextTestSuite):
self.assertEqual(balance, 0)
def _make_test_records(verbose=None):
from frappe.tests.utils import make_test_objects
accounts = [
# [account_name, parent_account, is_group]
["_Test Bank", "Bank Accounts", 0, "Bank", None],
["_Test Bank USD", "Bank Accounts", 0, "Bank", "USD"],
["_Test Bank EUR", "Bank Accounts", 0, "Bank", "EUR"],
["_Test Cash", "Cash In Hand", 0, "Cash", None],
["_Test Account Stock Expenses", "Direct Expenses", 1, None, None],
["_Test Account Shipping Charges", "_Test Account Stock Expenses", 0, "Chargeable", None],
["_Test Account Customs Duty", "_Test Account Stock Expenses", 0, "Tax", None],
["_Test Account Insurance Charges", "_Test Account Stock Expenses", 0, "Chargeable", None],
["_Test Account Stock Adjustment", "_Test Account Stock Expenses", 0, "Stock Adjustment", None],
["_Test Employee Advance", "Current Liabilities", 0, None, None],
["_Test Account Tax Assets", "Current Assets", 1, None, None],
["_Test Account VAT", "_Test Account Tax Assets", 0, "Tax", None],
["_Test Account Service Tax", "_Test Account Tax Assets", 0, "Tax", None],
["_Test Account Reserves and Surplus", "Current Liabilities", 0, None, None],
["_Test Account Cost for Goods Sold", "Expenses", 0, None, None],
["_Test Account Excise Duty", "_Test Account Tax Assets", 0, "Tax", None],
["_Test Account Education Cess", "_Test Account Tax Assets", 0, "Tax", None],
["_Test Account S&H Education Cess", "_Test Account Tax Assets", 0, "Tax", None],
["_Test Account CST", "Direct Expenses", 0, "Tax", None],
["_Test Account Discount", "Direct Expenses", 0, None, None],
["_Test Write Off", "Indirect Expenses", 0, None, None],
["_Test Exchange Gain/Loss", "Indirect Expenses", 0, None, None],
["_Test Account Sales", "Direct Income", 0, None, None],
# related to Account Inventory Integration
["_Test Account Stock In Hand", "Current Assets", 0, None, None],
# fixed asset depreciation
["_Test Fixed Asset", "Current Assets", 0, "Fixed Asset", None],
["_Test Accumulated Depreciations", "Current Assets", 0, "Accumulated Depreciation", None],
["_Test Depreciations", "Expenses", 0, "Depreciation", None],
["_Test Gain/Loss on Asset Disposal", "Expenses", 0, None, None],
# Receivable / Payable Account
["_Test Receivable", "Current Assets", 0, "Receivable", None],
["_Test Payable", "Current Liabilities", 0, "Payable", None],
["_Test Receivable USD", "Current Assets", 0, "Receivable", "USD"],
["_Test Payable USD", "Current Liabilities", 0, "Payable", "USD"],
]
for company, abbr in [
["_Test Company", "_TC"],
["_Test Company 1", "_TC1"],
["_Test Company with perpetual inventory", "TCP1"],
]:
test_objects = make_test_objects(
"Account",
[
{
"doctype": "Account",
"account_name": account_name,
"parent_account": parent_account + " - " + abbr,
"company": company,
"is_group": is_group,
"account_type": account_type,
"account_currency": currency,
}
for account_name, parent_account, is_group, account_type, currency in accounts
],
)
return test_objects
def get_inventory_account(company, warehouse=None):
account = None
if warehouse:

View File

@@ -772,7 +772,7 @@ class TestAccountsReceivable(ERPNextTestSuite, AccountsTestMixin):
def test_party_account_filter(self):
si1 = self.create_sales_invoice()
self.customer2 = frappe.get_doc(
jane = frappe.get_doc(
{
"doctype": "Customer",
"customer_name": "Jane Doe",
@@ -781,9 +781,9 @@ class TestAccountsReceivable(ERPNextTestSuite, AccountsTestMixin):
}
).insert()
self.customer = jane.name
si2 = self.create_sales_invoice(do_not_submit=True)
si2.posting_date = add_days(today(), -1)
si2.customer = self.customer2.name
si2.currency = "USD"
si2.conversion_rate = 80
si2.debit_to = self.debtors_usd
@@ -991,7 +991,7 @@ class TestAccountsReceivable(ERPNextTestSuite, AccountsTestMixin):
self.assertEqual(expected_data, report_output)
def test_future_payments_on_foreign_currency(self):
self.customer2 = frappe.get_doc(
jane = frappe.get_doc(
{
"doctype": "Customer",
"customer_name": "Jane Doe",
@@ -999,10 +999,10 @@ class TestAccountsReceivable(ERPNextTestSuite, AccountsTestMixin):
"default_currency": "USD",
}
).insert()
self.customer = jane.name
si = self.create_sales_invoice(do_not_submit=True)
si.posting_date = add_days(today(), -1)
si.customer = self.customer2.name
si.currency = "USD"
si.conversion_rate = 80
si.debit_to = self.debtors_usd

View File

@@ -14,7 +14,7 @@ from erpnext.selling.doctype.customer.customer import (
get_customer_outstanding,
parse_full_name,
)
from erpnext.tests.utils import ERPNextTestSuite, create_test_contact_and_address
from erpnext.tests.utils import ERPNextTestSuite
class TestCustomer(ERPNextTestSuite):
@@ -71,8 +71,6 @@ class TestCustomer(ERPNextTestSuite):
"customer_name": "_Test Customer",
}
create_test_contact_and_address()
frappe.db.set_value(
"Contact", "_Test Contact for _Test Customer-_Test Customer", "is_primary_contact", 1
)

View File

@@ -10,7 +10,7 @@ from erpnext.stock.doctype.delivery_trip.delivery_trip import (
get_contact_and_address,
notify_customers,
)
from erpnext.tests.utils import ERPNextTestSuite, create_test_contact_and_address
from erpnext.tests.utils import ERPNextTestSuite
class TestDeliveryTrip(ERPNextTestSuite):
@@ -19,7 +19,6 @@ class TestDeliveryTrip(ERPNextTestSuite):
driver = create_driver()
create_vehicle()
create_delivery_notification()
create_test_contact_and_address()
address = create_address(driver)
self.delivery_trip = create_delivery_trip(driver, address, company="_Test Company")

View File

@@ -16,49 +16,6 @@ ReportFilters = dict[str, Any]
ReportName = NewType("ReportName", str)
def create_test_contact_and_address():
frappe.db.sql("delete from tabContact")
frappe.db.sql("delete from `tabContact Email`")
frappe.db.sql("delete from `tabContact Phone`")
frappe.db.sql("delete from tabAddress")
frappe.db.sql("delete from `tabDynamic Link`")
frappe.get_doc(
{
"doctype": "Address",
"address_title": "_Test Address for Customer",
"address_type": "Office",
"address_line1": "Station Road",
"city": "_Test City",
"state": "Test State",
"country": "India",
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}],
}
).insert()
contact = frappe.get_doc(
{
"doctype": "Contact",
"first_name": "_Test Contact for _Test Customer",
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}],
}
)
contact.add_email("test_contact_customer@example.com", is_primary=True)
contact.add_phone("+91 0000000000", is_primary_phone=True)
contact.insert()
contact_two = frappe.get_doc(
{
"doctype": "Contact",
"first_name": "_Test Contact 2 for _Test Customer",
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}],
}
)
contact_two.add_email("test_contact_two_customer@example.com", is_primary=True)
contact_two.add_phone("+92 0000000000", is_primary_phone=True)
contact_two.insert()
def execute_script_report(
report_name: ReportName,
module: str,
@@ -241,6 +198,7 @@ class BootStrapTestData:
self.make_sales_person()
self.make_activity_type()
self.make_address()
self.make_contact()
self.update_support_settings()
self.update_selling_settings()
self.update_stock_settings()
@@ -2859,9 +2817,38 @@ class BootStrapTestData:
{"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"}
],
},
{
"doctype": "Address",
"address_title": "_Test Address for Customer",
"address_type": "Office",
"address_line1": "Station Road",
"city": "_Test City",
"state": "Test State",
"country": "India",
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}],
},
]
self.make_records(["address_title", "address_type"], records)
def make_contact(self):
records = [
{
"doctype": "Contact",
"first_name": "_Test Contact for _Test Customer",
"email_ids": [{"email_id": "test_contact_customer@example.com", "is_primary": True}],
"phone_nos": [{"phone": "+91 0000000000", "is_primary_phone": True}],
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}],
},
{
"doctype": "Contact",
"first_name": "_Test Contact 2 for _Test Customer",
"email_ids": [{"email_id": "test_contact_two_customer@example.com", "is_primary": True}],
"phone_nos": [{"phone": "+92 0000000000", "is_primary_phone": True}],
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}],
},
]
self.make_records(["first_name"], records)
def make_dimensions(self):
records = [
{