77import jwt
88
99from 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" )
1320class 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" )
2170class 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