Create a FastAPI PUT endpoint at /todos/todo_id. It should accept a todo_id as a path parameter and a TodoItem in the request body. Find the existing todo with that ID in the todo_db list, update it with the new data, and return the updated item. If no todo with that ID exists, return a 404 error with HTTPException.


Create a FastAPI DELETE endpoint at /todos/todo_id. It should find the todo item with the matching ID and remove it from the todo_db list. If the item is found and deleted successfully, return a success message like "message": "Todo deleted successfully". If no item with that ID exists, return a 404 error.


"id": 1, "title": "Test the API", "completed": false

Import TestClient from fastapi.testclient and import my FastAPI app from main.py

Create a TestClient instance using my FastAPI app.

Create a pytest function named test_read_root that uses the client to make a GET request to the '/' endpoint. It should assert that the status code is 200 and the JSON response matches the expected welcome message.

Create a pytest function named test_create_todo that tests the POST /todos endpoint. It should send a JSON payload with a new todo item containing an id, title, and completed status. Assert that the status code is 200 and that the response JSON contains the same data that was sent.



Create a test function named test_read_all_todos that makes a GET request to /todos and asserts that the response status is 200 and that the response contains a JSON list

Create a test function named test_read_single_todo that first creates a todo using POST /todos, then uses the returned ID to make a GET request to /todos/{id}. Assert that both operations return status 200 and that the retrieved todo matches the created todo.

Create a test function named test_update_todo that creates a todo, then sends a PUT request to /todos/{id} with updated data. Assert that the response shows the changes and that subsequent GET requests return the updated version.

Create a test function named test_delete_todo that creates a todo, deletes it using DELETE /todos/{id}, and then verifies the deletion by attempting to retrieve the deleted todo and expecting a 404 status code.