Skip to content

Commit

Permalink
fix: tests and sider issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed Dec 7, 2021
1 parent 4686527 commit b0d67fa
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 63 deletions.
30 changes: 29 additions & 1 deletion erpnext/hr/doctype/exit_interview/test_exit_interview.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import frappe
from frappe import _
from frappe.core.doctype.user_permission.test_user_permission import create_user
from frappe.tests.test_webform import create_custom_doctype, create_webform
from frappe.utils import getdate
Expand All @@ -13,6 +14,9 @@


class TestExitInterview(unittest.TestCase):
def setUp(self):
frappe.db.sql('delete from `tabExit Interview`')

def test_duplicate_interview(self):
employee = make_employee('employeeexit1@example.com')
frappe.db.set_value('Employee', employee, 'relieving_date', getdate())
Expand All @@ -23,6 +27,8 @@ def test_duplicate_interview(self):

def test_relieving_date_validation(self):
employee = make_employee('employeeexit2@example.com')
# unset relieving date
frappe.db.set_value('Employee', employee, 'relieving_date', None)

interview = create_exit_interview(employee, save=False)
self.assertRaises(frappe.ValidationError, interview.save)
Expand Down Expand Up @@ -52,9 +58,13 @@ def test_interview_date_updated_in_employee_master(self):
def test_send_exit_questionnaire(self):
create_custom_doctype()
create_webform()
template = create_notification_template()

webform = frappe.db.get_all('Web Form', limit=1)
frappe.db.set_value('HR Settings', 'HR Settings', 'exit_questionnaire_web_form', webform[0].name)
frappe.db.set_value('HR Settings', 'HR Settings', {
'exit_questionnaire_web_form': webform[0].name,
'exit_questionnaire_notification_template': template
})

employee = make_employee('employeeexit3@example.com')
frappe.db.set_value('Employee', employee, 'relieving_date', getdate())
Expand Down Expand Up @@ -87,3 +97,21 @@ def create_exit_interview(employee, save=True):
if save:
return doc.insert()
return doc


def create_notification_template():
template = frappe.db.exists('Email Template', _('Exit Questionnaire Notification'))
if not template:
base_path = frappe.get_app_path('erpnext', 'hr', 'doctype')
response = frappe.read_file(os.path.join(base_path, 'exit_interview/exit_questionnaire_notification_template.html'))

template = frappe.get_doc({
'doctype': 'Email Template',
'name': _('Exit Questionnaire Notification'),
'response': response,
'subject': _('Exit Questionnaire Notification'),
'owner': frappe.session.user,
}).insert(ignore_permissions=True)
template = template.name

return template
145 changes: 83 additions & 62 deletions erpnext/hr/report/employee_exits/test_employee_exits.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

from erpnext.hr.doctype.employee.test_employee import make_employee
from erpnext.hr.doctype.exit_interview.test_exit_interview import create_exit_interview
from erpnext.hr.doctype.full_and_final_statement.test_full_and_final_statement import create_full_and_final_statement
from erpnext.hr.doctype.full_and_final_statement.test_full_and_final_statement import (
create_full_and_final_statement
)
from erpnext.hr.report.employee_exits.employee_exits import execute


class TestEmployeeExits(unittest.TestCase):
@classmethod
def setUpClass(cls):
create_company()
frappe.db.sql("delete from `tabEmployee` where company='Test Company'")
frappe.db.sql("delete from `tabFull and Final Statement` where company='Test Company'")
frappe.db.sql("delete from `tabExit Interview` where company='Test Company'")
Expand All @@ -24,26 +27,30 @@ def tearDownClass(cls):

