Implementing More Features for the Shopping Cart
Introduction to the Shopping Cart Module
Welcome to your fourth unit for this course dedicated to practicing Test-Driven Development (TDD) utilizing Python and pytest. We're going to continue building our ShoppingCart system by integrating even more features into our class.
In this course, the emphasis is placed on hands-on practice, where you'll receive requirements through tests, one at a time. Your task is to write tests AND implement code that makes each test pass, simulating a real-world TDD environment.
Remember to use the core concepts of the Red-Green-Refactor cycle while completing these coding exercises. I'm still here to help! Just ask.
More Requirements for `ShoppingCart` Class
In this section, we'll extend our ShoppingCart class with more advanced operations that build upon our fundamental cart functionality. These additional requirements address error handling for item removal, discount application strategies, cart management capabilities, and quantity updates—providing a more complete e-commerce shopping experience. Through implementing these features using TDD methodology, you'll practice handling edge cases and business logic that mirror real-world shopping cart systems while continuing to follow the Red-Green-Refactor pattern for each new requirement.
6. Removing a Non-Existent Item
- Description: Removing an item that does not exist in the cart should raise an exception, indicating the item is not found.
- Details
- Support item removal through a
remove_item(item_id)method. - Ensure the method raises an appropriate error message if an item does not exist in the cart.
- Support item removal through a
- Examples: Attempting to remove an item with
item_id: '999'from the cart should raise an exception with the message'Item not found'.
7. Applying Percentage Discount
- Description: When a percentage discount is applied, the total price of the items in the cart should reflect this discount.
- Details
- Use the
apply_discount(percentage)method to apply a percentage discount to the total. - Ensure
get_total()returns the discounted price after applying the discount.
- Use the
- Examples: Applying a 10% discount to an item with a total price of
100should result in a new total of90.
