def test_shouldJumpToASpecificState(self): authorized_permission = PermissionObjectFactory() state1 = RawState("state1") state2 = RawState("state2") state3 = RawState("state3") authorization_policies = [ AuthorizationPolicyBuilder().with_permission( authorized_permission).build(), ] flow = FlowBuilder("my_field", self.content_type) \ .with_transition(state1, state2, authorization_policies) \ .with_transition(state2, state3, authorization_policies) \ .build() workflow_object = flow.objects[0] assert_that(workflow_object.my_field, equal_to(flow.get_state(state1))) approvals = TransitionApproval.objects.filter( workflow_object=workflow_object) assert_that(approvals, has_approval(state1, state2, PENDING)) assert_that(approvals, has_approval(state2, state3, PENDING)) workflow_object.river.my_field.jump_to(flow.get_state(state3)) assert_that(workflow_object.my_field, equal_to(flow.get_state(state3))) approvals = TransitionApproval.objects.filter( workflow_object=workflow_object) assert_that(approvals, has_approval(state1, state2, JUMPED)) assert_that(approvals, has_approval(state2, state3, JUMPED))
def test_shouldNotCancelDescendantsThatCanBeTransitedInTheFuture(self): authorized_permission = PermissionObjectFactory() authorized_user = UserObjectFactory( user_permissions=[authorized_permission]) state1 = RawState("state_1") state2 = RawState("state_2") state3 = RawState("state_3") final_state = RawState("final_state") authorization_policies = [ AuthorizationPolicyBuilder().with_permission( authorized_permission).build(), ] flow = FlowBuilder("my_field", self.content_type) \ .with_transition(state1, state2, authorization_policies) \ .with_transition(state1, state3, authorization_policies) \ .with_transition(state2, state3, authorization_policies) \ .with_transition(state3, final_state, authorization_policies) \ .build() workflow_object = flow.objects[0] assert_that(workflow_object.my_field, equal_to(flow.get_state(state1))) workflow_object.river.my_field.approve( as_user=authorized_user, next_state=flow.get_state(state2)) assert_that(workflow_object.my_field, equal_to(flow.get_state(state2))) approvals = TransitionApproval.objects.filter( workflow=flow.workflow, workflow_object=workflow_object) assert_that(approvals, has_approval(state3, final_state, PENDING))
def test_shouldAssessIterationsCorrectly(self): authorized_permission1 = PermissionObjectFactory() authorized_permission2 = PermissionObjectFactory() state1 = RawState("state1") state2 = RawState("state2") state3 = RawState("state3") flow = FlowBuilder("my_field", self.content_type) \ .with_transition(state1, state2, [AuthorizationPolicyBuilder().with_permission(authorized_permission1).build()]) \ .with_transition(state2, state3, [ AuthorizationPolicyBuilder().with_permission(authorized_permission1).build(), AuthorizationPolicyBuilder().with_priority(1).with_permission(authorized_permission2).build(), ]) \ .build() workflow_object = flow.objects[0] approvals = TransitionApproval.objects.filter( workflow=flow.workflow, workflow_object=workflow_object) assert_that(approvals, has_length(3)) assert_that(approvals, has_approval(state1, state2, PENDING, iteration=0)) assert_that( approvals, has_approval(state2, state3, PENDING, iteration=1, permissions=[authorized_permission1])) assert_that( approvals, has_approval(state2, state3, PENDING, iteration=1, permissions=[authorized_permission2]))
def test_shouldAssessIterationsCorrectlyWhenCycled(self): authorized_permission = PermissionObjectFactory() authorized_user = UserObjectFactory( user_permissions=[authorized_permission]) cycle_state_1 = RawState("cycle_state_1") cycle_state_2 = RawState("cycle_state_2") cycle_state_3 = RawState("cycle_state_3") off_the_cycle_state = RawState("off_the_cycle_state") final_state = RawState("final_state") authorization_policies = [ AuthorizationPolicyBuilder().with_permission( authorized_permission).build(), ] flow = FlowBuilder("my_field", self.content_type) \ .with_transition(cycle_state_1, cycle_state_2, authorization_policies) \ .with_transition(cycle_state_2, cycle_state_3, authorization_policies) \ .with_transition(cycle_state_3, cycle_state_1, authorization_policies) \ .with_transition(cycle_state_3, off_the_cycle_state, authorization_policies) \ .with_transition(off_the_cycle_state, final_state, authorization_policies) \ .build() workflow_object = flow.objects[0] assert_that(workflow_object.my_field, equal_to(flow.get_state(cycle_state_1))) workflow_object.river.my_field.approve(as_user=authorized_user) assert_that(workflow_object.my_field, equal_to(flow.get_state(cycle_state_2))) workflow_object.river.my_field.approve(as_user=authorized_user) assert_that(workflow_object.my_field, equal_to(flow.get_state(cycle_state_3))) approvals = TransitionApproval.objects.filter( workflow=flow.workflow, workflow_object=workflow_object) assert_that(approvals, has_length(5)) workflow_object.river.my_field.approve( as_user=authorized_user, next_state=flow.get_state(cycle_state_1)) assert_that(workflow_object.my_field, equal_to(flow.get_state(cycle_state_1))) approvals = TransitionApproval.objects.filter( workflow=flow.workflow, workflow_object=workflow_object) assert_that(approvals, has_length(10)) assert_that( approvals, has_approval(cycle_state_1, cycle_state_2, APPROVED, iteration=0)) assert_that( approvals, has_approval(cycle_state_2, cycle_state_3, APPROVED, iteration=1)) assert_that( approvals, has_approval(cycle_state_3, cycle_state_1, APPROVED, iteration=2)) assert_that( approvals, has_approval(cycle_state_3, off_the_cycle_state, CANCELLED, iteration=2)) assert_that( approvals, has_approval(off_the_cycle_state, final_state, CANCELLED, iteration=3)) assert_that( approvals, has_approval(cycle_state_1, cycle_state_2, PENDING, iteration=3)) assert_that( approvals, has_approval(cycle_state_2, cycle_state_3, PENDING, iteration=4)) assert_that( approvals, has_approval(cycle_state_3, cycle_state_1, PENDING, iteration=5)) assert_that( approvals, has_approval(cycle_state_3, off_the_cycle_state, PENDING, iteration=5)) assert_that( approvals, has_approval(off_the_cycle_state, final_state, PENDING, iteration=6))
def test_shouldNotCancelDescendantsIfItIsPartOfPossibleFuture(self): authorized_permission = PermissionObjectFactory() authorized_user = UserObjectFactory( user_permissions=[authorized_permission]) first_state = RawState("first") diamond_left_state_1 = RawState("diamond-left-1") diamond_left_state_2 = RawState("diamond-left-2") diamond_right_state_1 = RawState("diamond-right-1") diamond_right_state_2 = RawState("diamond-right-2") diamond_join_state = RawState("diamond-join") final_state = RawState("final") authorization_policies = [ AuthorizationPolicyBuilder().with_permission( authorized_permission).build(), ] flow = FlowBuilder("my_field", self.content_type) \ .with_transition(first_state, diamond_left_state_1, authorization_policies) \ .with_transition(first_state, diamond_right_state_1, authorization_policies) \ .with_transition(diamond_left_state_1, diamond_left_state_2, authorization_policies) \ .with_transition(diamond_right_state_1, diamond_right_state_2, authorization_policies) \ .with_transition(diamond_left_state_2, diamond_join_state, authorization_policies) \ .with_transition(diamond_right_state_2, diamond_join_state, authorization_policies) \ .with_transition(diamond_join_state, final_state, authorization_policies) \ .build() workflow_object = flow.objects[0] assert_that(workflow_object.my_field, equal_to(flow.get_state(first_state))) workflow_object.river.my_field.approve( as_user=authorized_user, next_state=flow.get_state(diamond_left_state_1)) assert_that(workflow_object.my_field, equal_to(flow.get_state(diamond_left_state_1))) approvals = TransitionApproval.objects.filter( workflow=flow.workflow, workflow_object=workflow_object) assert_that(approvals, has_approval(first_state, diamond_left_state_1, APPROVED)) assert_that( approvals, has_approval(diamond_left_state_1, diamond_left_state_2, PENDING)) assert_that( approvals, has_approval(diamond_left_state_2, diamond_join_state, PENDING)) assert_that( approvals, has_approval(first_state, diamond_right_state_1, CANCELLED)) assert_that( approvals, has_approval(diamond_right_state_1, diamond_right_state_2, CANCELLED)) assert_that( approvals, has_approval(diamond_right_state_2, diamond_join_state, CANCELLED)) assert_that(approvals, has_approval(diamond_join_state, final_state, PENDING))