Ejemplo n.º 1
0
 def start():
     with session_scope() as session:
         new_stack = Stack()
         session.add(new_stack)
         session.commit()
         calc_id = new_stack.calc_id
         return calc_id
Ejemplo n.º 2
0
    def push(*, operand: float, id_: int) -> float:
        with session_scope() as session:
            stack = Stack.find_stack(id_, session)

            stack.operands.append(_Operand(operand=operand))
            session.commit()

            return operand
Ejemplo n.º 3
0
    def pop(*, id_: int) -> float:
        with session_scope() as session:
            stack = Stack.find_stack(id_, session)

            # This list of operands seems to be in the right order.   If it isn't then
            # the query to the DB can be modified to order by the Operand stack_idx (DateTime)
            # or the list can be sorted in Python.
            operand = stack.operands.pop()
            session.commit()

            return operand.operand
Ejemplo n.º 4
0
def test_cascading_delete_pass():
    # given
    x = 1

    # when
    calc_id = Stack.start()
    Stack.push(operand=x, id_=calc_id)
    Stack.delete(id_=calc_id)

    # then
    stacks = Stack.stacks()
    assert 0 == len(stacks)

    # Check to make sure that the operands are removed through cascading delete.
    with session_scope() as session:
        operands = session.query(_Operand).filter(
            _Operand.calc_id == calc_id).all()

        assert 0 == len(operands)
Ejemplo n.º 5
0
 def delete(*, id_: int):
     with session_scope() as session:
         stack = Stack.find_stack(id_, session)
         if stack:
             session.delete(stack)
         session.commit()
Ejemplo n.º 6
0
    def stack(*, id_: int) -> List[float]:
        with session_scope() as session:
            stack = Stack.find_stack(id_, session)

            return [o.operand for o in stack.operands]
Ejemplo n.º 7
0
 def stacks():
     with session_scope() as session:
         stacks = session.query(Stack).all()
         return stacks
Ejemplo n.º 8
0
    def peek(*, id_: int) -> float:
        with session_scope() as session:
            stack = Stack.find_stack(id_, session)

            # Same discussion about ordering.
            return stack.operands[-1].operand