-
Notifications
You must be signed in to change notification settings - Fork 106
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: Call promote directly at signin
- Loading branch information
1 parent
0c7a3f1
commit eb422e2
Showing
5 changed files
with
52 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
This addon adds a web API to signin into the application and create a partner | ||
if the email in the jwt payload is unknown. | ||
|
||
This addon supports the "anonymous partner" feature, which allows to create | ||
carts for user that are not loggedin. | ||
When you login from an anonymous partner, your cart is transfered to your real | ||
partner, and your anonymous partner is deleted. |
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,38 @@ 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} | ||
) | ||
anonymous_cart = 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()) | ||
self.assertFalse(anonymous_cart.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() | ||
|