From 6e1381ff005db821d883905497b6f3782337c570 Mon Sep 17 00:00:00 2001 From: mle Date: Wed, 17 Jan 2024 16:24:54 +0100 Subject: [PATCH] [IMP] shopinvader_api_cart: add GET /current , POST /current/sync and /current/update routes This is done to avoid problems when adding new routes, such as /payable, that would conflict with /{uuid}. --- shopinvader_api_cart/routers/cart.py | 3 ++ .../tests/test_shopinvader_api_cart.py | 51 ++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/shopinvader_api_cart/routers/cart.py b/shopinvader_api_cart/routers/cart.py index a233a21639..fce92b1fea 100644 --- a/shopinvader_api_cart/routers/cart.py +++ b/shopinvader_api_cart/routers/cart.py @@ -25,6 +25,7 @@ @cart_router.get("/") +@cart_router.get("/current") @cart_router.get("/{uuid}") def get( env: Annotated[api.Environment, Depends(authenticated_partner_env)], @@ -39,6 +40,7 @@ def get( @cart_router.post("/sync", status_code=201) +@cart_router.post("/current/sync", status_code=201) @cart_router.post("/{uuid}/sync", status_code=201) @cart_router.post("/sync/{uuid}", status_code=201, deprecated=True) def sync( @@ -55,6 +57,7 @@ def sync( @cart_router.post("/update") +@cart_router.post("/current/update") @cart_router.post("/{uuid}/update") @cart_router.post("/update/{uuid}", deprecated=True) def update( diff --git a/shopinvader_api_cart/tests/test_shopinvader_api_cart.py b/shopinvader_api_cart/tests/test_shopinvader_api_cart.py index 03a62722ab..cd480977a8 100644 --- a/shopinvader_api_cart/tests/test_shopinvader_api_cart.py +++ b/shopinvader_api_cart/tests/test_shopinvader_api_cart.py @@ -82,6 +82,18 @@ def test_get_authenticated_exists_cart_no_uuid(self) -> None: self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()["id"], so.id) + def test_get_current(self) -> None: + """ + Check that route GET /current is reachable + """ + so = self.env["sale.order"]._create_empty_cart( + self.default_fastapi_authenticated_partner.id + ) + with self._create_test_client(router=cart_router) as test_client: + response: Response = test_client.get("/current") + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.json()["id"], so.id) + def test_sync_authenticated_no_uuid_one_transactions_no_cart_exists(self) -> None: """ Provide no uuid but at least one transaction. Since no cart exists, @@ -101,6 +113,21 @@ def test_sync_authenticated_no_uuid_one_transactions_no_cart_exists(self) -> Non so = self.env["sale.order"].browse(response_json["id"]) self.assertEqual(self.trans_uuid_1, so.applied_cart_api_transaction_uuids) + def test_sync_current_cart(self) -> None: + """ + Check that the route /current/sync is reachable. + """ + data = { + "transactions": [ + {"uuid": self.trans_uuid_1, "product_id": self.product_1.id, "qty": 1} + ] + } + with self._create_test_client(router=cart_router) as test_client: + response: Response = test_client.post( + "/current/sync", content=json.dumps(data) + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + def test_sync_authenticated_no_rights(self) -> None: data = { "transactions": [ @@ -430,7 +457,29 @@ def test_update(self) -> None: self.assertEqual(so.partner_shipping_id, address) self.assertEqual(so.partner_invoice_id, partner) - def test_deprecated_route_update_uuidq(self) -> None: + def test_route_update_current(self) -> None: + """ + Check that the route /current/update is reachable. + """ + partner = self.default_fastapi_authenticated_partner + address = self.env["res.partner"].create( + { + "name": "Delivery", + "parent_id": partner.id, + "type": "delivery", + } + ) + self.env["sale.order"]._create_empty_cart( + self.default_fastapi_authenticated_partner.id + ) + data = {"delivery": {"address_id": address.id}} + with self._create_test_client(router=cart_router) as test_client: + response: Response = test_client.post( + "/current/update", content=json.dumps(data) + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_deprecated_route_update_uuid(self) -> None: """ Check that the deprecated /update/{uuid} route is still callable. """