Skip to content

Commit eb82241

Browse files
sbidoulmaurochip
authored andcommitted
[MIG] auth_jwt_demo: capture log warning and assert expected warning
This is necessary to avoid warnings in test logs, and it improves coverage.
1 parent acbd2cf commit eb82241

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

auth_jwt_demo/tests/test_auth_jwt_demo.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2021 ACSONE SA/NV
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
33

4+
import logging
45
import time
56

67
import jwt
@@ -45,7 +46,16 @@ def test_whoami(self):
4546
# Try again in a user session, it will be rejected because auth_jwt
4647
# is not designed to work in user session.
4748
self.authenticate("demo", "demo")
48-
resp = self.url_open("/auth_jwt_demo/whoami", headers={"Authorization": token})
49+
with self.assertLogs("odoo.addons.auth_jwt.models.ir_http", "WARNING") as logs:
50+
resp = self.url_open(
51+
"/auth_jwt_demo/whoami", headers={"Authorization": token}
52+
)
53+
self.assertEqual(len(logs.records), 1)
54+
self.assertEqual(logs.records[0].levelno, logging.WARNING)
55+
self.assertIn(
56+
'A route with auth="jwt" must not be used within a user session',
57+
logs.output[0],
58+
)
4959
self.assertEqual(resp.status_code, 401)
5060

5161
def test_whoami_cookie(self):

0 commit comments

Comments
 (0)