Test case

This commit is contained in:
Anurag Mishra 2019-01-01 14:11:59 +05:30
parent 3637e14e9f
commit a3b5f5f6e4
2 changed files with 19 additions and 6 deletions

View File

@ -12,6 +12,7 @@ from frappe.utils.nestedset import NestedSet
class CircularReferenceError(frappe.ValidationError): pass
class EndDateConnotGreaterThanProjecteEndDateError(frappe.ValidationError): pass
class Task(NestedSet):
nsm_parent_field = 'parent_task'
@ -45,7 +46,8 @@ class Task(NestedSet):
doc = frappe.get_doc("Project", self.project)
if self.exp_end_date and doc.expected_end_date and getdate(self.exp_end_date) > getdate(doc.expected_end_date) :
frappe.throw(_("Expected end date cannot be after Project: "+doc.name+" Expected end date"))
frappe.msgprint(_("Expected end date cannot be after Project: <b>'{0}'</b> Expected end date").format(doc.name))
raise EndDateConnotGreaterThanProjecteEndDateError
def validate_status(self):
if self.status!=self.get_db_value("status") and self.status == "Closed":

View File

@ -5,7 +5,7 @@ import frappe
import unittest
from frappe.utils import getdate, nowdate, add_days
from erpnext.projects.doctype.task.task import CircularReferenceError
from erpnext.projects.doctype.task.task import CircularReferenceError, EndDateConnotGreaterThanProjecteEndDateError
class TestTask(unittest.TestCase):
def test_circular_reference(self):
@ -97,7 +97,16 @@ class TestTask(unittest.TestCase):
self.assertEqual(frappe.db.get_value("Task", task.name, "status"), "Overdue")
def create_task(subject, start=None, end=None, depends_on=None, project=None):
def test_end_date_validation(self):
task_end = create_task("Testing_Enddate_validation", add_days(nowdate(), -10), add_days(nowdate(), 5), save=False)
pro = frappe.get_doc("Project", task_end.project)
pro.expected_end_date = add_days(nowdate(), 20)
pro.save()
self.assertRaises(EndDateConnotGreaterThanProjecteEndDateError, task_end.save)
def create_task(subject, start=None, end=None, save=True, depends_on=None, project=None):
if not frappe.db.exists("Task", subject):
task = frappe.new_doc('Task')
task.status = "Open"
@ -105,6 +114,7 @@ def create_task(subject, start=None, end=None, depends_on=None, project=None):
task.exp_start_date = start or nowdate()
task.exp_end_date = end or nowdate()
task.project = project or "_Test Project"
if save:
task.save()
else:
task = frappe.get_doc("Task", subject)
@ -113,6 +123,7 @@ def create_task(subject, start=None, end=None, depends_on=None, project=None):
task.append("depends_on", {
"task": depends_on
})
if save:
task.save()
return task