Skip to content

Commit a904431

Browse files
committed
Get the demo credentials following the https://demo.odoo.com/ redirects
1 parent fbbd734 commit a904431

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

tests/utility.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
##
2020

2121
import os
22+
import urllib.parse
2223
import xmlrpc.client
2324

25+
import requests
26+
2427
from pyodoo.v12 import Model
2528

2629

@@ -44,11 +47,28 @@ def get_authentication_from_demo() -> dict[str, str]:
4447
except (xmlrpc.client.Fault,
4548
xmlrpc.client.ProtocolError):
4649
# Sometimes the free public server start page is not available
47-
# Use a specif instance (this may be very mutable)
48-
info = {'host': 'https://demo6.odoo.com',
49-
'database': 'demo_saas-163_d08cf84b6242_1687720660',
50-
'user': 'admin',
51-
'password': 'admin'}
50+
info = {}
51+
# Follow the redirects from https://demo.odoo.com/
52+
request = requests.get('https://demo.odoo.com/')
53+
if request.status_code == 200:
54+
# Process all the previous redirects to get the credentials
55+
for request in request.history:
56+
parse_result = urllib.parse.urlparse(url=request.url)
57+
if parse_result.query:
58+
qs = urllib.parse.parse_qs(qs=parse_result.query)
59+
if 'dbname' in qs:
60+
info = {'host': f'{parse_result.scheme}://'
61+
f'{parse_result.netloc}',
62+
'database': qs['dbname'][0],
63+
'user': qs['user'][0],
64+
'password': qs['key'][0]}
65+
break
66+
if not info:
67+
# Use a specific instance (this may be very mutable)
68+
info = {'host': 'https://demo6.odoo.com',
69+
'database': 'demo_saas-163_845e0736dbcc_1687729511',
70+
'user': 'admin',
71+
'password': 'admin'}
5272
return info
5373

5474

0 commit comments

Comments
 (0)