本文整理汇总了Python中integration.ggrc_workflows.generator.WorkflowsGenerator类的典型用法代码示例。如果您正苦于以下问题:Python WorkflowsGenerator类的具体用法?Python WorkflowsGenerator怎么用?Python WorkflowsGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WorkflowsGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.client.get("/login")
self.generator = ObjectGenerator()
if TestComprehensiveSheets.first_run:
TestComprehensiveSheets.first_run = False
super(TestComprehensiveSheets, self).setUp()
self.create_custom_attributes()
self.import_file("comprehensive_sheet1.csv")
gen = WorkflowsGenerator()
wfs = all_models.Workflow.eager_query().filter_by(status='Draft').all()
for workflow in wfs:
_, cycle = gen.generate_cycle(workflow)
self.assertIsNotNone(cycle)
示例2: activate
def activate(self):
""" activate workflows just once after the class has been initialized
This should be in setUpClass method, but we can't access the server
context from there."""
gen = WorkflowsGenerator()
# generate cycle for the only one time wf
wf1 = Workflow.query.filter_by(status="Draft", slug="wf-1").first()
if wf1:
gen.generate_cycle(wf1)
workflows = Workflow.query.filter_by(status="Draft").all()
for wf in workflows:
gen.activate_workflow(wf)
示例3: setUp
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,
}
]},
]
}
示例4: setUp
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()
示例5: setUp
def setUp(self):
super(TestRecurringCycleNotifications, self).setUp()
self.api = Api()
self.generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
_, self.assignee = self.object_generator.generate_person(
user_role="Administrator")
self.create_test_cases()
示例6: setUp
def setUp(self):
super(TestRecurringWorkflowRevisions, self).setUp()
self.wf_generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
self.random_objects = self.object_generator.generate_random_objects()
_, self.person_1 = self.object_generator.generate_person(
user_role="Administrator")
_, self.person_2 = self.object_generator.generate_person(
user_role="Administrator")
def person_dict(person_id):
return {
"href": "/api/people/%d" % person_id,
"id": person_id,
"type": "Person"
}
self.monthly_workflow = {
"title": "test monthly wf notifications",
"notify_on_change": True,
"description": "some test workflow",
"owners": [person_dict(self.person_2.id)],
"unit": "month",
"repeat_every": 1,
"task_groups": [{
"title": "one time task group",
"contact": person_dict(self.person_1.id),
"task_group_tasks": [{
"title": "task 1",
"description": "some task",
"contact": person_dict(self.person_1.id),
}, {
"title": "task 2",
"description": "some task",
"contact": person_dict(self.person_1.id),
}],
"task_group_objects": self.random_objects[:2]
}, {
"title": "another one time task group",
"contact": person_dict(self.person_1.id),
"task_group_tasks": [{
"title": "task 1 in tg 2",
"description": "some task",
"contact": person_dict(self.person_1.id),
}, {
"title": "task 2 in tg 2",
"description": "some task",
"contact": person_dict(self.person_2.id),
}],
"task_group_objects": []
}]
}
示例7: setUp
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()
示例8: setUp
def setUp(self):
super(TestCycleTaskImportUpdate, self).setUp()
self.wf_generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
self.random_objects = self.object_generator.generate_random_objects(2)
_, self.person_1 = self.object_generator.generate_person(
user_role="Administrator")
self.ftime_active = "2016-07-01"
self.ftime_historical = "2014-05-01"
self._create_test_cases_data()
# It is needed because cycle-tasks are generated automatically with
# 'slug' based on auto_increment 'id' field.
# At start of each test we suppose that created cycle-task's 'slug'
# lie in range from 1 to 10.
db.session.execute('ALTER TABLE cycle_task_group_object_tasks '
'AUTO_INCREMENT = 1')
示例9: setUp
def setUp(self):
super(TestNotificationsForDeletedObjects, self).setUp()
self.api = Api()
self.wf_generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
Notification.query.delete()
self.random_objects = self.object_generator.generate_random_objects(2)
_, self.user = self.object_generator.generate_person(
user_role="Administrator")
self.create_test_cases()
def init_decorator(init):
def new_init(self, *args, **kwargs):
init(self, *args, **kwargs)
if hasattr(self, "created_at"):
self.created_at = datetime.now()
return new_init
Notification.__init__ = init_decorator(Notification.__init__)
示例10: setUp
def setUp(self):
super(TestOneTimeWorkflowNotification, self).setUp()
self.api = Api()
self.wf_generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
self.random_objects = self.object_generator.generate_random_objects()
self.random_people = self.object_generator.generate_random_people(
user_role="Administrator"
)
self.create_test_cases()
def init_decorator(init):
def new_init(self, *args, **kwargs):
init(self, *args, **kwargs)
if hasattr(self, "created_at"):
self.created_at = datetime.now()
return new_init
Notification.__init__ = init_decorator(Notification.__init__)
示例11: setUp
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),
}]},
]
}
示例12: TestNotificationsForDeletedObjects
class TestNotificationsForDeletedObjects(TestCase):
""" This class contains simple one time workflow tests that are not
in the gsheet test grid
"""
def setUp(self):
super(TestNotificationsForDeletedObjects, self).setUp()
self.api = Api()
self.wf_generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
Notification.query.delete()
self.random_objects = self.object_generator.generate_random_objects(2)
_, self.user = self.object_generator.generate_person(
user_role="Administrator")
self.create_test_cases()
def init_decorator(init):
def new_init(self, *args, **kwargs):
init(self, *args, **kwargs)
if hasattr(self, "created_at"):
self.created_at = datetime.now()
return new_init
Notification.__init__ = init_decorator(Notification.__init__)
@patch("ggrc.notifications.common.send_email")
def test_delete_activated_workflow(self, mock_mail):
with freeze_time("2015-02-01 13:39:20"):
_, workflow = self.wf_generator.generate_workflow(self.quarterly_wf_1)
response, workflow = self.wf_generator.activate_workflow(workflow)
self.assert200(response)
user = Person.query.get(self.user.id)
with freeze_time("2015-01-01 13:39:20"):
_, notif_data = common.get_daily_notifications()
self.assertNotIn(user.email, notif_data)
with freeze_time("2015-01-29 13:39:20"):
_, notif_data = common.get_daily_notifications()
self.assertIn(user.email, notif_data)
self.assertIn("cycle_starts_in", notif_data[user.email])
workflow = Workflow.query.get(workflow.id)
# After workflow deletion its notifications object_ids updated to 0
# value, this is the error, them should be deleted
# so this query checks existence of notifications with object_id
# equal to workflow id or 0 id before and
# after deletion workflow instance
exists_qs = db.session.query(
Notification.query.filter(
Notification.object_type == workflow.__class__.__name__,
Notification.object_id.in_((workflow.id, 0))
).exists()
)
self.assertTrue(exists_qs.one()[0])
response = self.wf_generator.api.delete(workflow)
self.assert200(response)
self.assertFalse(exists_qs.one()[0])
_, notif_data = common.get_daily_notifications()
user = Person.query.get(self.user.id)
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.quarterly_wf_1 = {
"title": "quarterly wf 1",
"notify_on_change": True,
"description": "",
"owners": [person_dict(self.user.id)],
"frequency": "quarterly",
"task_groups": [{
"title": "tg_1",
"contact": person_dict(self.user.id),
"task_group_tasks": [{
"contact": person_dict(self.user.id),
"description": factories.random_str(100),
"relative_start_day": 5,
"relative_start_month": 2,
"relative_end_day": 25,
"relative_end_month": 2,
},
],
},
]
}
示例13: TestOneTimeWfEndDateChange
class TestOneTimeWfEndDateChange(TestCase):
""" This class contains simple one time workflow tests that are not
in the gsheet test grid
"""
def setUp(self):
super(TestOneTimeWfEndDateChange, self).setUp()
self.api = Api()
self.wf_generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
Notification.query.delete()
self.random_objects = self.object_generator.generate_random_objects(2)
_, self.user = self.object_generator.generate_person(
user_role="Administrator")
self.create_test_cases()
def init_decorator(init):
def new_init(self, *args, **kwargs):
init(self, *args, **kwargs)
if hasattr(self, "created_at"):
self.created_at = datetime.now()
return new_init
Notification.__init__ = init_decorator(Notification.__init__)
@patch("ggrc.notifications.common.send_email")
def test_no_date_change(self, mock_mail):
def get_person(person_id):
return db.session.query(Person).filter(Person.id == person_id).one()
with freeze_time("2015-04-10 03:21:34"):
_, 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-04 03:21:34"): # one day before due date
_, notif_data = common.get_daily_notifications()
user = get_person(self.user.id)
self.assertIn("due_in", notif_data[user.email])
self.assertEqual(len(notif_data[user.email]["due_in"]), 2)
with freeze_time("2015-05-04 03:21:34"): # one day before due date
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, 3)
with freeze_time("2015-05-05 03:21:34"): # due date
_, notif_data = common.get_daily_notifications()
self.assertIn("due_today", notif_data[user.email])
self.assertEqual(len(notif_data[user.email]["due_today"]), 2)
@patch("ggrc.notifications.common.send_email")
def test_move_end_date_to_future(self, mock_mail):
"""
test moving the end date to the future, befor due_in and due_today
notifications have been sent
"""
def get_person(person_id):
return db.session.query(Person).filter(Person.id == person_id).one()
with freeze_time("2015-04-10 03:21:34"):
_, 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"):
#.........这里部分代码省略.........
示例14: TestOneTimeWorkflowNotification
class TestOneTimeWorkflowNotification(TestCase):
""" This class contains simple one time workflow tests that are not
in the gsheet test grid
"""
def setUp(self):
super(TestOneTimeWorkflowNotification, self).setUp()
self.api = Api()
self.wf_generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
self.random_objects = self.object_generator.generate_random_objects()
self.random_people = self.object_generator.generate_random_people(
user_role="Administrator"
)
self.create_test_cases()
def init_decorator(init):
def new_init(self, *args, **kwargs):
init(self, *args, **kwargs)
if hasattr(self, "created_at"):
self.created_at = datetime.now()
return new_init
Notification.__init__ = init_decorator(Notification.__init__)
def test_one_time_wf_activate(self):
def get_person(person_id):
return db.session.query(Person).filter(Person.id == person_id).one()
with freeze_time("2015-04-10"):
_, wf = self.wf_generator.generate_workflow(self.one_time_workflow_1)
_, cycle = self.wf_generator.generate_cycle(wf)
self.wf_generator.activate_workflow(wf)
person_2 = get_person(self.random_people[2].id)
with freeze_time("2015-04-11"):
_, notif_data = common.get_daily_notifications()
self.assertIn(person_2.email, notif_data)
self.assertIn("cycle_started", notif_data[person_2.email])
self.assertIn(cycle.id, notif_data[person_2.email]["cycle_started"])
self.assertIn("my_tasks",
notif_data[person_2.email]["cycle_data"][cycle.id])
person_1 = get_person(self.random_people[0].id)
with freeze_time("2015-05-03"): # two days befor due date
_, notif_data = common.get_daily_notifications()
self.assertIn(person_1.email, notif_data)
self.assertNotIn("due_in", notif_data[person_1.email])
self.assertNotIn("due_today", notif_data[person_1.email])
with freeze_time("2015-05-04"): # one day befor due date
_, notif_data = common.get_daily_notifications()
self.assertEqual(len(notif_data[person_1.email]["due_in"]), 1)
with freeze_time("2015-05-05"): # due date
_, notif_data = common.get_daily_notifications()
self.assertEqual(len(notif_data[person_1.email]["due_today"]), 1)
@patch("ggrc.notifications.common.send_email")
def test_one_time_wf_activate_single_person(self, mock_mail):
with freeze_time("2015-04-10"):
user = "[email protected]"
_, wf = self.wf_generator.generate_workflow(
self.one_time_workflow_single_person)
_, cycle = self.wf_generator.generate_cycle(wf)
self.wf_generator.activate_workflow(wf)
with freeze_time("2015-04-11"):
_, notif_data = common.get_daily_notifications()
self.assertIn("cycle_started", notif_data[user])
self.assertIn(cycle.id, notif_data[user]["cycle_started"])
self.assertIn("my_tasks", notif_data[user]["cycle_data"][cycle.id])
self.assertIn("cycle_tasks", notif_data[user]["cycle_data"][cycle.id])
self.assertIn(
"my_task_groups", notif_data[user]["cycle_data"][cycle.id])
self.assertIn("cycle_url", notif_data[user]["cycle_started"][cycle.id])
cycle = Cycle.query.get(cycle.id)
cycle_data = notif_data[user]["cycle_data"][cycle.id]
for task in cycle.cycle_task_group_object_tasks:
self.assertIn(task.id, cycle_data["my_tasks"])
self.assertIn(task.id, cycle_data["cycle_tasks"])
self.assertIn("title", cycle_data["my_tasks"][task.id])
self.assertIn("title", cycle_data["cycle_tasks"][task.id])
self.assertIn("cycle_task_url", cycle_data["cycle_tasks"][task.id])
with freeze_time("2015-05-03"): # two days before due date
_, notif_data = common.get_daily_notifications()
self.assertIn(user, notif_data)
self.assertNotIn("due_in", notif_data[user])
self.assertNotIn("due_today", notif_data[user])
with freeze_time("2015-05-04"): # one day before due date
_, notif_data = common.get_daily_notifications()
#.........这里部分代码省略.........
示例15: TestWorkflowCycleStatePropagantion
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)
#.........这里部分代码省略.........