Simple shopping cart that lets you add items and display the state of the cart
Project description
Code style
This project makes use of black with default settings to format the code and flake8 as a linter.
Usage
from shopping_cart.shopping_cart import ShoppingCart
cart: ShoppingCart = ShoppingCart()
print(cart.add_to_cart("cornflakes", 1))
print(cart.add_to_cart("cornflakes", 1))
print(cart.add_to_cart("weetabix", 1))
print(cart.calculate_state())
API
add_to_cart(product_name, quantity)
Will add the product details to the cart.
Args:
product_name (str): the name of the product
quantity (int): how many of the product
Raises: Exception: Exception, when there is an error adding a product to the cart
Returns: dict: object containing the status_code and message
calculate_state()
Will display the current state of the shopping cart
Returns: str:
A string representing the state of the shopping cart.
This includes:
product_name: the name of the product
quantity: how many of the product
sub: sum of all the prices of the products
tax: the tax payable on the sub
total: the sum of the sub and tax
Requirements
- python >= 3.10
- poetry
- coverage
Testing
The project uses pytest to run its tests To run the tests, follow the steps below.
Open up a terminal in the project
- run
poetry install
this will install the dependencies for the project - run
poetry shell
to enter the virtual environment - run
poetry run pytest -vv
to run the tests
Coverage
Open up a terminal in the project
- run
coverage run -m pytest
run the test suite and get data - run
coverage report -m
to get a report of the results
Other
The .gitignore file was generated using gitignore.io https://www.toptal.com/developers/gitignore/#
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file shopping_cart_387dd67aa803-0.2.0.tar.gz
.
File metadata
- Download URL: shopping_cart_387dd67aa803-0.2.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.5 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98833d4d8bbcb8f9c835037c968fd4dd0ecd91f755e539c61848ff9b5566ccfe |
|
MD5 | 0a299cdbe76300ff305f9c464c048ad1 |
|
BLAKE2b-256 | c7da2385824c32b33edfbac52dfd941585a9af3d6ef0cfc6c463bbc8fe43bf7b |
File details
Details for the file shopping_cart_387dd67aa803-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: shopping_cart_387dd67aa803-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.5 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d53bc0c118b972a8204e82de9bf5547b3a0795bedcb4a806182351959f896b5 |
|
MD5 | aa87a8620baf5539bdb939f988c643e2 |
|
BLAKE2b-256 | 5662dabb21c903003d07169328b09e6d69b06f148e56bb204c7b13318d810c3b |