Katkat

Implement a Python To-Do Task Manager Class with CRUD and Status Rules

CiscoSoftware Engineer · Onsite

Last updated

A Python coding question asking for a to-do task manager class with create, read, update, and delete operations, where every task has a status of new, pending, or resolved. It tests data modeling, input validation, status transition rules, error handling for missing tasks, and testable class design.

Write a Python class that manages a to-do list of tasks. It must support the four CRUD operations: create a task, read one task or a list of tasks, update a task, and delete a task. Every task has a status, which is one of new, pending or resolved.

Constraints and Clarifications

  • Assume in-memory storage is enough unless the interviewer asks for persistence.
  • Assume a newly created task starts with the status new.

Clarifying Questions

  • Which fields does a task have besides a title and a status: a description, a due date, timestamps, an owner?
  • Are any status changes forbidden, for example moving a resolved task back to new?
  • How are task IDs generated, and must an ID stay unused after its task is deleted?
  • Should an operation on a missing task raise an exception, or return a value such as None or False?
  • Is listing with a filter needed, for example all pending tasks?
  • Must the class be safe to use from several threads?

Hints

Hint 1

Model the status: Decide how to represent the three statuses so that a typo such as `"resloved"` can never end up stored on a task.

Hint 2

Decide the failure behavior first: Before writing the methods, decide what each one does when the task ID does not exist or the input is invalid, and apply that choice consistently.

Follow-up questions

  • How would you test this class with pytest, and which fixtures would you write?
  • How would you add persistence to SQLite or a file without changing the public interface?
  • How would you make the class safe to use from several threads?
  • How would you support undoing the last operation?