test: lead creation and deletion restricted to dummy company

This commit is contained in:
ruthra kumar 2022-10-17 16:21:54 +05:30
parent 43037d893d
commit ced8d2a537

View File

@ -15,8 +15,30 @@ from erpnext.support.doctype.service_level_agreement.service_level_agreement imp
class TestServiceLevelAgreement(unittest.TestCase): class TestServiceLevelAgreement(unittest.TestCase):
def setUp(self): def setUp(self):
self.create_company()
frappe.db.set_value("Support Settings", None, "track_service_level_agreement", 1) frappe.db.set_value("Support Settings", None, "track_service_level_agreement", 1)
frappe.db.sql("delete from `tabLead`") lead = frappe.qb.DocType("Lead")
frappe.qb.from_(lead).delete().where(lead.company == self.company).run()
def create_company(self):
name = "_Test Support SLA"
company = None
if frappe.db.exists("Company", name):
company = frappe.get_doc("Company", name)
else:
company = frappe.get_doc(
{
"doctype": "Company",
"company_name": name,
"country": "India",
"default_currency": "INR",
"create_chart_of_accounts_based_on": "Standard Template",
"chart_of_accounts": "Standard",
}
)
company = company.save()
self.company = company.name
def test_service_level_agreement(self): def test_service_level_agreement(self):
# Default Service Level Agreement # Default Service Level Agreement
@ -205,7 +227,7 @@ class TestServiceLevelAgreement(unittest.TestCase):
# make lead with default SLA # make lead with default SLA
creation = datetime.datetime(2019, 3, 4, 12, 0) creation = datetime.datetime(2019, 3, 4, 12, 0)
lead = make_lead(creation=creation, index=1) lead = make_lead(creation=creation, index=1, company=self.company)
self.assertEqual(lead.service_level_agreement, lead_sla.name) self.assertEqual(lead.service_level_agreement, lead_sla.name)
self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0)) self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0))
@ -233,7 +255,7 @@ class TestServiceLevelAgreement(unittest.TestCase):
) )
creation = datetime.datetime(2020, 3, 4, 4, 0) creation = datetime.datetime(2020, 3, 4, 4, 0)
lead = make_lead(creation, index=2) lead = make_lead(creation, index=2, company=self.company)
frappe.flags.current_time = datetime.datetime(2020, 3, 4, 4, 15) frappe.flags.current_time = datetime.datetime(2020, 3, 4, 4, 15)
lead.reload() lead.reload()
@ -267,7 +289,7 @@ class TestServiceLevelAgreement(unittest.TestCase):
) )
creation = datetime.datetime(2019, 3, 4, 12, 0) creation = datetime.datetime(2019, 3, 4, 12, 0)
lead = make_lead(creation=creation, index=1) lead = make_lead(creation=creation, index=1, company=self.company)
self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0)) self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0))
# failed with response time only # failed with response time only
@ -294,7 +316,7 @@ class TestServiceLevelAgreement(unittest.TestCase):
# fulfilled with response time only # fulfilled with response time only
creation = datetime.datetime(2019, 3, 4, 12, 0) creation = datetime.datetime(2019, 3, 4, 12, 0)
lead = make_lead(creation=creation, index=2) lead = make_lead(creation=creation, index=2, company=self.company)
self.assertEqual(lead.service_level_agreement, lead_sla.name) self.assertEqual(lead.service_level_agreement, lead_sla.name)
self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0)) self.assertEqual(lead.response_by, datetime.datetime(2019, 3, 4, 16, 0))
@ -321,7 +343,7 @@ class TestServiceLevelAgreement(unittest.TestCase):
apply_sla_for_resolution=0, apply_sla_for_resolution=0,
) )
creation = datetime.datetime(2019, 3, 4, 12, 0) creation = datetime.datetime(2019, 3, 4, 12, 0)
lead = make_lead(creation=creation, index=4) lead = make_lead(creation=creation, index=4, company=self.company)
applied_sla = frappe.db.get_value("Lead", lead.name, "service_level_agreement") applied_sla = frappe.db.get_value("Lead", lead.name, "service_level_agreement")
self.assertFalse(applied_sla) self.assertFalse(applied_sla)
@ -611,7 +633,7 @@ def create_custom_doctype():
return frappe.get_doc("DocType", "Test SLA on Custom Dt") return frappe.get_doc("DocType", "Test SLA on Custom Dt")
def make_lead(creation=None, index=0): def make_lead(creation=None, index=0, company=None):
return frappe.get_doc( return frappe.get_doc(
{ {
"doctype": "Lead", "doctype": "Lead",
@ -621,5 +643,6 @@ def make_lead(creation=None, index=0):
"creation": creation, "creation": creation,
"service_level_agreement_creation": creation, "service_level_agreement_creation": creation,
"priority": "Medium", "priority": "Medium",
"company": company,
} }
).insert(ignore_permissions=True) ).insert(ignore_permissions=True)