test: dont create lead manually, add coverage for notes

This commit is contained in:
Sagar Vora 2022-09-02 18:30:39 +05:30
parent 58e553151e
commit 875ff15109

View File

@ -6,29 +6,20 @@ import unittest
import frappe import frappe
LEAD_EMAIL = "test_appointment_lead@example.com"
def create_test_lead():
test_lead = frappe.db.get_value("Lead", {"email_id": "test@example.com"})
if test_lead:
return frappe.get_doc("Lead", test_lead)
test_lead = frappe.get_doc(
{"doctype": "Lead", "lead_name": "Test Lead", "email_id": "test@example.com"}
)
test_lead.insert(ignore_permissions=True)
return test_lead
def create_test_appointments(): def create_test_appointment():
test_appointment = frappe.get_doc( test_appointment = frappe.get_doc(
{ {
"doctype": "Appointment", "doctype": "Appointment",
"email": "test@example.com",
"status": "Open", "status": "Open",
"customer_name": "Test Lead", "customer_name": "Test Lead",
"customer_phone_number": "666", "customer_phone_number": "666",
"customer_skype": "test", "customer_skype": "test",
"customer_email": "test@example.com", "customer_email": LEAD_EMAIL,
"scheduled_time": datetime.datetime.now(), "scheduled_time": datetime.datetime.now(),
"customer_details": "Hello, Friend!",
} }
) )
test_appointment.insert() test_appointment.insert()
@ -36,16 +27,16 @@ def create_test_appointments():
class TestAppointment(unittest.TestCase): class TestAppointment(unittest.TestCase):
test_appointment = test_lead = None def setUpClass():
frappe.db.delete("Lead", {"email_id": LEAD_EMAIL})
def setUp(self): def setUp(self):
self.test_lead = create_test_lead() self.test_appointment = create_test_appointment()
self.test_appointment = create_test_appointments() self.test_appointment.set_verified(self.test_appointment.customer_email)
def test_calendar_event_created(self): def test_calendar_event_created(self):
cal_event = frappe.get_doc("Event", self.test_appointment.calendar_event) cal_event = frappe.get_doc("Event", self.test_appointment.calendar_event)
self.assertEqual(cal_event.starts_on, self.test_appointment.scheduled_time) self.assertEqual(cal_event.starts_on, self.test_appointment.scheduled_time)
def test_lead_linked(self): def test_lead_linked(self):
lead = frappe.get_doc("Lead", self.test_lead.name) self.assertTrue(self.test_appointment.party)
self.assertIsNotNone(lead)