Finishing the Shopping Cart
Introduction to the Shopping Cart Module
Welcome to your fifth and final unit for this course, dedicated to practicing Test-Driven Development (TDD) utilizing Python and pytest. We're going to finish building our ShoppingCart system by adding even more features to our class.
In this course, 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. Previously, I wrote the tests for you; this time, it's all up to you!
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.
Final Requirements for `ShoppingCart` Class
In this final section, we'll complete our ShoppingCart implementation with advanced features that address real-world shopping scenarios. These requirements focus on quantity management with enforced limits, item retrieval capabilities, discount code application with validation, and intelligent handling of duplicate items. Each feature builds upon our existing cart functionality to create a comprehensive e-commerce solution that enforces business rules while maintaining a positive user experience. As you implement these final requirements using Test-Driven Development, you'll gain valuable experience writing tests that validate both expected behavior and proper error handling—skills that transfer directly to professional software development.
11. Quantity Limit for a Single Item
- Description: The cart should enforce a maximum quantity limit of 10 for a single type of item, preventing more than the allowed amount from being added.
- Details
- Utilize the
add_item(item, quantity)method to add items to the cart. - Ensure an exception is raised when adding a quantity that exceeds a limit of
10for a single item. - The exception message should clearly state, "Maximum quantity exceeded" when the limit is breached.
- Utilize the
- Examples: Attempting to add
11units of{'id': '1', 'name': 'Book', 'price': 10}should raise an exception indicating "Maximum quantity exceeded."
12. Retrieving Item Details by ID
