From 7f021fb705629d70f397914f7b4866962949bfe2 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 20 Apr 2026 11:06:50 +0530 Subject: [PATCH] refactor(test): move create_test_contact_and_address to bootstrap --- .../selling/doctype/customer/test_customer.py | 4 +- .../delivery_trip/test_delivery_trip.py | 3 +- erpnext/tests/utils.py | 73 ++++++++----------- 3 files changed, 32 insertions(+), 48 deletions(-) diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py index 211343966f9..5eef7f95651 100644 --- a/erpnext/selling/doctype/customer/test_customer.py +++ b/erpnext/selling/doctype/customer/test_customer.py @@ -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 ) diff --git a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py index 783a28a47d8..83b7395f342 100644 --- a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py +++ b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py @@ -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") diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index e2a2a7ab195..0544f0e3383 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -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 = [ {