Skip to main content

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())

Alt text

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

  1. run poetry install this will install the dependencies for the project
  2. run poetry shell to enter the virtual environment
  3. run poetry run pytest -vv to run the tests

Coverage

Open up a terminal in the project

  1. run coverage run -m pytest run the test suite and get data
  2. run coverage report -m to get a report of the results

Alt text

Other

The .gitignore file was generated using gitignore.io https://www.toptal.com/developers/gitignore/#

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shopping_cart_387dd67aa803-0.2.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file shopping_cart_387dd67aa803-0.2.0.tar.gz.

File metadata

File hashes

Hashes for shopping_cart_387dd67aa803-0.2.0.tar.gz
Algorithm Hash digest
SHA256 98833d4d8bbcb8f9c835037c968fd4dd0ecd91f755e539c61848ff9b5566ccfe
MD5 0a299cdbe76300ff305f9c464c048ad1
BLAKE2b-256 c7da2385824c32b33edfbac52dfd941585a9af3d6ef0cfc6c463bbc8fe43bf7b

See more details on using hashes here.

File details

Details for the file shopping_cart_387dd67aa803-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shopping_cart_387dd67aa803-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d53bc0c118b972a8204e82de9bf5547b3a0795bedcb4a806182351959f896b5
MD5 aa87a8620baf5539bdb939f988c643e2
BLAKE2b-256 5662dabb21c903003d07169328b09e6d69b06f148e56bb204c7b13318d810c3b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page