本文整理汇总了Python中integration.ggrc_workflows.generator.WorkflowsGenerator.modify_object方法的典型用法代码示例。如果您正苦于以下问题:Python WorkflowsGenerator.modify_object方法的具体用法?Python WorkflowsGenerator.modify_object怎么用?Python WorkflowsGenerator.modify_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类integration.ggrc_workflows.generator.WorkflowsGenerator
的用法示例。
在下文中一共展示了WorkflowsGenerator.modify_object方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestWorkflowCycleStatePropagantion
# 需要导入模块: from integration.ggrc_workflows.generator import WorkflowsGenerator [as 别名]
# 或者: from integration.ggrc_workflows.generator.WorkflowsGenerator import modify_object [as 别名]
class TestWorkflowCycleStatePropagantion(TestCase):
"""Test case for cycle task to cycle task group status propagation"""
def setUp(self):
super(TestWorkflowCycleStatePropagantion, self).setUp()
self.api = Api()
self.generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
self.weekly_wf = {
"title": "weekly thingy",
"description": "start this many a time",
"frequency": "weekly",
"task_groups": [{
"title": "weekly task group",
"task_group_tasks": [{
"title": "weekly task 1",
"relative_end_day": 1,
"relative_end_month": None,
"relative_start_day": 5,
"relative_start_month": None,
}, {
"title": "weekly task 1",
"relative_end_day": 1,
"relative_end_month": None,
"relative_start_day": 1,
"relative_start_month": None,
}
]},
]
}
def test_weekly_state_transitions_assigned_inprogress(self):
"Test that starting one cycle task changes cycle task group"
_, wf = self.generator.generate_workflow(self.weekly_wf)
with freeze_time("2016-6-10 13:00:00"): # Friday, 6/10/2016
self.generator.activate_workflow(wf)
ctg = db.session.query(CycleTaskGroup).join(
Cycle).join(Workflow).filter(Workflow.id == wf.id).all()[0]
self.assertEqual(ctg.status, "Assigned")
cycle_tasks = db.session.query(CycleTaskGroupObjectTask).join(
Cycle).join(Workflow).filter(Workflow.id == wf.id).all()
first_ct, second_ct = cycle_tasks
for cycle_task in cycle_tasks:
self.assertEqual(cycle_task.status, "Assigned")
# Move one task to InProgress
_, first_ct = self.generator.modify_object(
first_ct, {"status": "InProgress"})
self.assertEqual(first_ct.status, "InProgress")
ctg = db.session.query(CycleTaskGroup).get(ctg.id)
self.assertEqual(ctg.status, "InProgress")
# Undo operation
_, first_ct = self.generator.modify_object(
first_ct, {"status": "Assigned"})
self.assertEqual(first_ct.status, "Assigned")
ctg = db.session.query(CycleTaskGroup).get(ctg.id)
self.assertEqual(ctg.status, "Assigned")
# Move both to in progress
for cycle_task in cycle_tasks:
self.generator.modify_object(
cycle_task, {"status": "InProgress"})
ctg = db.session.query(CycleTaskGroup).get(ctg.id)
self.assertEqual(ctg.status, "InProgress")
# Undo one cycle task
_, first_ct = self.generator.modify_object(
first_ct, {"status": "Assigned"})
second_ct = db.session.query(CycleTaskGroupObjectTask).get(second_ct.id)
ctg = db.session.query(CycleTaskGroup).get(ctg.id)
self.assertEqual(first_ct.status, "Assigned")
self.assertEqual(second_ct.status, "InProgress")
self.assertEqual(ctg.status, "InProgress")
# Undo second cycle task
_, second_ct = self.generator.modify_object(
second_ct, {"status": "Assigned"})
first_ct = db.session.query(CycleTaskGroupObjectTask).get(first_ct.id)
ctg = db.session.query(CycleTaskGroup).get(ctg.id)
self.assertEqual(first_ct.status, "Assigned")
self.assertEqual(second_ct.status, "Assigned")
self.assertEqual(ctg.status, "Assigned")
def test_weekly_state_transitions_inprogress_finished(self):
"Test In Progress to Finished transitions"
_, wf = self.generator.generate_workflow(self.weekly_wf)
with freeze_time("2016-6-10 13:00:00"): # Friday, 6/10/2016
self.generator.activate_workflow(wf)
#.........这里部分代码省略.........
示例2: TestOneTimeWfEndDateChange
# 需要导入模块: from integration.ggrc_workflows.generator import WorkflowsGenerator [as 别名]
# 或者: from integration.ggrc_workflows.generator.WorkflowsGenerator import modify_object [as 别名]
#.........这里部分代码省略.........
_, workflow = self.wf_generator.generate_workflow(
self.one_time_workflow_1)
_, cycle = self.wf_generator.generate_cycle(workflow)
self.wf_generator.activate_workflow(workflow)
with freeze_time("2015-04-11 03:21:34"):
user = get_person(self.user.id)
_, notif_data = common.get_daily_notifications()
self.assertIn("cycle_started", notif_data[user.email])
with freeze_time("2015-05-02 03:21:34"):
_, notif_data = common.get_daily_notifications()
self.assertIn(user.email, notif_data)
self.assertIn("cycle_started", notif_data[user.email])
self.assertNotIn("due_in", notif_data[user.email])
self.assertNotIn("due_today", notif_data[user.email])
with freeze_time("2015-05-02 03:21:34"):
common.send_daily_digest_notifications()
_, notif_data = common.get_daily_notifications()
self.assertEqual(notif_data, {})
# one email to owner and one to assigne
self.assertEqual(mock_mail.call_count, 2)
with freeze_time("2015-05-03 03:21:34"):
cycle = Cycle.query.get(cycle.id)
task1 = CycleTaskGroupObjectTask.query.get(
cycle.cycle_task_group_object_tasks[0].id)
task2 = CycleTaskGroupObjectTask.query.get(
cycle.cycle_task_group_object_tasks[1].id)
self.wf_generator.modify_object(
task1, data={"end_date": date(2015, 5, 15)})
self.wf_generator.modify_object(
task2, data={"end_date": date(2015, 5, 15)})
with freeze_time("2015-05-04 03:21:34"): # one day befor due date
_, notif_data = common.get_daily_notifications()
user = get_person(self.user.id)
self.assertEqual(notif_data, {})
with freeze_time("2015-05-05 03:21:34"): # due date
_, notif_data = common.get_daily_notifications()
self.assertEqual(notif_data, {})
with freeze_time("2015-05-14 03:21:34"): # due date
_, notif_data = common.get_daily_notifications()
self.assertIn(user.email, notif_data)
self.assertIn("due_in", notif_data[user.email])
self.assertEqual(len(notif_data[user.email]["due_in"]),
len(self.random_objects))
with freeze_time("2015-05-15 03:21:34"): # due date
_, notif_data = common.get_daily_notifications()
self.assertIn(user.email, notif_data)
# yesterdays mail has not been sent
self.assertIn("due_in", notif_data[user.email])
self.assertIn("due_today", notif_data[user.email])
self.assertEqual(len(notif_data[user.email]["due_today"]),
len(self.random_objects))
@patch("ggrc.notifications.common.send_email")
示例3: TestCycleTaskImportUpdate
# 需要导入模块: from integration.ggrc_workflows.generator import WorkflowsGenerator [as 别名]
# 或者: from integration.ggrc_workflows.generator.WorkflowsGenerator import modify_object [as 别名]
#.........这里部分代码省略.........
self.generated_cycle_tasks_active)
expected_cycle_task_permission_error.update(
self.generated_cycle_tasks_historical)
self._cmp_tasks(expected_cycle_task_permission_error)
def _cmp_tasks(self, expected_ctasks):
"""Compare tasks values from argument's list and test DB."""
for ctask in db.session.query(CycleTaskGroupObjectTask).all():
if ctask.slug not in expected_ctasks:
continue
exp_task = expected_ctasks[ctask.slug]
for attr, val in exp_task.iteritems():
self.assertEqual(str(getattr(ctask, attr, None)), val)
# pylint: disable=too-many-arguments
def _activate_workflow(self, ftime, workflow, task_group, task_group_tasks,
random_object, cycle_tasks):
"""Helper which is responsible for active cycle-tasks creation"""
with freeze_time(ftime):
_, wf = self.wf_generator.generate_workflow(workflow)
_, tg = self.wf_generator.generate_task_group(wf, task_group)
for task in task_group_tasks:
self.wf_generator.generate_task_group_task(tg, task)
self.wf_generator.generate_task_group_object(tg, random_object)
_, cycle = self.wf_generator.generate_cycle(wf)
self.wf_generator.activate_workflow(wf)
for exp_slug, exp_task in cycle_tasks.iteritems():
obj = db.session.query(CycleTaskGroupObjectTask).filter_by(
slug=exp_slug
).first()
if exp_task["status"] == "Verified":
self.wf_generator.modify_object(obj, {"status": "Finished"})
self.wf_generator.modify_object(obj, {"status": exp_task["status"]})
self._cmp_tasks(cycle_tasks)
return cycle
def _generate_cycle_tasks(self):
"""Helper which is responsible for test data creation"""
self._activate_workflow(self.ftime_active, self.workflow_active,
self.task_group_active,
self.task_group_tasks_active,
self.random_objects[0],
self.generated_cycle_tasks_active)
cycle = self._activate_workflow(self.ftime_historical,
self.workflow_historical,
self.task_group_historical,
self.task_group_tasks_historical,
self.random_objects[1],
self.generated_cycle_tasks_historical)
with freeze_time(self.ftime_historical):
cycle = Cycle.query.get(cycle.id)
self.wf_generator.modify_object(cycle, data={"is_current": False})
def _create_test_cases_data(self):
"""Create test cases data: for object generation,
expected data for checks"""
def person_dict(person_id):
"""Return person data"""
return {
"href": "/api/people/%d" % person_id,
"id": person_id,
"type": "Person"
}
示例4: TestBasicWorkflowActions
# 需要导入模块: from integration.ggrc_workflows.generator import WorkflowsGenerator [as 别名]
# 或者: from integration.ggrc_workflows.generator.WorkflowsGenerator import modify_object [as 别名]
class TestBasicWorkflowActions(TestCase):
"""
Tests for basic workflow actions
"""
def setUp(self):
super(TestBasicWorkflowActions, self).setUp()
self.api = Api()
self.generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
self.random_objects = self.object_generator.generate_random_objects()
self.create_test_cases()
def tearDown(self):
pass
def test_create_workflows(self):
_, wflow = self.generator.generate_workflow(self.one_time_workflow_1)
self.assertIsInstance(wflow, Workflow)
task_groups = db.session.query(TaskGroup)\
.filter(TaskGroup.workflow_id == wflow.id).all()
self.assertEqual(len(task_groups),
len(self.one_time_workflow_1["task_groups"]))
def test_workflows(self):
for workflow in self.all_workflows:
_, wflow = self.generator.generate_workflow(workflow)
self.assertIsInstance(wflow, Workflow)
task_groups = db.session.query(TaskGroup)\
.filter(TaskGroup.workflow_id == wflow.id).all()
self.assertEqual(len(task_groups),
len(workflow["task_groups"]))
def test_activate_wf(self):
for workflow in self.all_workflows:
_, wflow = self.generator.generate_workflow(workflow)
response, wflow = self.generator.activate_workflow(wflow)
self.assert200(response)
def test_one_time_workflow_edits(self):
_, wflow = self.generator.generate_workflow(self.one_time_workflow_1)
wf_dict = {"title": "modified one time wf"}
self.generator.modify_workflow(wflow, data=wf_dict)
modified_wf = db.session.query(Workflow).filter(
Workflow.id == wflow.id).one()
self.assertEqual(wf_dict["title"], modified_wf.title)
def test_one_time_wf_activate(self):
_, wflow = self.generator.generate_workflow(self.one_time_workflow_1)
self.generator.generate_cycle(wflow)
self.generator.activate_workflow(wflow)
tasks = [len(tg.get("task_group_tasks", []))
for tg in self.one_time_workflow_1["task_groups"]]
cycle_tasks = db.session.query(CycleTaskGroupObjectTask).join(
Cycle).join(Workflow).filter(Workflow.id == wflow.id).all()
active_wf = db.session.query(Workflow).filter(
Workflow.id == wflow.id).one()
self.assertEqual(sum(tasks), len(cycle_tasks))
self.assertEqual(active_wf.status, "Active")
def test_one_time_wf_state_transition_dates(self):
_, wflow = self.generator.generate_workflow(self.one_time_workflow_1)
self.generator.generate_cycle(wflow)
self.generator.activate_workflow(wflow)
cycle_tasks = db.session.query(CycleTaskGroupObjectTask).join(
Cycle).join(Workflow).filter(Workflow.id == wflow.id).all()
with freeze_time("2015-6-9 13:00:00"):
today = dtm.datetime.now()
transitions = [
("InProgress", None, None),
("Finished", today, None),
("Declined", None, None),
("Finished", today, None),
("Verified", today, today),
("Finished", today, None),
]
# Iterate over possible transitions and check if dates got set correctly
for (status, expected_finished, expected_verified) in transitions:
cycle_task = cycle_tasks[0]
_, task = self.generator.modify_object(cycle_task, {"status": status})
self.assertEqual(task.finished_date, expected_finished)
self.assertEqual(task.verified_date, expected_verified)
def test_delete_calls(self):
_, workflow = self.generator.generate_workflow()
self.generator.generate_task_group(workflow)
_, task_group = self.generator.generate_task_group(workflow)
task_groups = db.session.query(TaskGroup).filter(
TaskGroup.workflow_id == workflow.id).all()
#.........这里部分代码省略.........
示例5: TestTaskOverdueNotificationsUsingAPI
# 需要导入模块: from integration.ggrc_workflows.generator import WorkflowsGenerator [as 别名]
# 或者: from integration.ggrc_workflows.generator.WorkflowsGenerator import modify_object [as 别名]
class TestTaskOverdueNotificationsUsingAPI(TestTaskOverdueNotifications):
"""Tests for overdue notifications when changing Tasks with an API."""
# pylint: disable=invalid-name
def setUp(self):
super(TestTaskOverdueNotificationsUsingAPI, self).setUp()
self.api = Api()
self.wf_generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
models.Notification.query.delete()
self._fix_notification_init()
self.random_objects = self.object_generator.generate_random_objects(2)
_, self.user = self.object_generator.generate_person(
user_role="Administrator")
self._create_test_cases()
@ddt.data(True, False)
@patch("ggrc.notifications.common.send_email")
def test_sending_overdue_notifications_for_tasks(self, is_vf_needed, _):
"""Overdue notifications should be sent for overdue tasks every day.
Even if an overdue notification has already been sent, it should still be
sent in every following daily digest f a task is still overdue.
"""
with freeze_time("2017-05-15 14:25:36"):
tmp = self.one_time_workflow.copy()
tmp['is_verification_needed'] = is_vf_needed
_, workflow = self.wf_generator.generate_workflow(tmp)
self.wf_generator.generate_cycle(workflow)
response, workflow = self.wf_generator.activate_workflow(workflow)
self.assert200(response)
tasks = workflow.cycles[0].cycle_task_group_object_tasks
task1_id = tasks[0].id
task2_id = tasks[1].id
user = models.Person.query.get(self.user.id)
with freeze_time("2017-05-14 08:09:10"):
_, notif_data = common.get_daily_notifications()
user_notifs = notif_data.get(user.email, {})
self.assertNotIn("task_overdue", user_notifs)
with freeze_time("2017-05-15 08:09:10"): # task 1 due date
_, notif_data = common.get_daily_notifications()
user_notifs = notif_data.get(user.email, {})
self.assertNotIn("task_overdue", user_notifs)
with freeze_time("2017-05-16 08:09:10"): # task 2 due date
_, notif_data = common.get_daily_notifications()
user_notifs = notif_data.get(user.email, {})
self.assertIn("task_overdue", user_notifs)
overdue_task_ids = sorted(user_notifs["task_overdue"].keys())
self.assertEqual(overdue_task_ids, [task1_id])
with freeze_time("2017-05-17 08:09:10"): # after both tasks' due dates
_, notif_data = common.get_daily_notifications()
user_notifs = notif_data.get(user.email, {})
self.assertIn("task_overdue", user_notifs)
overdue_task_ids = sorted(user_notifs["task_overdue"].keys())
self.assertEqual(overdue_task_ids, [task1_id, task2_id])
common.send_daily_digest_notifications()
# even after sending the overdue notifications, they are sent again the
# day after, too
with freeze_time("2017-05-18 08:09:10"):
_, notif_data = common.get_daily_notifications()
user_notifs = notif_data.get(user.email, {})
self.assertIn("task_overdue", user_notifs)
overdue_task_ids = sorted(user_notifs["task_overdue"].keys())
self.assertEqual(overdue_task_ids, [task1_id, task2_id])
@ddt.data(True, False)
@patch("ggrc.notifications.common.send_email")
def test_adjust_overdue_notifications_on_task_due_date_change(self,
is_vf_needed,
_):
"""Sending overdue notifications should adjust to task due date changes."""
with freeze_time("2017-05-15 14:25:36"):
tmp = self.one_time_workflow.copy()
tmp['is_verification_needed'] = is_vf_needed
_, workflow = self.wf_generator.generate_workflow(tmp)
self.wf_generator.generate_cycle(workflow)
response, workflow = self.wf_generator.activate_workflow(workflow)
self.assert200(response)
tasks = workflow.cycles[0].cycle_task_group_object_tasks
task1, task2 = tasks
self.wf_generator.modify_object(task2, {"end_date": date(2099, 12, 31)})
user = models.Person.query.get(self.user.id)
with freeze_time("2017-05-16 08:09:10"): # a day after task1 due date
#.........这里部分代码省略.........
示例6: TestWorkflowCycleStatePropagation
# 需要导入模块: from integration.ggrc_workflows.generator import WorkflowsGenerator [as 别名]
# 或者: from integration.ggrc_workflows.generator.WorkflowsGenerator import modify_object [as 别名]
class TestWorkflowCycleStatePropagation(TestCase):
"""Test case for cycle task to cycle task group status propagation"""
def setUp(self):
super(TestWorkflowCycleStatePropagation, self).setUp()
self.api = Api()
self.generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
self.weekly_wf = {
"title": "weekly thingy",
"description": "start this many a time",
"unit": "week",
"repeat_every": 1,
"task_groups": [{
"title": "weekly task group",
"task_group_tasks": [{
"title": "weekly task 1",
"start_date": dtm.date(2016, 6, 10),
"end_date": dtm.date(2016, 6, 13),
}, {
"title": "weekly task 1",
"start_date": dtm.date(2016, 6, 10),
"end_date": dtm.date(2016, 6, 13),
}]},
]
}
def test_weekly_state_transitions_assigned_inprogress(self):
"""Test that starting one cycle task changes cycle task group"""
with freeze_time("2016-6-10 13:00:00"): # Friday, 6/10/2016
_, wf = self.generator.generate_workflow(self.weekly_wf)
self.generator.activate_workflow(wf)
ctg = db.session.query(CycleTaskGroup).join(
Cycle).join(Workflow).filter(Workflow.id == wf.id).all()[0]
self.assertEqual(ctg.status, "Assigned")
cycle_tasks = db.session.query(CycleTaskGroupObjectTask).join(
Cycle).join(Workflow).filter(Workflow.id == wf.id).all()
first_ct, second_ct = cycle_tasks
for cycle_task in cycle_tasks:
self.assertEqual(cycle_task.status, "Assigned")
# Move one task to InProgress
_, first_ct = self.generator.modify_object(
first_ct, {"status": "InProgress"})
self.assertEqual(first_ct.status, "InProgress")
ctg = db.session.query(CycleTaskGroup).get(ctg.id)
self.assertEqual(ctg.status, "InProgress")
# Undo operation
_, first_ct = self.generator.modify_object(
first_ct, {"status": "Assigned"})
self.assertEqual(first_ct.status, "Assigned")
ctg = db.session.query(CycleTaskGroup).get(ctg.id)
self.assertEqual(ctg.status, "Assigned")
# Move both to in progress
for cycle_task in cycle_tasks:
self.generator.modify_object(
cycle_task, {"status": "InProgress"})
ctg = db.session.query(CycleTaskGroup).get(ctg.id)
self.assertEqual(ctg.status, "InProgress")
# Undo one cycle task
_, first_ct = self.generator.modify_object(
first_ct, {"status": "Assigned"})
second_ct = db.session.query(CycleTaskGroupObjectTask).get(second_ct.id)
ctg = db.session.query(CycleTaskGroup).get(ctg.id)
self.assertEqual(first_ct.status, "Assigned")
self.assertEqual(second_ct.status, "InProgress")
self.assertEqual(ctg.status, "InProgress")
# Undo second cycle task
_, second_ct = self.generator.modify_object(
second_ct, {"status": "Assigned"})
first_ct = db.session.query(CycleTaskGroupObjectTask).get(first_ct.id)
ctg = db.session.query(CycleTaskGroup).get(ctg.id)
self.assertEqual(first_ct.status, "Assigned")
self.assertEqual(second_ct.status, "Assigned")
self.assertEqual(ctg.status, "Assigned")
def test_weekly_state_transitions_inprogress_finished(self):
"""Test In Progress to Finished transitions"""
with freeze_time("2016-6-10 13:00:00"): # Friday, 6/10/2016
_, wf = self.generator.generate_workflow(self.weekly_wf)
self.generator.activate_workflow(wf)
ctg = db.session.query(CycleTaskGroup).join(
Cycle).join(Workflow).filter(Workflow.id == wf.id).all()[0]
#.........这里部分代码省略.........
示例7: TestCycleTaskStatusChange
# 需要导入模块: from integration.ggrc_workflows.generator import WorkflowsGenerator [as 别名]
# 或者: from integration.ggrc_workflows.generator.WorkflowsGenerator import modify_object [as 别名]
#.........这里部分代码省略.........
_, notif_data = common.get_daily_notifications()
self.assertEqual(notif_data, {})
with freeze_time("2015-05-03"):
cycle = Cycle.query.get(cycle.id)
task1 = CycleTaskGroupObjectTask.query.get(
cycle.cycle_task_group_object_tasks[0].id)
self.task_change_status(task1)
user = Person.query.get(self.user.id)
_, notif_data = common.get_daily_notifications()
self.assertNotIn(user.email, notif_data)
self.assertIn("all_tasks_completed", notif_data["[email protected]"])
@patch("ggrc.notifications.common.send_email")
def test_end_cycle(self, mock_mail):
"""
manaually ending a cycle should stop all notifications for that cycle
"""
with freeze_time("2015-05-01"):
_, workflow = self.wf_generator.generate_workflow(
self.one_time_workflow_1)
_, cycle = self.wf_generator.generate_cycle(workflow)
self.wf_generator.activate_workflow(workflow)
with freeze_time("2015-05-03"):
_, notif_data = common.get_daily_notifications()
cycle = Cycle.query.get(cycle.id)
user = Person.query.get(self.user.id)
self.assertIn(user.email, notif_data)
self.wf_generator.modify_object(cycle, data={"is_current": False})
cycle = Cycle.query.get(cycle.id)
self.assertFalse(cycle.is_current)
_, notif_data = common.get_daily_notifications()
self.assertNotIn(user.email, notif_data)
def create_test_cases(self):
def person_dict(person_id):
return {
"href": "/api/people/%d" % person_id,
"id": person_id,
"type": "Person"
}
self.one_time_workflow_1 = {
"title": "one time test workflow",
"notify_on_change": True,
"description": "some test workflow",
"owners": [person_dict(self.user.id)],
"task_groups": [{
"title": "single task group",
"contact": person_dict(self.user.id),
"task_group_tasks": [{
"title": "task 1",
"description": "single task in a wf",
"contact": person_dict(self.user.id),
"start_date": date(2015, 5, 1), # friday
"end_date": date(2015, 5, 5),
}],
}]
}