cassiobotaro / do_zero_a_implantacao

:rocket: Do zero a implantação utilizando Python
https://cassiobotaro.dev/do_zero_a_implantacao/
Apache License 2.0
265 stars 52 forks source link

colocando limite na lista de tarefas e adicionando novo teste: #86

Open mabittar opened 2 years ago

mabittar commented 2 years ago
@app.post(
    "/tarefas", response_model=TarefaResponse, status_code=status.HTTP_201_CREATED
)
def criar(tarefa: TarefaBase):
    nova_tarefa = tarefa.dict()
    nova_tarefa.update({"id": uuid4()})
    response = TarefaResponse(**nova_tarefa)
    TAREFAS.append(nova_tarefa)
    if len(TAREFAS) > 10:
        TarefasList.pop()
    return response

##

    def test_quando_criar_deve_persistir_ate_10(self):
        tarefa = {"titulo": "titulo", "descricao": "descricao"}
        i = 0
        while i < 15:
            self.cliente.post("/tarefas", json=tarefa)
            i += 1

        numero_tarefas = len(TarefasList)
        assert numero_tarefas == 10
        TarefasList.clear()