From f7f3269c682ce5761107beeb148eef271c532287 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sun, 4 May 2025 08:00:02 +0530 Subject: [PATCH] refactor(test): "Lead" test suite working locally --- erpnext/crm/doctype/lead/test_lead.py | 61 ++++++++++++++++++++-- erpnext/crm/doctype/lead/test_records.json | 34 ------------ 2 files changed, 57 insertions(+), 38 deletions(-) delete mode 100644 erpnext/crm/doctype/lead/test_records.json diff --git a/erpnext/crm/doctype/lead/test_lead.py b/erpnext/crm/doctype/lead/test_lead.py index 7c7b4320b6a..2431d3478ef 100644 --- a/erpnext/crm/doctype/lead/test_lead.py +++ b/erpnext/crm/doctype/lead/test_lead.py @@ -11,14 +11,67 @@ from erpnext.crm.utils import get_linked_prospect class TestLead(IntegrationTestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.make_leads() + + @classmethod + def make_leads(cls): + records = [ + { + "doctype": "Lead", + "email_id": "test_lead@example.com", + "lead_name": "_Test Lead", + "status": "Open", + "territory": "_Test Territory", + "naming_series": "_T-Lead-", + }, + { + "doctype": "Lead", + "email_id": "test_lead1@example.com", + "lead_name": "_Test Lead 1", + "status": "Open", + "naming_series": "_T-Lead-", + }, + { + "doctype": "Lead", + "email_id": "test_lead2@example.com", + "lead_name": "_Test Lead 2", + "status": "Lead", + "naming_series": "_T-Lead-", + }, + { + "doctype": "Lead", + "email_id": "test_lead3@example.com", + "lead_name": "_Test Lead 3", + "status": "Converted", + "naming_series": "_T-Lead-", + }, + { + "doctype": "Lead", + "email_id": "test_lead4@example.com", + "lead_name": "_Test Lead 4", + "company_name": "_Test Lead 4", + "status": "Open", + "naming_series": "_T-Lead-", + }, + ] + cls.leads = [] + for x in records: + if not frappe.db.exists("Lead", {"email_id": x.get("email_id")}): + cls.leads.append(frappe.get_doc(x).insert()) + else: + cls.leads.append(frappe.get_doc("Lead", {"email_id": x.get("email_id")})) + def test_make_customer(self): from erpnext.crm.doctype.lead.lead import make_customer frappe.delete_doc_if_exists("Customer", "_Test Lead") - customer = make_customer("_T-Lead-00001") + customer = make_customer(self.leads[0].name) self.assertEqual(customer.doctype, "Customer") - self.assertEqual(customer.lead_name, "_T-Lead-00001") + self.assertEqual(customer.lead_name, self.leads[0].name) customer.company = "_Test Company" customer.customer_group = "_Test Customer Group" @@ -42,9 +95,9 @@ class TestLead(IntegrationTestCase): def test_make_customer_from_organization(self): from erpnext.crm.doctype.lead.lead import make_customer - customer = make_customer("_T-Lead-00002") + customer = make_customer(self.leads[1].name) self.assertEqual(customer.doctype, "Customer") - self.assertEqual(customer.lead_name, "_T-Lead-00002") + self.assertEqual(customer.lead_name, self.leads[1].name) customer.company = "_Test Company" customer.customer_group = "_Test Customer Group" diff --git a/erpnext/crm/doctype/lead/test_records.json b/erpnext/crm/doctype/lead/test_records.json deleted file mode 100644 index 3158add0f23..00000000000 --- a/erpnext/crm/doctype/lead/test_records.json +++ /dev/null @@ -1,34 +0,0 @@ -[ - { - "doctype": "Lead", - "email_id": "test_lead@example.com", - "lead_name": "_Test Lead", - "status": "Open", - "territory": "_Test Territory" - }, - { - "doctype": "Lead", - "email_id": "test_lead1@example.com", - "lead_name": "_Test Lead 1", - "status": "Open" - }, - { - "doctype": "Lead", - "email_id": "test_lead2@example.com", - "lead_name": "_Test Lead 2", - "status": "Lead" - }, - { - "doctype": "Lead", - "email_id": "test_lead3@example.com", - "lead_name": "_Test Lead 3", - "status": "Converted" -}, -{ - "doctype": "Lead", - "email_id": "test_lead4@example.com", - "lead_name": "_Test Lead 4", - "company_name": "_Test Lead 4", - "status": "Open" -} -]