From a55a86f300431811fad1aa1434c8f6e3d97d4ac6 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Wed, 7 May 2025 12:12:50 +0530 Subject: [PATCH] refactor(test): Queries test suite to use ERPNextTestSuite --- erpnext/controllers/tests/test_queries.py | 116 +--------------------- erpnext/tests/utils.py | 48 +++++++++ 2 files changed, 50 insertions(+), 114 deletions(-) diff --git a/erpnext/controllers/tests/test_queries.py b/erpnext/controllers/tests/test_queries.py index 69ec12ebd47..9e92d7ce638 100644 --- a/erpnext/controllers/tests/test_queries.py +++ b/erpnext/controllers/tests/test_queries.py @@ -8,6 +8,7 @@ from frappe.custom.doctype.property_setter.property_setter import make_property_ from frappe.tests import IntegrationTestCase from erpnext.controllers import queries +from erpnext.tests.utils import ERPNextTestSuite def add_default_params(func, doctype): @@ -17,7 +18,7 @@ def add_default_params(func, doctype): EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "BOM", "Account"] -class TestQueries(IntegrationTestCase): +class TestQueries(ERPNextTestSuite): # All tests are based on self.globalTestRecords[doctype] @classmethod @@ -27,119 +28,6 @@ class TestQueries(IntegrationTestCase): cls.make_leads() cls.make_projects() - @classmethod - def make_employees(cls): - records = [ - { - "company": "_Test Company", - "date_of_birth": "1980-01-01", - "date_of_joining": "2010-01-01", - "department": "_Test Department - _TC", - "doctype": "Employee", - "first_name": "_Test Employee", - "gender": "Female", - "naming_series": "_T-Employee-", - "status": "Active", - "user_id": "test@example.com", - }, - { - "company": "_Test Company", - "date_of_birth": "1980-01-01", - "date_of_joining": "2010-01-01", - "department": "_Test Department 1 - _TC", - "doctype": "Employee", - "first_name": "_Test Employee 1", - "gender": "Male", - "naming_series": "_T-Employee-", - "status": "Active", - "user_id": "test1@example.com", - }, - { - "company": "_Test Company", - "date_of_birth": "1980-01-01", - "date_of_joining": "2010-01-01", - "department": "_Test Department 1 - _TC", - "doctype": "Employee", - "first_name": "_Test Employee 2", - "gender": "Male", - "naming_series": "_T-Employee-", - "status": "Active", - "user_id": "test2@example.com", - }, - ] - cls.employees = [] - for x in records: - if not frappe.db.exists("Employee", {"first_name": x.get("first_name")}): - cls.employees.append(frappe.get_doc(x).insert()) - else: - cls.employees.append(frappe.get_doc("Employee", {"first_name": x.get("first_name")})) - - @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")})) - - @classmethod - def make_projects(cls): - records = [ - { - "doctype": "Project", - "company": "_Test Company", - "project_name": "_Test Project", - "status": "Open", - } - ] - - cls.projects = [] - for x in records: - if not frappe.db.exists("Project", {"project_name": x.get("project_name")}): - cls.projects.append(frappe.get_doc(x).insert()) - else: - cls.projects.append(frappe.get_doc("Project", {"project_name": x.get("project_name")})) - def assert_nested_in(self, item, container): self.assertIn(item, [vals for tuples in container for vals in tuples]) diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index f62da50672b..7dedd637d3c 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -252,3 +252,51 @@ class ERPNextTestSuite(IntegrationTestCase): cls.sales_person.append( frappe.get_doc("Sales Person", {"sales_person_name": x.get("sales_person_name")}) ) + + @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")}))