From 1fa8ed8a1f75568d08a9ebc1c5defbc9bb871cd5 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Thu, 23 Apr 2015 17:35:44 +0530 Subject: [PATCH] Test Cases Added, fixes in task --- erpnext/projects/doctype/task/task.py | 8 +- erpnext/projects/doctype/task/test_task.py | 92 ++++++++++++++++++- .../doctype/time_log/test_time_log.py | 1 - 3 files changed, 95 insertions(+), 6 deletions(-) diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index b52e2d8f5e..6b16f02cce 100644 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -9,6 +9,8 @@ from frappe import _ from frappe.model.document import Document +class ReferenceError(frappe.ValidationError): pass + class Task(Document): def get_feed(self): return '{0}: {1}'.format(_(self.status), self.subject) @@ -53,8 +55,8 @@ class Task(Document): def update_time_and_costing(self): tl = frappe.db.sql("""select min(from_time) as start_date, max(to_time) as end_date, sum(billing_amount) as total_billing_amount, sum(costing_amount) as total_costing_amount, - sum(hours) as time from `tabTime Log` where project = %s and task = %s and docstatus=1""", - (self.project, self.name),as_dict=1)[0] + sum(hours) as time from `tabTime Log` where task = %s and docstatus=1""" + ,self.name, as_dict=1)[0] if self.status == "Open": self.status = "Working" self.total_costing_amount= tl.total_costing_amount @@ -80,7 +82,7 @@ class Task(Document): def check_recursion(self, task, task_list): if task in task_list: - frappe.throw("Circular Reference Error") + frappe.throw("Circular Reference Error", ReferenceError) else : task_list.append(task) return frappe.db.get_value("Task", task, "depends_on") diff --git a/erpnext/projects/doctype/task/test_task.py b/erpnext/projects/doctype/task/test_task.py index 62e560fbe7..f1038b47f4 100644 --- a/erpnext/projects/doctype/task/test_task.py +++ b/erpnext/projects/doctype/task/test_task.py @@ -1,7 +1,95 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt from __future__ import unicode_literals - - import frappe +import unittest +from frappe.utils import getdate + test_records = frappe.get_test_records('Task') + +from erpnext.projects.doctype.task.task import ReferenceError + +class TestTask(unittest.TestCase): + def test_circular_refereence(self): + task1 = frappe.new_doc('Task') + task1.update({ + "status": "Open", + "subject": "_Test Task 3" + }) + task1.save() + + task2 = frappe.new_doc('Task') + task2.update({ + "status": "Open", + "subject": "_Test Task 4", + "depends_on": task1.name + }) + task2.save() + + task3 = frappe.new_doc('Task') + task3.update({ + "status": "Open", + "subject": "_Test Task 5", + "depends_on": task2.name + }) + task3.save() + + task1.update({ + "depends_on": task3.name + }) + self.assertRaises(ReferenceError, task1.save) + + def test_reschedule_depending_task(self): + task1 = frappe.new_doc('Task') + task1.update({ + "status": "Open", + "subject": "_Test Task 6", + "exp_start_date": "2015-1-1", + "exp_end_date": "2015-1-10" + }) + task1.save() + + task2 = frappe.new_doc('Task') + task2.update({ + "status": "Open", + "subject": "_Test Task 7", + "exp_start_date": "2015-1-11", + "exp_end_date": "2015-1-15", + "depends_on": task1.name + }) + task2.save() + + task3 = frappe.new_doc('Task') + task3.update({ + "status": "Open", + "subject": "_Test Task 5", + "exp_start_date": "2015-1-16", + "exp_end_date": "2015-1-18", + "depends_on": task2.name + }) + task3.save() + + task1.update({ + "exp_end_date": "2015-1-20" + }) + task1.save() + + self.assertEqual(frappe.db.get_value("Task", task2.name, "exp_start_date"), getdate('2015-1-21')) + self.assertEqual(frappe.db.get_value("Task", task2.name, "exp_end_date"), getdate('2015-1-25')) + + self.assertEqual(frappe.db.get_value("Task", task3.name, "exp_start_date"), getdate('2015-1-26')) + self.assertEqual(frappe.db.get_value("Task", task3.name, "exp_end_date"), getdate('2015-1-28')) + + time_log = frappe.new_doc('Time Log') + time_log.update({ + "from_time": "2015-1-1", + "to_time": "2015-1-22", + "task": task1.name + }) + time_log.submit() + + self.assertEqual(frappe.db.get_value("Task", task2.name, "exp_start_date"), getdate('2015-1-23')) + self.assertEqual(frappe.db.get_value("Task", task2.name, "exp_end_date"), getdate('2015-1-27')) + + self.assertEqual(frappe.db.get_value("Task", task3.name, "exp_start_date"), getdate('2015-1-28')) + self.assertEqual(frappe.db.get_value("Task", task3.name, "exp_end_date"), getdate('2015-1-30')) \ No newline at end of file diff --git a/erpnext/projects/doctype/time_log/test_time_log.py b/erpnext/projects/doctype/time_log/test_time_log.py index 3d9e0be5f9..9b43b0dffe 100644 --- a/erpnext/projects/doctype/time_log/test_time_log.py +++ b/erpnext/projects/doctype/time_log/test_time_log.py @@ -1,6 +1,5 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt -from __future__ import unicode_literals from __future__ import unicode_literals import frappe