Skip to content

Commit

Permalink
Get the demo credentials following the https://demo.odoo.com/ redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
muflone committed Jun 25, 2023
1 parent fbbd734 commit a904431
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions tests/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
##

import os
import urllib.parse
import xmlrpc.client

import requests

from pyodoo.v12 import Model


Expand All @@ -44,11 +47,28 @@ def get_authentication_from_demo() -> dict[str, str]:
except (xmlrpc.client.Fault,
xmlrpc.client.ProtocolError):
# Sometimes the free public server start page is not available
# Use a specif instance (this may be very mutable)
info = {'host': 'https://demo6.odoo.com',
'database': 'demo_saas-163_d08cf84b6242_1687720660',
'user': 'admin',
'password': 'admin'}
info = {}
# Follow the redirects from https://demo.odoo.com/
request = requests.get('https://demo.odoo.com/')
if request.status_code == 200:
# Process all the previous redirects to get the credentials
for request in request.history:
parse_result = urllib.parse.urlparse(url=request.url)
if parse_result.query:
qs = urllib.parse.parse_qs(qs=parse_result.query)
if 'dbname' in qs:
info = {'host': f'{parse_result.scheme}://'
f'{parse_result.netloc}',
'database': qs['dbname'][0],
'user': qs['user'][0],
'password': qs['key'][0]}
break
if not info:
# Use a specific instance (this may be very mutable)
info = {'host': 'https://demo6.odoo.com',
'database': 'demo_saas-163_845e0736dbcc_1687729511',
'user': 'admin',
'password': 'admin'}
return info


Expand Down

0 comments on commit a904431

Please sign in to comment.