refactor(test): Queries test suite to use ERPNextTestSuite

This commit is contained in:
ruthra kumar
2025-05-07 12:12:50 +05:30
parent 26915c622f
commit a55a86f300
2 changed files with 50 additions and 114 deletions

View File

@@ -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])

View File

@@ -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")}))