test: Job Opening against a Staffing Plan

This commit is contained in:
Rucha Mahabal 2022-05-26 11:32:46 +05:30
parent 29228575fa
commit ab0ef60918
2 changed files with 79 additions and 7 deletions

View File

@ -3,8 +3,77 @@
import unittest
# test_records = frappe.get_test_records('Job Opening')
import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, getdate
from erpnext.hr.doctype.employee.test_employee import make_employee
from erpnext.hr.doctype.staffing_plan.test_staffing_plan import make_company
class TestJobOpening(unittest.TestCase):
pass
class TestJobOpening(FrappeTestCase):
def setUp(self):
frappe.db.delete("Staffing Plan")
frappe.db.delete("Staffing Plan Detail")
frappe.db.delete("Job Opening")
make_company("_Test Opening Company", "_TOC")
frappe.db.delete("Employee", {"company": "_Test Opening Company"})
def test_vacancies_fulfilled(self):
make_employee(
"test_job_opening@example.com", company="_Test Opening Company", designation="Designer"
)
staffing_plan = frappe.get_doc(
{
"doctype": "Staffing Plan",
"company": "_Test Opening Company",
"name": "Test",
"from_date": getdate(),
"to_date": add_days(getdate(), 10),
}
)
staffing_plan.append(
"staffing_details",
{"designation": "Designer", "vacancies": 1, "estimated_cost_per_position": 50000},
)
staffing_plan.insert()
staffing_plan.submit()
self.assertEqual(staffing_plan.staffing_details[0].number_of_positions, 2)
# allows creating 1 job opening as per vacancy
opening_1 = get_job_opening()
opening_1.insert()
# vacancies as per staffing plan already fulfilled via job opening and existing employee count
opening_2 = get_job_opening(job_title="Designer New")
self.assertRaises(frappe.ValidationError, opening_2.insert)
# allows updating existing job opening
opening_1.status = "Closed"
opening_1.save()
def get_job_opening(**args):
args = frappe._dict(args)
opening = frappe.db.exists("Job Opening", {"job_title": args.job_title or "Designer"})
if opening:
return frappe.get_doc("Job Opening", opening)
opening = frappe.get_doc(
{
"doctype": "Job Opening",
"job_title": "Designer",
"designation": "Designer",
"company": "_Test Opening Company",
"status": "Open",
}
)
opening.update(args)
return opening

View File

@ -85,13 +85,16 @@ def _set_up():
make_company()
def make_company():
if frappe.db.exists("Company", "_Test Company 10"):
def make_company(name=None, abbr=None):
if not name:
name = "_Test Company 10"
if frappe.db.exists("Company", name):
return
company = frappe.new_doc("Company")
company.company_name = "_Test Company 10"
company.abbr = "_TC10"
company.company_name = name
company.abbr = abbr or "_TC10"
company.parent_company = "_Test Company 3"
company.default_currency = "INR"
company.country = "Pakistan"