refactor(test): make accounts/test/test_utils.py deterministic

This commit is contained in:
ruthra kumar
2026-02-02 18:38:41 +05:30
parent 40bb5c6ed0
commit a1aff71ca5
2 changed files with 70 additions and 47 deletions

View File

@@ -19,11 +19,6 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestUtils(ERPNextTestSuite):
@classmethod
def setUpClass(cls):
super().setUpClass()
make_test_objects("Address", ADDRESS_RECORDS)
def test_get_party_shipping_address(self):
address = get_party_shipping_address("Customer", "_Test Customer 1")
self.assertEqual(address, "_Test Billing Address 2 Title-Billing")
@@ -158,45 +153,3 @@ class TestUtils(ERPNextTestSuite):
self.assertEqual(get_zero_cutoff(None), 0.005)
self.assertEqual(get_zero_cutoff("EUR"), 0.005)
self.assertEqual(get_zero_cutoff("BHD"), 0.0005)
ADDRESS_RECORDS = [
{
"doctype": "Address",
"address_type": "Billing",
"address_line1": "Address line 1",
"address_title": "_Test Billing Address Title",
"city": "Lagos",
"country": "Nigeria",
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}],
},
{
"doctype": "Address",
"address_type": "Shipping",
"address_line1": "Address line 2",
"address_title": "_Test Shipping Address 1 Title",
"city": "Lagos",
"country": "Nigeria",
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}],
},
{
"doctype": "Address",
"address_type": "Shipping",
"address_line1": "Address line 3",
"address_title": "_Test Shipping Address 2 Title",
"city": "Lagos",
"country": "Nigeria",
"is_shipping_address": "1",
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}],
},
{
"doctype": "Address",
"address_type": "Billing",
"address_line1": "Address line 4",
"address_title": "_Test Billing Address 2 Title",
"city": "Lagos",
"country": "Nigeria",
"is_shipping_address": "1",
"links": [{"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"}],
},
]

View File

@@ -257,6 +257,7 @@ class ERPNextTestSuite(unittest.TestCase):
cls.make_leads()
cls.make_sales_person()
cls.make_activity_type()
cls.make_address()
cls.update_selling_settings()
cls.update_stock_settings()
cls.update_system_settings()
@@ -3343,6 +3344,75 @@ class ERPNextTestSuite(unittest.TestCase):
}
).insert(ignore_permissions=True)
@classmethod
def make_address(cls):
records = [
{
"doctype": "Address",
"address_type": "Billing",
"address_line1": "Address line 1",
"address_title": "_Test Billing Address Title",
"city": "Lagos",
"country": "Nigeria",
"links": [
{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
],
},
{
"doctype": "Address",
"address_type": "Shipping",
"address_line1": "Address line 2",
"address_title": "_Test Shipping Address 1 Title",
"city": "Lagos",
"country": "Nigeria",
"links": [
{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
],
},
{
"doctype": "Address",
"address_type": "Shipping",
"address_line1": "Address line 3",
"address_title": "_Test Shipping Address 2 Title",
"city": "Lagos",
"country": "Nigeria",
"is_shipping_address": "1",
"links": [
{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}
],
},
{
"doctype": "Address",
"address_type": "Billing",
"address_line1": "Address line 4",
"address_title": "_Test Billing Address 2 Title",
"city": "Lagos",
"country": "Nigeria",
"is_shipping_address": "1",
"links": [
{"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"}
],
},
]
cls.address = []
for x in records:
if not frappe.db.exists(
"Address",
{
"address_title": x.get("address_title"),
},
):
cls.address.append(frappe.get_doc(x).insert())
else:
cls.address.append(
frappe.get_doc(
"Address",
{
"address_title": x.get("address_title"),
},
)
)
@contextmanager
def set_user(self, user: str):
try: