-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] shopinvader_api_signin_jwt: anonymous cart
- Loading branch information
Showing
8 changed files
with
56 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
This addon adds a web API to signin into the application and create a partner | ||
if the email in the jwt payload is unknown. | ||
If we had an anonymous partner, transfer his cart to the loggedin partner and delete it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* Manage anonymous cart (see https://github.com/shopinvader/odoo-shopinvader/issues/1428) | ||
* Use ``fastapi_auth_jwt.auth_jwt_authenticated_odoo_env`` dependency for the env (see https://github.com/OCA/rest-framework/issues/406) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
from odoo.addons.fastapi.tests.common import FastAPITransactionCase | ||
from odoo.addons.fastapi_auth_jwt.dependencies import auth_jwt_default_validator_name | ||
from odoo.addons.shopinvader_anonymous_partner.models.res_partner import COOKIE_NAME | ||
|
||
from ..routers import signin_router | ||
|
||
|
@@ -79,6 +80,37 @@ def test_signin(self): | |
res = client.post("/signin", headers={"Authorization": token}) | ||
self.assertEqual(res.status_code, 200) | ||
|
||
def test_signin_anonymous_cart(self): | ||
anonymous_partner = self.env["res.partner"].create( | ||
{"name": "Test anonymous", "anonymous_token": "1234", "active": False} | ||
) | ||
product = self.env["product.product"].create( | ||
{"name": "product", "uom_id": self.env.ref("uom.product_uom_unit").id} | ||
) | ||
self.env["sale.order"].create( | ||
{ | ||
"partner_id": anonymous_partner.id, | ||
"order_line": [ | ||
(0, 0, {"product_id": product.id, "product_uom_qty": 1}), | ||
], | ||
"typology": "cart", | ||
} | ||
) | ||
|
||
token = self._get_token() | ||
with self._create_test_client() as client: | ||
res = client.post( | ||
"/signin", | ||
headers={"Authorization": token}, | ||
cookies={COOKIE_NAME: "1234"}, | ||
) | ||
self.assertFalse(res.cookies.get(COOKIE_NAME)) | ||
self.assertFalse(anonymous_partner.exists()) | ||
partner = self.env["res.partner"].search([("email", "=", "[email protected]")]) | ||
cart = self.env["sale.order"].search([("partner_id", "=", partner.id)]) | ||
self.assertEqual(len(cart.order_line), 1) | ||
self.assertEqual(cart.order_line[0].product_id, product) | ||
|
||
def test_signout(self): | ||
self.validator.write({"cookie_enabled": True, "cookie_name": "test_cookie"}) | ||
token = self._get_token() | ||
|