Skip to main content

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/#

Release files for shopping-cart-387dd67aa803 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shopping-cart-387dd67aa803 0.2.0
File Size Uploaded
shopping_cart_387dd67aa803-0.2.0.tar.gz 2.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shopping-cart-387dd67aa803 0.2.0
File Interpreter ABI Platform
shopping_cart_387dd67aa803-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.6 kB

Release files / shopping_cart_387dd67aa803-0.2.0.tar.gz

Download URL shopping_cart_387dd67aa803-0.2.0.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
98833d4d8bbcb8f9c835037c968fd4dd0ecd91f755e539c61848ff9b5566ccfe
BLAKE2b-256 checksum
How to use checksums
c7da2385824c32b33edfbac52dfd941585a9af3d6ef0cfc6c463bbc8fe43bf7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.5 Darwin/21.6.0

Release files / shopping_cart_387dd67aa803-0.2.0-py3-none-any.whl

Download URL shopping_cart_387dd67aa803-0.2.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d53bc0c118b972a8204e82de9bf5547b3a0795bedcb4a806182351959f896b5
BLAKE2b-256 checksum
How to use checksums
5662dabb21c903003d07169328b09e6d69b06f148e56bb204c7b13318d810c3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.5 Darwin/21.6.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page