Source code for odoo_xmlrpc_twisted.functions.test_odoo_xmlrpc_server

"""
Test if the XML-RPC server connected to the Odoo system
is running and handling XML-RPC calls correctly.
"""

from xmlrpc.client import Fault, ProtocolError
import os
import sys


# as this program is in the folder "test",
# import the module to test from the parent directory
current = os.path.dirname(os.path.realpath(__file__))
parent_directory = os.path.dirname(current)
sys.path.append(parent_directory)

try:
    from .get_settings_odoo import get_settings_odoo
except ImportError:
    from get_settings_odoo import get_settings_odoo
result   = get_settings_odoo()

db              = result[0]
username        = result[2]
password        = result[3]
models          = result[4]
common_endpoint = result[5]


[docs] def test_server_is_running(): """ Check if the XML-RPC server is running. """ try: version = common_endpoint.version() return 'server_version' in version except (ConnectionRefusedError, ProtocolError): return False
[docs] def test_xmlrpc_login(): """ Attempts to authenticate with the Odoo system using XML-RPC. """ try: uid = common_endpoint.authenticate(db, username, password, {}) return isinstance(uid, int) except (Fault, ConnectionRefusedError, ProtocolError): return False
[docs] def test_xmlrpc_call(): """ Checks if the server processes XML-RPC requests correctly. """ try: uid = common_endpoint.authenticate(db, username, password, {}) partner_ids = models.execute_kw(db, uid, password, 'res.partner', 'search', [[['is_company', '=', True]]], {'limit': 5}) return isinstance(partner_ids, list) except (Fault, ConnectionRefusedError, ProtocolError): return False
[docs] def test_odoo_xmlrpc_server(): """ Runs all tests and returns 'True' if they all pass, otherwise 'False'. """ return "True" if test_server_is_running() and test_xmlrpc_login() and test_xmlrpc_call() else "False"