@classmethod
def create_records(cls):
cls.emp1 = make_employee('employeeexit1@example.com',
cls.emp1 = make_employee(
'employeeexit1@example.com',
company='Test Company',
date_of_joining=getdate('01-10-2021'),
relieving_date=add_days(getdate(), 14),
designation='Accountant'
)
cls.emp2 = make_employee('employeeexit2@example.com',
cls.emp2 = make_employee(
'employeeexit2@example.com',
company='Test Company',
date_of_joining=getdate('01-12-2021'),
relieving_date=add_days(getdate(), 15),
designation='Accountant'
)

cls.emp3 = make_employee('employeeexit3@example.com',
cls.emp3 = make_employee(
'employeeexit3@example.com',
company='Test Company',
date_of_joining=getdate('02-12-2021'),
relieving_date=add_days(getdate(), 29),
designation='Engineer'
)
cls.emp4 = make_employee('employeeexit4@example.com',
cls.emp4 = make_employee(
'employeeexit4@example.com',
company='Test Company',
date_of_joining=getdate('01-12-2021'),
relieving_date=add_days(getdate(), 30),
Expand Down Expand Up @@ -90,34 +97,36 @@ def test_employee_exits_summary(self):

employee1 = frappe.get_doc('Employee', self.emp1)
employee2 = frappe.get_doc('Employee', self.emp2)
expected_data = [{
'employee': employee1.name,
'employee_name': employee1.employee_name,
'date_of_joining': employee1.date_of_joining,
'relieving_date': employee1.relieving_date,
'department': employee1.department,
'designation': employee1.designation,
'reports_to': None,
'exit_interview': self.interview1.name,
'interview_status': self.interview1.status,
'employee_status': '',
'questionnaire': employee1.name,
'full_and_final_statement': self.fnf1.name
},
{
'employee': employee2.name,
'employee_name': employee2.employee_name,
'date_of_joining': employee2.date_of_joining,
'relieving_date': employee2.relieving_date,
'department': employee2.department,
'designation': employee2.designation,
'reports_to': None,
'exit_interview': self.interview2.name,
'interview_status': self.interview2.status,
'employee_status': '',
'questionnaire': employee2.name,
'full_and_final_statement': self.fnf2.name
}]
expected_data = [
{
'employee': employee1.name,
'employee_name': employee1.employee_name,
'date_of_joining': employee1.date_of_joining,
'relieving_date': employee1.relieving_date,
'department': employee1.department,
'designation': employee1.designation,
'reports_to': None,
'exit_interview': self.interview1.name,
'interview_status': self.interview1.status,
'employee_status': '',
'questionnaire': employee1.name,
'full_and_final_statement': self.fnf1.name
},
{
'employee': employee2.name,
'employee_name': employee2.employee_name,
'date_of_joining': employee2.date_of_joining,
'relieving_date': employee2.relieving_date,
'department': employee2.department,
'designation': employee2.designation,
'reports_to': None,
'exit_interview': self.interview2.name,
'interview_status': self.interview2.status,
'employee_status': '',
'questionnaire': employee2.name,
'full_and_final_statement': self.fnf2.name
}
]

self.assertEqual(expected_data, report[1]) # rows

Expand Down Expand Up @@ -189,33 +198,45 @@ def test_pending_fnf_summary(self):

employee3 = frappe.get_doc('Employee', self.emp3)
employee4 = frappe.get_doc('Employee', self.emp4)
expected_data = [{
'employee': employee3.name,
'employee_name': employee3.employee_name,
'date_of_joining': employee3.date_of_joining,
'relieving_date': employee3.relieving_date,
'department': employee3.department,
'designation': employee3.designation,
'reports_to': None,
'exit_interview': self.interview3.name,
'interview_status': self.interview3.status,
'employee_status': '',
'questionnaire': employee3.name,
'full_and_final_statement': None
},
{
'employee': employee4.name,
'employee_name': employee4.employee_name,
'date_of_joining': employee4.date_of_joining,
'relieving_date': employee4.relieving_date,
'department': employee4.department,
'designation': employee4.designation,
'reports_to': None,
'exit_interview': None,
'interview_status': None,
'employee_status': None,
'questionnaire': None,
'full_and_final_statement': None
}]
expected_data = [
{
'employee': employee3.name,
'employee_name': employee3.employee_name,
'date_of_joining': employee3.date_of_joining,
'relieving_date': employee3.relieving_date,
'department': employee3.department,
'designation': employee3.designation,
'reports_to': None,
'exit_interview': self.interview3.name,
'interview_status': self.interview3.status,
'employee_status': '',
'questionnaire': employee3.name,
'full_and_final_statement': None
},
{
'employee': employee4.name,
'employee_name': employee4.employee_name,
'date_of_joining': employee4.date_of_joining,
'relieving_date': employee4.relieving_date,
'department': employee4.department,
'designation': employee4.designation,
'reports_to': None,
'exit_interview': None,
'interview_status': None,
'employee_status': None,
'questionnaire': None,
'full_and_final_statement': None
}
]

self.assertEqual(expected_data, report[1]) # rows


self.assertEqual(expected_data, report[1]) # rows
def create_company():
if not frappe.db.exists('Company', 'Test Company'):
frappe.get_doc({
'doctype': 'Company',
'company_name': 'Test Company',
'default_currency': 'INR',
'country': 'India'
}).insert()

0 comments on commit b0d67fa

Please sign in to comment.