From 95319edbef9f29283dacc554b97d193d7a43c487 Mon Sep 17 00:00:00 2001 From: cisc0f Date: Sat, 27 Apr 2024 11:36:57 -0400 Subject: [PATCH] TDD + BDD working + Swagger --- service/routes.py | 4 ++-- tests/test_routes.py | 10 +++++----- tests/test_shop_cart.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/service/routes.py b/service/routes.py index d7d77a9..f91f038 100644 --- a/service/routes.py +++ b/service/routes.py @@ -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)) @@ -626,7 +626,7 @@ def get(self, shopcart_id): ###################################################################### # PATH: /shopcarts/{shopcart_id}/products/{product_id} ###################################################################### -@api.route("/shopcarts//products/") +@api.route("/shopcarts//products/", strict_slashes=False) @api.param("shopcart_id", "The Shopcart identifier") @api.param("product_id", "The Product identifier") class ProductResource(Resource): diff --git a/tests/test_routes.py b/tests/test_routes.py index b74ed8d..e284400 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -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 @@ -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): @@ -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"], } @@ -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""" @@ -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", diff --git a/tests/test_shop_cart.py b/tests/test_shop_cart.py index 3d5ccc3..6f27eb1 100644 --- a/tests/test_shop_cart.py +++ b/tests/test_shop_cart.py @@ -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)