Skip to content

Commit

Permalink
Merge PR #1488 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
shopinvader-git-bot committed Dec 14, 2023
2 parents 2a6a66f + 85114e0 commit 444346b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions shopinvader_api_cart/routers/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import OrderedDict
from typing import Annotated

from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, Response

from odoo import _, api, models
from odoo.exceptions import MissingError
Expand Down Expand Up @@ -34,7 +34,7 @@ def get(
Return an empty dict if no cart was found
"""
cart = env["sale.order"]._find_open_cart(partner.id, uuid)
return Sale.from_sale_order(cart) if cart else None
return Sale.from_sale_order(cart) if cart else Response(status_code=204)


@cart_router.post("/sync", status_code=201)
Expand All @@ -49,7 +49,7 @@ def sync(
cart = env["shopinvader_api_cart.cart_router.helper"]._sync_cart(
partner, cart, uuid, data.transactions
)
return Sale.from_sale_order(cart) if cart else None
return Sale.from_sale_order(cart) if cart else Response(status_code=204)


@cart_router.post("/update")
Expand Down
12 changes: 8 additions & 4 deletions shopinvader_api_cart/tests/test_shopinvader_api_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def _create_unauthenticated_user_client(self):
def test_get_authenticated_no_cart_no_uuid(self) -> None:
with self._create_test_client(router=cart_router) as test_client:
response: Response = test_client.get("/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.json(), None)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

def test_get_authenticated_no_cart_no_uuid_no_rights(self) -> None:
with self._create_unauthenticated_user_client() as test_client, self.assertRaises(
Expand All @@ -88,8 +87,7 @@ def test_get_authenticated_no_cart_no_uuid_no_rights(self) -> None:
def test_get_authenticated_no_cart_uuid(self) -> None:
with self._create_test_client(router=cart_router) as test_client:
response: Response = test_client.get("/1234")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.json(), None)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

def test_get_authenticated_no_cart_uuid_no_rights(self) -> None:
with self._create_unauthenticated_user_client() as test_client, self.assertRaises(
Expand Down Expand Up @@ -219,6 +217,12 @@ def test_sync_authenticated_wrong_uuid_one_transactions_cart_exists(self) -> Non
self.assertEqual(so.id, response_json["id"])
self.assertFalse(so.applied_cart_api_transaction_uuids)

def test_sync_no_content_no_cart(self):
data = {"transactions": []}
with self._create_test_client(router=cart_router) as test_client:
response: Response = test_client.post("/sync", content=json.dumps(data))
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

def test_transaction_product_not_existing(self) -> None:
so = self.env["sale.order"]._create_empty_cart(
self.default_fastapi_authenticated_partner.id
Expand Down

0 comments on commit 444346b

Please sign in to comment.