def _create_cycle_structure(self): """Create cycle structure. It will create workflow, cycle, group and 3 tasks in that group. Retruns tuple: workflow, cycle, group and list of tasks. """ wf_slug = "WF-SLUG-{}".format( factories.random_str(length=6, chars=string.ascii_letters)) with factories.single_commit(): workflow = wf_factories.WorkflowFactory(slug=wf_slug) task_group = wf_factories.TaskGroupFactory(workflow=workflow) for ind in xrange(3): wf_factories.TaskGroupTaskFactory( task_group=task_group, title='task{}'.format(ind), start_date=datetime.datetime.now(), end_date=datetime.datetime.now() + datetime.timedelta(7)) data = workflow_api.get_cycle_post_dict(workflow) self.api.post(all_models.Cycle, data) workflow = all_models.Workflow.query.filter_by(slug=wf_slug).one() cycle = all_models.Cycle.query.filter_by(workflow_id=workflow.id).one() group = all_models.CycleTaskGroup.query.filter_by( cycle_id=cycle.id).one() tasks = all_models.CycleTaskGroupObjectTask.query.filter_by( cycle_id=cycle.id).all() return workflow, cycle, group, tasks
def setUp(self): """Set up.""" super(TestWfNotifsGenerator, self).setUp() self.api = Api() self.wf_generator = WorkflowsGenerator() self.object_generator = ObjectGenerator() Notification.query.delete() with freeze_time("2015-05-01 14:29:00"): wf_slug = "wf1" with factories.single_commit(): wf = wf_factories.WorkflowFactory(slug=wf_slug, is_verification_needed=True) task_group = wf_factories.TaskGroupFactory(workflow=wf) wf_factories.TaskGroupTaskFactory(task_group=task_group, title='task1', start_date=datetime.now(), end_date=datetime.now() + timedelta(7)) data = workflow_api.get_cycle_post_dict(wf) self.api.post(all_models.Cycle, data) wf = all_models.Workflow.query.filter_by(slug=wf_slug).one() self.cycle = all_models.Cycle.query.filter_by( workflow_id=wf.id).one() self.ctask = all_models.CycleTaskGroupObjectTask.query.filter_by( cycle_id=self.cycle.id).first()
def _create_cycle_structure(self): """Create cycle structure. It will create workflow, cycle, group and 3 tasks in that group. Retruns tuple: workflow, cycle, group and list of tasks. """ wf_slug = "WF-SLUG-{}".format(factories.random_str( length=6, chars=string.ascii_letters)) with factories.single_commit(): workflow = wf_factories.WorkflowFactory(slug=wf_slug) task_group = wf_factories.TaskGroupFactory(workflow=workflow) for ind in xrange(3): wf_factories.TaskGroupTaskFactory( task_group=task_group, title='task{}'.format(ind), start_date=datetime.datetime.now(), end_date=datetime.datetime.now() + datetime.timedelta(7) ) data = workflow_api.get_cycle_post_dict(workflow) self.api.post(all_models.Cycle, data) workflow = all_models.Workflow.query.filter_by(slug=wf_slug).one() cycle = all_models.Cycle.query.filter_by(workflow_id=workflow.id).one() group = all_models.CycleTaskGroup.query.filter_by(cycle_id=cycle.id).one() tasks = all_models.CycleTaskGroupObjectTask.query.filter_by( cycle_id=cycle.id).all() return workflow, cycle, group, tasks
def setUp(self): """Set up.""" super(TestWfNotifsGenerator, self).setUp() self.api = Api() self.wf_generator = WorkflowsGenerator() self.object_generator = ObjectGenerator() Notification.query.delete() with freeze_time("2015-05-01 14:29:00"): wf_slug = "wf1" with factories.single_commit(): wf = wf_factories.WorkflowFactory(slug=wf_slug) task_group = wf_factories.TaskGroupFactory(workflow=wf) wf_factories.TaskGroupTaskFactory( task_group=task_group, title='task1', start_date=datetime.now(), end_date=datetime.now() + timedelta(7) ) data = workflow_api.get_cycle_post_dict(wf) self.api.post(all_models.Cycle, data) wf = all_models.Workflow.query.filter_by(slug=wf_slug).one() self.cycle = all_models.Cycle.query.filter_by(workflow_id=wf.id).one() self.ctask = all_models.CycleTaskGroupObjectTask.query.filter_by( cycle_id=self.cycle.id).first()
def test_post_cycle_g_role_admin(self, g_rname): """Activate Workflow/POST Cycle logged in as {} & WF Admin.""" with factories.single_commit(): workflow = self.setup_helper.setup_workflow((g_rname, )) task_group = wf_factories.TaskGroupFactory(workflow=workflow) wf_factories.TaskGroupTaskFactory(task_group=task_group) g_person = self.setup_helper.get_person(g_rname, ac_roles.workflow.ADMIN_NAME) self.api_helper.set_user(g_person) workflow = all_models.Workflow.query.one() data = workflow_api.get_cycle_post_dict(workflow) response = self.api_helper.post(all_models.Cycle, data) self.assertEqual(response.status_code, 201)
def test_post_cycle_g_role_admin(self, g_rname): """Activate Workflow/POST Cycle logged in as {} & WF Admin.""" with factories.single_commit(): workflow = self.setup_helper.setup_workflow((g_rname,)) task_group = wf_factories.TaskGroupFactory(workflow=workflow) wf_factories.TaskGroupTaskFactory(task_group=task_group) g_person = self.setup_helper.get_person(g_rname, ac_roles.workflow.ADMIN_NAME) self.api_helper.set_user(g_person) workflow = all_models.Workflow.query.one() data = workflow_api.get_cycle_post_dict(workflow) response = self.api_helper.post(all_models.Cycle, data) self.assertEqual(response.status_code, 201)
def test_create_with_mapped_object(self, model_name): """Test cycle creation with mapped {0}.""" with factories.single_commit(): mapped_object = factories.get_model_factory(model_name)() task_group = wf_factories.TaskGroupFactory() wf_factories.TaskGroupTaskFactory(task_group=task_group) wf_factories.TaskGroupObjectFactory(task_group=task_group, object=mapped_object) mapped_object_id = mapped_object.id data = workflow_api.get_cycle_post_dict(task_group.workflow) response = self.api_helper.post(all_models.Cycle, data) self.assertEquals(response.status_code, 201) cycle_id = response.json.get("cycle", {}).get("id") cycle = all_models.Cycle.query.filter_by(id=cycle_id).first() obj = cycle.cycle_task_groups[0].task_group.task_group_objects[0].object self.assertEquals(obj.id, mapped_object_id)
def test_create_with_mapped_object(self, model_name): """Test cycle creation with mapped {0}.""" with factories.single_commit(): mapped_object = factories.get_model_factory(model_name)() task_group = wf_factories.TaskGroupFactory() wf_factories.TaskGroupTaskFactory(task_group=task_group) wf_factories.TaskGroupObjectFactory(task_group=task_group, object=mapped_object) mapped_object_id = mapped_object.id data = workflow_api.get_cycle_post_dict(task_group.workflow) response = self.api_helper.post(all_models.Cycle, data) self.assertEquals(response.status_code, 201) cycle_id = response.json.get("cycle", {}).get("id") cycle = all_models.Cycle.query.filter_by(id=cycle_id).first() obj = cycle.cycle_task_groups[0].task_group.task_group_objects[ 0].object self.assertEquals(obj.id, mapped_object_id)
def test_create_with_mapped_object(self, model_name): """Test cycle creation with mapped {0}.""" with factories.single_commit(): mapped_object = factories.get_model_factory(model_name)() task_group = wf_factories.TaskGroupFactory() wf_factories.TaskGroupTaskFactory(task_group=task_group) factories.RelationshipFactory(source=task_group, destination=mapped_object) mapped_object_id = mapped_object.id data = workflow_api.get_cycle_post_dict(task_group.workflow) response = self.api_helper.post(all_models.Cycle, data) self.assertEquals(response.status_code, 201) cycle_id = response.json.get("cycle", {}).get("id") cycle = all_models.Cycle.query.filter_by(id=cycle_id).first() mapped_objs = filter( lambda obj: obj.__class__.__name__ == model_name, cycle.cycle_task_groups[0].task_group.related_objects()) obj_id = mapped_objs.pop().id self.assertEquals(obj_id, mapped_object_id)
def test_create_with_mapped_object(self, model_name): """Test cycle creation with mapped {0}.""" with factories.single_commit(): mapped_object = factories.get_model_factory(model_name)() task_group = wf_factories.TaskGroupFactory() wf_factories.TaskGroupTaskFactory(task_group=task_group) factories.RelationshipFactory(source=task_group, destination=mapped_object) mapped_object_id = mapped_object.id data = workflow_api.get_cycle_post_dict(task_group.workflow) response = self.api_helper.post(all_models.Cycle, data) self.assertEquals(response.status_code, 201) cycle_id = response.json.get("cycle", {}).get("id") cycle = all_models.Cycle.query.filter_by(id=cycle_id).first() mapped_objs = filter( lambda obj: obj.__class__.__name__ == model_name, cycle.cycle_task_groups[0].task_group.related_objects() ) obj_id = mapped_objs.pop().id self.assertEquals(obj_id, mapped_object_id)