diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index 013d36691db..6fa655c0a36 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -3,18 +3,22 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import now_datetime, nowdate from erpnext.accounts.doctype.budget.budget import BudgetError, get_actual_expense from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry from erpnext.accounts.utils import get_fiscal_year from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Monthly Distribution"] +from erpnext.tests.utils import ERPNextTestSuite -class TestBudget(IntegrationTestCase): +class TestBudget(ERPNextTestSuite): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.make_monthly_distribution() + cls.make_projects() + def test_monthly_budget_crossed_ignore(self): set_total_expense_zero(nowdate(), "cost_center") diff --git a/erpnext/accounts/doctype/monthly_distribution/test_records.json b/erpnext/accounts/doctype/monthly_distribution/test_records.json deleted file mode 100644 index 8dbf210ce65..00000000000 --- a/erpnext/accounts/doctype/monthly_distribution/test_records.json +++ /dev/null @@ -1,44 +0,0 @@ -[{ - "doctype": "Monthly Distribution", - "distribution_id": "_Test Distribution", - "fiscal_year": "_Test Fiscal Year 2013", - "percentages": [ - { - "month": "January", - "percentage_allocation": "8" - }, { - "month": "February", - "percentage_allocation": "8" - }, { - "month": "March", - "percentage_allocation": "8" - }, { - "month": "April", - "percentage_allocation": "8" - }, { - "month": "May", - "percentage_allocation": "8" - }, { - "month": "June", - "percentage_allocation": "8" - }, { - "month": "July", - "percentage_allocation": "8" - }, { - "month": "August", - "percentage_allocation": "8" - }, { - "month": "September", - "percentage_allocation": "8" - }, { - "month": "October", - "percentage_allocation": "8" - }, { - "month": "November", - "percentage_allocation": "10" - }, { - "month": "December", - "percentage_allocation": "10" - } - ] -}] diff --git a/erpnext/accounts/doctype/sales_invoice/test_records.json b/erpnext/accounts/doctype/sales_invoice/test_records.json index 61e5219c80c..814c6757d38 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_records.json +++ b/erpnext/accounts/doctype/sales_invoice/test_records.json @@ -55,20 +55,6 @@ ], "plc_conversion_rate": 1.0, "price_list_currency": "INR", - "sales_team": [ - { - "allocated_percentage": 65.5, - "doctype": "Sales Team", - "parentfield": "sales_team", - "sales_person": "_Test Sales Person 1" - }, - { - "allocated_percentage": 34.5, - "doctype": "Sales Team", - "parentfield": "sales_team", - "sales_person": "_Test Sales Person 2" - } - ], "selling_price_list": "_Test Price List", "territory": "_Test Territory" }, diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index dcd465e51a4..367f3f82ccd 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -48,6 +48,7 @@ from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ) from erpnext.stock.get_item_details import get_item_tax_map from erpnext.stock.utils import get_incoming_rate, get_stock_balance +from erpnext.tests.utils import ERPNextTestSuite class UnitTestSalesInvoice(UnitTestCase): @@ -59,7 +60,7 @@ class UnitTestSalesInvoice(UnitTestCase): pass -class TestSalesInvoice(IntegrationTestCase): +class TestSalesInvoice(ERPNextTestSuite): def setUp(self): from erpnext.stock.doctype.stock_ledger_entry.test_stock_ledger_entry import create_items @@ -87,6 +88,8 @@ class TestSalesInvoice(IntegrationTestCase): def setUpClass(cls): super().setUpClass() cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) + cls.make_employees() + cls.make_sales_person() unlink_payment_on_cancel_of_invoice() @classmethod diff --git a/erpnext/controllers/tests/test_queries.py b/erpnext/controllers/tests/test_queries.py index 124a351212a..9e92d7ce638 100644 --- a/erpnext/controllers/tests/test_queries.py +++ b/erpnext/controllers/tests/test_queries.py @@ -8,18 +8,26 @@ 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): return partial(func, doctype=doctype, txt="", searchfield="name", start=0, page_len=20, filters=None) -EXTRA_TEST_RECORD_DEPENDENCIES = ["Employee", "Lead", "Item", "BOM", "Project", "Account"] +EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "BOM", "Account"] -class TestQueries(IntegrationTestCase): +class TestQueries(ERPNextTestSuite): # All tests are based on self.globalTestRecords[doctype] + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.make_employees() + cls.make_leads() + cls.make_projects() + def assert_nested_in(self, item, container): self.assertIn(item, [vals for tuples in container for vals in tuples]) @@ -105,7 +113,7 @@ class TestQueries(IntegrationTestCase): { "user": user.name, "doctype": "Employee", - "docname": "_T-Employee-00001", + "docname": self.employees[0].name, "is_default": 1, "apply_to_all_doctypes": 1, "applicable_doctypes": [], diff --git a/erpnext/crm/doctype/lead/test_lead.py b/erpnext/crm/doctype/lead/test_lead.py index 7c7b4320b6a..b1b4e162b32 100644 --- a/erpnext/crm/doctype/lead/test_lead.py +++ b/erpnext/crm/doctype/lead/test_lead.py @@ -8,17 +8,23 @@ from frappe.utils import random_string, today from erpnext.crm.doctype.lead.lead import make_opportunity from erpnext.crm.utils import get_linked_prospect +from erpnext.tests.utils import ERPNextTestSuite -class TestLead(IntegrationTestCase): +class TestLead(ERPNextTestSuite): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.make_leads() + 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 +48,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" -} -] diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index b21f87d17ba..db9866d9b89 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -10,9 +10,40 @@ from erpnext.crm.doctype.lead.lead import make_customer from erpnext.crm.doctype.lead.test_lead import make_lead from erpnext.crm.doctype.opportunity.opportunity import make_quotation from erpnext.crm.utils import get_linked_communication_list +from erpnext.tests.utils import ERPNextTestSuite -class TestOpportunity(IntegrationTestCase): +class TestOpportunity(ERPNextTestSuite): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Only first lead is required + # TODO: dynamically generate limited test records + cls.make_leads() + cls.make_opportunities() + + @classmethod + def make_opportunities(cls): + records = [ + { + "doctype": "Opportunity", + "name": "_Test Opportunity 1", + "opportunity_from": "Lead", + "enquiry_type": "Sales", + "party_name": cls.leads[0].name, + "transaction_date": "2013-12-12", + "items": [ + {"item_name": "Test Item", "description": "Some description", "qty": 5, "rate": 100} + ], + } + ] + cls.opportunities = [] + for x in records: + if not frappe.db.exists("Opportunity", {"name": x.get("name")}): + cls.opportunities.append(frappe.get_doc(x).insert()) + else: + cls.opportunities.append(frappe.get_doc("Opportunity", {"party_name": x.get("party_name")})) + def test_opportunity_status(self): doc = make_opportunity(with_items=0) quotation = make_quotation(doc.name) diff --git a/erpnext/crm/doctype/opportunity/test_records.json b/erpnext/crm/doctype/opportunity/test_records.json deleted file mode 100644 index f7e8350f308..00000000000 --- a/erpnext/crm/doctype/opportunity/test_records.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - { - "doctype": "Opportunity", - "name": "_Test Opportunity 1", - "opportunity_from": "Lead", - "enquiry_type": "Sales", - "party_name": "_T-Lead-00001", - "transaction_date": "2013-12-12", - "items": [{ - "item_name": "Test Item", - "description": "Some description", - "qty": 5, - "rate": 100 - }] - } -] diff --git a/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py b/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py index 34c6e955240..206c9687c31 100644 --- a/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py +++ b/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py @@ -16,6 +16,30 @@ from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_i class TestMaintenanceSchedule(IntegrationTestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.make_sales_person() + + @classmethod + def make_sales_person(cls): + records = [ + { + "doctype": "Sales Person", + "is_group": 0, + "parent_sales_person": "Sales Team", + "sales_person_name": "_Test Sales Person", + }, + ] + cls.sales_person = [] + for x in records: + if not frappe.db.exists("Sales Person", {"sales_person_name": x.get("sales_person_name")}): + cls.sales_person.append(frappe.get_doc(x).insert()) + else: + cls.sales_person.append( + frappe.get_doc("Sales Person", {"sales_person_name": x.get("sales_person_name")}) + ) + def test_events_should_be_created_and_deleted(self): ms = make_maintenance_schedule() ms.generate_schedule() @@ -136,7 +160,7 @@ class TestMaintenanceSchedule(IntegrationTestCase): self.assertFalse(ms.validate_items_table_change()) # After Save ms.items[0].serial_no = "TEST001" - ms.items[0].sales_person = "_Test Sales Person" + ms.items[0].sales_person = self.sales_person[0].name ms.items[0].no_of_visits = 2 self.assertTrue(ms.validate_items_table_change()) ms.save() diff --git a/erpnext/projects/doctype/activity_cost/test_activity_cost.py b/erpnext/projects/doctype/activity_cost/test_activity_cost.py index 03db2fe6d5a..470b21cca87 100644 --- a/erpnext/projects/doctype/activity_cost/test_activity_cost.py +++ b/erpnext/projects/doctype/activity_cost/test_activity_cost.py @@ -6,16 +6,23 @@ import frappe from frappe.tests import IntegrationTestCase from erpnext.projects.doctype.activity_cost.activity_cost import DuplicationError +from erpnext.tests.utils import ERPNextTestSuite -class TestActivityCost(IntegrationTestCase): +class TestActivityCost(ERPNextTestSuite): + @classmethod + def setUpClass(cls): + super().setUpClass() + # TODO: only 1 employee is required + cls.make_employees() + def test_duplication(self): frappe.db.sql("delete from `tabActivity Cost`") activity_cost1 = frappe.new_doc("Activity Cost") activity_cost1.update( { - "employee": "_T-Employee-00001", - "employee_name": "_Test Employee", + "employee": self.employees[0].name, + "employee_name": self.employees[0].first_name, "activity_type": "_Test Activity Type 1", "billing_rate": 100, "costing_rate": 50, diff --git a/erpnext/projects/doctype/project/test_project.py b/erpnext/projects/doctype/project/test_project.py index 901f7beabf1..2c88b88ff4e 100644 --- a/erpnext/projects/doctype/project/test_project.py +++ b/erpnext/projects/doctype/project/test_project.py @@ -9,6 +9,7 @@ from erpnext.projects.doctype.project_template.test_project_template import make from erpnext.projects.doctype.task.test_task import create_task from erpnext.selling.doctype.sales_order.sales_order import make_project as make_project_from_so from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order +from erpnext.tests.utils import ERPNextTestSuite IGNORE_TEST_RECORD_DEPENDENCIES = ["Sales Order"] @@ -22,7 +23,12 @@ class UnitTestProject(UnitTestCase): pass -class TestProject(IntegrationTestCase): +class TestProject(ERPNextTestSuite): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.make_projects() + def test_project_with_template_having_no_parent_and_depend_tasks(self): project_name = "Test Project with Template - No Parent and Dependend Tasks" frappe.db.sql(""" delete from tabTask where project = %s """, project_name) diff --git a/erpnext/projects/doctype/project/test_records.json b/erpnext/projects/doctype/project/test_records.json deleted file mode 100644 index 49021da4b7c..00000000000 --- a/erpnext/projects/doctype/project/test_records.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "company": "_Test Company", - "project_name": "_Test Project", - "status": "Open" - } -] \ No newline at end of file diff --git a/erpnext/projects/doctype/task/test_task.py b/erpnext/projects/doctype/task/test_task.py index 082b474c07a..7a93585e832 100644 --- a/erpnext/projects/doctype/task/test_task.py +++ b/erpnext/projects/doctype/task/test_task.py @@ -7,9 +7,15 @@ from frappe.tests import IntegrationTestCase from frappe.utils import add_days, getdate, nowdate from erpnext.projects.doctype.task.task import CircularReferenceError +from erpnext.tests.utils import ERPNextTestSuite -class TestTask(IntegrationTestCase): +class TestTask(ERPNextTestSuite): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.make_projects() + def test_circular_reference(self): task1 = create_task("_Test Task 1", add_days(nowdate(), -15), add_days(nowdate(), -10)) task2 = create_task("_Test Task 2", add_days(nowdate(), 11), add_days(nowdate(), 15), task1.name) diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index 311fe3da140..f9c631b00a8 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -10,9 +10,15 @@ from frappe.utils import add_to_date, now_datetime, nowdate from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.projects.doctype.timesheet.timesheet import OverlapError, make_sales_invoice from erpnext.setup.doctype.employee.test_employee import make_employee +from erpnext.tests.utils import ERPNextTestSuite -class TestTimesheet(IntegrationTestCase): +class TestTimesheet(ERPNextTestSuite): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.make_projects() + def setUp(self): frappe.db.delete("Timesheet") diff --git a/erpnext/setup/doctype/employee/test_records.json b/erpnext/setup/doctype/employee/test_records.json deleted file mode 100644 index dfd3eed6ea5..00000000000 --- a/erpnext/setup/doctype/employee/test_records.json +++ /dev/null @@ -1,38 +0,0 @@ -[ - { - "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" - } -] \ No newline at end of file diff --git a/erpnext/setup/doctype/sales_person/test_records.json b/erpnext/setup/doctype/sales_person/test_records.json deleted file mode 100644 index 536552a0c34..00000000000 --- a/erpnext/setup/doctype/sales_person/test_records.json +++ /dev/null @@ -1,23 +0,0 @@ -[ - { - "doctype": "Sales Person", - "employee": "_T-Employee-00001", - "is_group": 0, - "parent_sales_person": "Sales Team", - "sales_person_name": "_Test Sales Person" - }, - { - "doctype": "Sales Person", - "employee": "_T-Employee-00002", - "is_group": 0, - "parent_sales_person": "Sales Team", - "sales_person_name": "_Test Sales Person 1" - }, - { - "doctype": "Sales Person", - "employee": "_T-Employee-00003", - "is_group": 0, - "parent_sales_person": "Sales Team", - "sales_person_name": "_Test Sales Person 2" - } -] \ No newline at end of file diff --git a/erpnext/setup/doctype/sales_person/test_sales_person.py b/erpnext/setup/doctype/sales_person/test_sales_person.py deleted file mode 100644 index 650b1d27c25..00000000000 --- a/erpnext/setup/doctype/sales_person/test_sales_person.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Employee"] - -import frappe - -IGNORE_TEST_RECORD_DEPENDENCIES = ["Item Group"] diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index 7ed84514f52..7dedd637d3c 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -5,6 +5,7 @@ from typing import Any, NewType import frappe from frappe.core.doctype.report.report import get_report_module_dotted_path +from frappe.tests import IntegrationTestCase ReportFilters = dict[str, Any] ReportName = NewType("ReportName", str) @@ -114,3 +115,188 @@ def if_lending_app_not_installed(function): return return wrapper + + +class ERPNextTestSuite(IntegrationTestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + @classmethod + def make_monthly_distribution(cls): + records = [ + { + "doctype": "Monthly Distribution", + "distribution_id": "_Test Distribution", + "fiscal_year": "_Test Fiscal Year 2013", + "percentages": [ + {"month": "January", "percentage_allocation": "8"}, + {"month": "February", "percentage_allocation": "8"}, + {"month": "March", "percentage_allocation": "8"}, + {"month": "April", "percentage_allocation": "8"}, + {"month": "May", "percentage_allocation": "8"}, + {"month": "June", "percentage_allocation": "8"}, + {"month": "July", "percentage_allocation": "8"}, + {"month": "August", "percentage_allocation": "8"}, + {"month": "September", "percentage_allocation": "8"}, + {"month": "October", "percentage_allocation": "8"}, + {"month": "November", "percentage_allocation": "10"}, + {"month": "December", "percentage_allocation": "10"}, + ], + } + ] + cls.monthly_distribution = [] + for x in records: + if not frappe.db.exists("Monthly Distribution", {"distribution_id": x.get("distribution_id")}): + cls.monthly_distribution.append(frappe.get_doc(x).insert()) + else: + cls.monthly_distribution.append( + frappe.get_doc("Monthly Distribution", {"distribution_id": x.get("distribution_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")})) + + @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_sales_person(cls): + records = [ + { + "doctype": "Sales Person", + "employee": "_T-Employee-00001", + "is_group": 0, + "parent_sales_person": "Sales Team", + "sales_person_name": "_Test Sales Person", + }, + { + "doctype": "Sales Person", + "employee": "_T-Employee-00002", + "is_group": 0, + "parent_sales_person": "Sales Team", + "sales_person_name": "_Test Sales Person 1", + }, + { + "doctype": "Sales Person", + "employee": "_T-Employee-00003", + "is_group": 0, + "parent_sales_person": "Sales Team", + "sales_person_name": "_Test Sales Person 2", + }, + ] + cls.sales_person = [] + for x in records: + if not frappe.db.exists("Sales Person", {"sales_person_name": x.get("sales_person_name")}): + cls.sales_person.append(frappe.get_doc(x).insert()) + else: + 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")}))