fix: corrected tests

This commit is contained in:
pateljannat 2020-12-10 20:55:25 +05:30
parent f936e8a334
commit e15ef1e19f
4 changed files with 71 additions and 48 deletions

View File

@ -54,17 +54,15 @@ class Project(Document):
self.project_type = template.project_type
# create tasks from template
project_tasks = []
for task in template.tasks:
template_task_details = frappe.get_doc("Task", task.task)
project_task = self.create_task_from_template(template_task_details)
project_tasks.append(self.create_task_from_template(template_task_details))
if template_task_details.depends_on:
for child_task in template_task_details.depends_on:
child_task_details = frappe.get_doc("Task",child_task.task)
self.create_task_from_template(child_task_details, project_task)
#self.dependency_mapping(template.tasks, project_tasks)
def create_task_from_template(self, task_details, project_task=None):
doc = frappe.get_doc(dict(
def create_task_from_template(self, task_details):
return frappe.get_doc(dict(
doctype = 'Task',
subject = task_details.subject,
project = self.name,
@ -75,14 +73,21 @@ class Project(Document):
task_weight = task_details.task_weight,
type = task_details.type,
issue = task_details.issue,
is_group = task_details.is_group
))
if task_details.parent_task and project_task:
doc.parent_task = project_task.name
if not task_details.is_group:
doc.depends_on = task_details.depends_on
doc.insert()
return doc
is_group = task_details.is_group,
start = task_details.start,
duration = task_details.duration
)).insert()
""" def dependency_mapping(self, template_tasks, project_tasks):
for tmp_task in template_tasks:
for prj_task in project_tasks:
if tmp_task.subject == prj_task.subject:
if tmp_task.depends_on and not prj_task.depends_on:
for child_task in tmp_task.depends_on:
child_task_detai
prj_task.depends_on = tmp_task.depends_on
"""
def is_row_updated(self, row, existing_task_data, fields):
if self.get("__islocal") or not existing_task_data: return True

View File

@ -20,15 +20,16 @@ class TestProject(unittest.TestCase):
frappe.db.sql('delete from tabTask where project = "Test Project with Templ - no parent and dependend tasks"')
frappe.delete_doc('Project', 'Test Project with Templ - no parent and dependend tasks')
if not frappe.db.exists("Task", "Test Temp Task with no parent and dependency"):
task1 = create_task(subject="Test Temp Task with no parent and dependency", is_template=1, begin=0, duration=3)
task1 = task_exists("Test Temp Task with no parent and dependency")
if not task1:
task1 = create_task(subject="Test Temp Task with no parent and dependency", is_template=1, begin=5, duration=3)
template = make_project_template("Test Project Template - no parent and dependend tasks", [task1])
project = get_project("Test Project with Templ - no parent and dependend tasks", template)
tasks = frappe.get_all('Task', '*', dict(project=project.name), order_by='creation asc')
self.assertEqual(tasks[0].subject, 'Test Temp Task with no parent and dependency')
self.assertEqual(getdate(tasks[0].exp_end_date), add_days(nowdate() + 0 + 3))
self.assertEqual(getdate(tasks[0].exp_end_date), calculate_end_date(project, tasks[0]))
self.assertEqual(len(tasks), 1)
def test_project_template_having_parent_child_tasks(self):
@ -36,28 +37,31 @@ class TestProject(unittest.TestCase):
frappe.db.sql('delete from tabTask where project = "Test Project with Templ - tasks with parent-child"')
frappe.delete_doc('Project', 'Test Project with Templ - tasks with parent-child')
if not frappe.db.exists("Task", "Test Temp Task parent"):
task1 = task_exists("Test Temp Task parent")
if not task1:
task1 = create_task(subject="Test Temp Task parent", is_group=1, is_template=1, begin=1, duration=1)
if not frappe.db.exists("Task", "Test Temp Task child 1"):
task2 = task_exists("Test Temp Task child 1")
if not task2:
task2 = create_task(subject="Test Temp Task child 1", parent_task=task1.name, is_template=1, begin=1, duration=3)
if not frappe.db.exists("Task", "Test Temp Task child 2"):
task3 = task_exists("Test Temp Task child 2")
if not task3:
task3 = create_task(subject="Test Temp Task child 2", parent_task=task1.name, is_template=1, begin=2, duration=3)
template = make_project_template("Test Project Template - tasks with parent-child", [task1, task2, task3])
template = make_project_template("Test Project Template - tasks with parent-child", [task1])
project = get_project("Test Project with Templ - tasks with parent-child", template)
tasks = frappe.get_all('Task', '*', dict(project=project.name), order_by='creation asc')
print(tasks, type(tasks), len(tasks))
print(tasks[0].duration)
self.assertEqual(tasks[0].subject, 'Test Temp Task parent')
self.assertEqual(getdate(tasks[0].exp_end_date), add_days(nowdate()+ 1 + 1))
self.assertEqual(getdate(tasks[0].exp_end_date), calculate_end_date(project, tasks[0]))
self.assertEqual(tasks[1].subject, 'Test Temp Task child 1')
self.assertEqual(getdate(tasks[1].exp_end_date), add_days(nowdate()+ 1 + 3))
self.assertEqual(getdate(tasks[1].exp_end_date), calculate_end_date(project, tasks[1]))
self.assertEqual(tasks[1].parent_task, tasks[0].name)
self.assertEqual(tasks[2].subject, 'Test Temp Task child 2')
self.assertEqual(getdate(tasks[2].exp_end_date), add_days(nowdate()+ 2 + 3))
self.assertEqual(getdate(tasks[2].exp_end_date), calculate_end_date(project, tasks[2]))
self.assertEqual(tasks[2].parent_task, tasks[0].name)
self.assertEqual(len(tasks), 3)
@ -67,22 +71,24 @@ class TestProject(unittest.TestCase):
frappe.db.sql('delete from tabTask where project = "Test Project with Templ - dependent tasks"')
frappe.delete_doc('Project', 'Test Project with Templ - dependent tasks')
if not frappe.db.exists("Task", "Test Temp Task for dependency"):
task1 = task_exists("Test Temp Task for dependency")
if not task1:
task1 = create_task(subject="Test Temp Task for dependency", is_template=1, begin=3, duration=1)
if not frappe.db.exists("Task", "Test Temp Task with dependency"):
task2 = task_exists("Test Temp Task with dependency")
if not task2:
task2 = create_task(subject="Test Temp Task with dependency", depends_on=task1.name, is_template=1, begin=2, duration=2)
template = make_project_template("Test Project Template - tasks with parent-child", [task1, task2])
template = make_project_template("Test Project with Templ - dependent tasks", [task2])
project = get_project("Test Project with Templ - tasks with parent-child", template)
tasks = frappe.get_all('Task', '*', dict(project=project.name), order_by='creation asc')
self.assertEqual(tasks[0].subject, 'Test Temp Task for dependency')
self.assertEqual(getdate(tasks[0].exp_end_date), add_days(nowdate()+ 3 + 1))
self.assertEqual(tasks[0].subject, 'Test Temp Task with dependency')
self.assertEqual(getdate(tasks[0].exp_end_date), calculate_end_date(project, tasks[0]))
self.assertEqual(tasks[0].depends_on, tasks[1].name)
self.assertEqual(tasks[1].subject, 'Test Temp Task with dependency')
self.assertEqual(getdate(tasks[1].exp_end_date), add_days(nowdate()+ 2 + 2))
self.assertEqual(tasks[1].depends_on, tasks[0].name)
self.assertEqual(tasks[1].subject, 'Test Temp Task for dependency')
self.assertEqual(getdate(tasks[1].exp_end_date), calculate_end_date(project, tasks[1]) )
self.assertEqual(len(tasks), 2)
@ -93,7 +99,7 @@ def get_project(name, template):
project_name = name,
status = 'Open',
project_template = template.name,
expected_start_date = '2019-01-01'
expected_start_date = nowdate()
)).insert()
return project
@ -114,4 +120,13 @@ def make_project(args):
if not frappe.db.exists("Project", args.project_name):
project.insert()
return project
return project
def task_exists(subject):
result = frappe.db.get_list("Task", filters={"subject": subject},fields=["name"])
if not len(result):
return False
return frappe.get_doc("Task", result[0].name)
def calculate_end_date(project, task):
return getdate(add_days(project.expected_start_date, task.start + task.duration))

