Skip to content

Commit 205e0c8

Browse files
[MIG] auth_jwt_demo: Migration to 19.0
1 parent 48d97c8 commit 205e0c8

3 files changed

Lines changed: 95 additions & 1 deletion

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ exclude: |
1818
/build/|/dist/|
1919
# Ignore test files in addons
2020
/tests/samples/.*|
21+
^auth_jwt_demo/tests/spa.*|
2122
# You don't usually want a bot to modify your legal texts
2223
(LICENSE.*|COPYING.*)
2324
default_language_version:

auth_jwt_demo/__manifest__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
"name": "Auth JWT Test",
66
"summary": """
77
Test/demo module for auth_jwt.""",
8-
"version": "18.0.1.0.0",
8+
"version": "19.0.1.0.0",
99
"license": "LGPL-3",
1010
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
1111
"maintainers": ["sbidoul"],
1212
"website": "https://github.com/OCA/server-auth",
1313
"depends": ["auth_jwt"],
1414
"data": [],
1515
"demo": ["demo/auth_jwt_validator.xml"],
16+
"installable": True,
17+
"application": False,
1618
}

auth_jwt_demo/tests/test_auth_jwt_demo.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,59 @@
77
import jwt
88

99
from odoo import tests
10+
from odoo.tools import convert, file_path
11+
12+
13+
class TestAuthJwtDemo(tests.common.HttpCase):
14+
@classmethod
15+
def setUpClass(cls):
16+
super().setUpClass()
1017

1118

1219
@tests.tagged("post_install", "-at_install")
1320
class TestRegisterHook(tests.HttpCase):
21+
def setUp(self):
22+
super().setUp()
23+
demo_user = self.env.ref("base.user_demo", raise_if_not_found=False)
24+
if not demo_user:
25+
demo_user = self.env["res.users"].create(
26+
{
27+
"name": "Demo User",
28+
"login": "demo",
29+
"email": "demo@example.com",
30+
"group_ids": [(6, 0, [self.env.ref("base.group_user").id])],
31+
}
32+
)
33+
self.env["ir.model.data"].create(
34+
{
35+
"name": "user_demo",
36+
"module": "base",
37+
"model": "res.users",
38+
"res_id": demo_user.id,
39+
"noupdate": True,
40+
}
41+
)
42+
module_name = "auth_jwt_demo"
43+
xml_path_in_module = "demo/auth_jwt_validator.xml"
44+
try:
45+
full_path = file_path(f"{module_name}/{xml_path_in_module}")
46+
except FileNotFoundError:
47+
self.fail(f"No se pudo encontrar el fichero demo: {xml_path_in_module}")
48+
full_path = None
49+
if full_path:
50+
with open(full_path, "rb") as f:
51+
convert.load_xml(
52+
self.cr, module_name, f, idref={}, mode="demo", noupdate=False
53+
)
54+
self.registry.init_models(self.cr, ["ir.http"], {"module": "auth_jwt_demo"})
55+
try:
56+
self.registry["ir.http"]._register_auth_methods()
57+
except AttributeError:
58+
self.fail(
59+
"AttributeError: 'ir.http' don't have '_register_auth_methods'. "
60+
"This means the hook was not properly called."
61+
)
62+
1463
def test_auth_method_exists(self):
1564
validator = self.env["auth.jwt.validator"].search([("name", "=", "demo")])
1665
self.assertEqual(len(validator), 1)
@@ -19,6 +68,48 @@ def test_auth_method_exists(self):
1968

2069
@tests.tagged("post_install", "-at_install")
2170
class TestEndToEnd(tests.HttpCase):
71+
def setUp(self):
72+
super().setUp()
73+
demo_user = self.env.ref("base.user_demo", raise_if_not_found=False)
74+
if not demo_user:
75+
demo_user = self.env["res.users"].create(
76+
{
77+
"name": "Demo User",
78+
"login": "demo",
79+
"email": "demo@example.com",
80+
"group_ids": [(6, 0, [self.env.ref("base.group_user").id])],
81+
}
82+
)
83+
self.env["ir.model.data"].create(
84+
{
85+
"name": "user_demo",
86+
"module": "base",
87+
"model": "res.users",
88+
"res_id": demo_user.id,
89+
"noupdate": True,
90+
}
91+
)
92+
module_name = "auth_jwt_demo"
93+
xml_path_in_module = "demo/auth_jwt_validator.xml"
94+
try:
95+
full_path = file_path(f"{module_name}/{xml_path_in_module}")
96+
except FileNotFoundError:
97+
self.fail(f"No se pudo encontrar el fichero demo: {xml_path_in_module}")
98+
full_path = None
99+
if full_path:
100+
with open(full_path, "rb") as f:
101+
convert.load_xml(
102+
self.cr, module_name, f, idref={}, mode="demo", noupdate=False
103+
)
104+
self.registry.init_models(self.cr, ["ir.http"], {"module": "auth_jwt_demo"})
105+
try:
106+
self.registry["ir.http"]._register_auth_methods()
107+
except AttributeError:
108+
self.fail(
109+
"AttributeError: 'ir.http' don't have '_register_auth_methods'."
110+
" This means the hook was not properly called."
111+
)
112+
22113
def _get_token(self, aud=None, email=None):
23114
validator = self.env["auth.jwt.validator"].search([("name", "=", "demo")])
24115
payload = {

0 commit comments

Comments
 (0)