Skip to content

Commit

Permalink
TDD + BDD working + Swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
cisc0f committed Apr 27, 2024
1 parent da52b4e commit 95319ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions service/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def get(self, shopcart_id):

# items = ShopCartItem.find_by_shopcart_id(shopcart_id)
if not filtered_items:
return jsonify([]), status.HTTP_200_OK
return [], status.HTTP_200_OK

results = [item.serialize() for item in filtered_items]
app.logger.info("Returning %d items", len(results))
Expand All @@ -626,7 +626,7 @@ def get(self, shopcart_id):
######################################################################
# PATH: /shopcarts/{shopcart_id}/products/{product_id}
######################################################################
@api.route("/shopcarts/<int:shopcart_id>/products/<int:product_id>")
@api.route("/shopcarts/<int:shopcart_id>/products/<int:product_id>", strict_slashes=False)
@api.param("shopcart_id", "The Shopcart identifier")
@api.param("product_id", "The Product identifier")
class ProductResource(Resource):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from decimal import Decimal, ROUND_DOWN
from wsgi import app
from service.common import status
from service.models import db, ShopCart
from service.models import db, ShopCart, ShopCartItem
from service.models.shop_cart import ShopCartStatus
from .factories import ShopCartFactory, ShopCartItemFactory

Expand Down Expand Up @@ -50,6 +50,7 @@ def setUp(self):
"""Runs before each test"""
self.client = app.test_client()
db.session.query(ShopCart).delete() # clean up the last tests
db.session.query(ShopCartItem).delete() # clean up the last tests
db.session.commit()

def tearDown(self):
Expand Down Expand Up @@ -181,7 +182,7 @@ def test_update_shopcart(self):
"user_id"
], # Assuming user_id can be updated or is needed for identification
"name": "Updated Name",
"total_price": Decimal(new_shopcart["total_price"]) + Decimal('100'), # Example of updating the price
"total_price": new_shopcart["total_price"] + 100, # Example of updating the price
# Include updates to other fields here
"status": new_shopcart["status"],
}
Expand All @@ -195,9 +196,7 @@ def test_update_shopcart(self):

# Verify that all fields have been updated correctly
self.assertEqual(updated_shopcart["name"], update_payload["name"])
expected_price = update_payload["total_price"].quantize(Decimal('.001'), rounding=ROUND_DOWN)
actual_price = Decimal(updated_shopcart["total_price"]).quantize(Decimal('.001'), rounding=ROUND_DOWN)
self.assertEqual(actual_price, expected_price)
self.assertEqual(updated_shopcart["total_price"], float(update_payload["total_price"]))

def test_update_shop_cart_with_invalid_fields(self):
"""It should not update a shopcart with invalid fields and maintain required fields"""
Expand Down Expand Up @@ -775,6 +774,7 @@ def test_list_shopcart_item_with_no_shopcart(self):
def test_list_shopcart_item_with_no_item(self):
"""It should raise no items not found sign"""
shopcart = self._create_shopcarts(1)[0]
print(shopcart.id)
resp = self.client.get(
f"{BASE_URL}/{shopcart.id}/items",
content_type="application/json",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_shop_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_list_all_shop_carts(self):
def test_serialize_shop_cart(self):
"""It should serialize a Shop Cart"""
shop_cart = ShopCartFactory()
shop_cart_item = ShopCartItem()
shop_cart_item = ShopCartItemFactory()
shop_cart.items.append(shop_cart_item)
data = shop_cart.serialize()
self.assertNotEqual(data, None)
Expand Down

0 comments on commit 95319ed

Please sign in to comment.