View File

@ -17,9 +17,7 @@ def get_project_template(project_template_name="Test Project Template", project_
name = project_template_name,
tasks = project_tasks or [
create_task(subject="_Test Template Task 1", is_template=1, begin=0, duration=3),
create_task(subject="_Test Template Task 2", is_template=1, begin=0, duration=2),
create_task(subject="_Test Template Task 3", is_template=1, begin=2, duration=4),
create_task(subject="_Test Template Task 4", is_template=1, begin=3, duration=2),
create_task(subject="_Test Template Task 2", is_template=1, begin=0, duration=2)
]
)).insert()
@ -27,13 +25,18 @@ def get_project_template(project_template_name="Test Project Template", project_
def make_project_template(project_template_name, project_tasks=[]):
if not frappe.db.exists('Project Template', project_template_name):
frappe.get_doc(dict(
doctype = 'Project Template',
name = project_template_name,
tasks = project_tasks or [
project_tasks = project_tasks or [
create_task(subject="_Test Template Task 1", is_template=1, begin=0, duration=3),
create_task(subject="_Test Template Task 2", is_template=1, begin=0, duration=2),
]
)).insert()
doc = frappe.get_doc(dict(
doctype = 'Project Template',
name = project_template_name
))
for task in project_tasks:
doc.append("tasks",{
"task": task.name
})
doc.insert()
return frappe.get_doc('Project Template', project_template_name)

View File

@ -104,11 +104,12 @@ def create_task(subject, start=None, end=None, depends_on=None, project=None, pa
task.subject = subject
task.exp_start_date = start or nowdate()
task.exp_end_date = end or nowdate()
task.project = project or "_Test Project"
task.is_template = is_template,
task.project = project
task.is_template = is_template
task.start = begin
task.duration = duration,
task.duration = duration
task.is_group = is_group
task.parent_task = parent_task
if save:
task.save()
else:
@ -120,5 +121,4 @@ def create_task(subject, start=None, end=None, depends_on=None, project=None, pa
})
if save:
task.save()
return task