def should_add_steps(self): path = base.Path() step = base.Path() path.steps.append(step) self.session.add(path) self.session.commit() assert step.parent == path
def should_create_operations(self): path = base.Path() steps = [base.Path() for _ in range(3)] for step in steps: path.steps.append(step) step.create_flow = Mock() step.create_flow.return_value = base.Flow() flow = base.Flow(path=path) flow.responsible = base.Node(key='resp') calls = [] for step, operation in zip(steps, flow.op_creator()): assert operation == step.create_flow.return_value step.create_flow.assert_called_with() assert operation.responsible == flow.responsible assert operation.parent == flow
def should_execute(self): flow = base.Flow() flow.execute() path = base.Path() path.method = Mock() flow.path = path flow.execute() path.method.assert_called_with(flow)
def should_persist_basic_relationships(self): flow = base.Flow() role = base.Node() role.key = 'role' flow.path = base.Path(role=role) responsible = base.Node() responsible.key = 'responsible' flow.responsible = responsible op = base.Flow() flow.operations.append(op) self.session.add(flow) self.session.commit() assert op.parent == flow assert flow.path.role.key == 'role' assert flow.responsible.key == 'responsible'
def setup_method(self, method): super().setup_method(method) self.path = base.Path()
def should_allocate_origin_and_destination(self): flow = base.Flow() operations = [base.Flow() for _ in range(3)] for op in operations: op.allocate = Mock() flow.operations.append(op) with pytest.raises(base.FlowAllocateException): flow.allocate() flow.finished_on = Mock() flow.state = 'finished' destination = base.Node() origin = base.Node() from_node = base.Node() to_node = base.Node() path = base.Path() path.from_node = from_node path.to_node = to_node flow.path = path flow.origin = origin flow.destination = destination flow.allocate() for op in operations: op.allocate.assert_called_with() assert flow.origin == origin assert flow.destination == destination flow.origin = flow.destination = None flow.allocate() assert flow.origin == from_node assert flow.destination == to_node parent_path = base.Path() parent_path.from_node = from_node parent_path.to_node = to_node path.parent = parent_path path.from_node = path.to_node = None flow.origin = flow.destination = None flow.allocate() assert flow.origin == from_node assert flow.destination == to_node flow.state = 'cancelled' flow.destination = destination flow.origin = origin flow.allocate() assert flow.destination == origin for op in operations: assert op.state == 'cancelled'