Source code for odoo_xmlrpc_twisted.functions.test_odoo_xmlrpc_server
"""Test if the XML-RPC server connected to the Odoo systemis running and handling XML-RPC calls correctly."""fromxmlrpc.clientimportFault,ProtocolErrorimportosimportsys# as this program is in the folder "test",# import the module to test from the parent directorycurrent=os.path.dirname(os.path.realpath(__file__))parent_directory=os.path.dirname(current)sys.path.append(parent_directory)try:from.get_settings_odooimportget_settings_odooexceptImportError:fromget_settings_odooimportget_settings_odooresult=get_settings_odoo()db=result[0]username=result[2]password=result[3]models=result[4]common_endpoint=result[5]
[docs]deftest_server_is_running():""" Check if the XML-RPC server is running. """try:version=common_endpoint.version()return'server_version'inversionexcept(ConnectionRefusedError,ProtocolError):returnFalse
[docs]deftest_xmlrpc_login():""" Attempts to authenticate with the Odoo system using XML-RPC. """try:uid=common_endpoint.authenticate(db,username,password,{})returnisinstance(uid,int)except(Fault,ConnectionRefusedError,ProtocolError):returnFalse
[docs]deftest_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})returnisinstance(partner_ids,list)except(Fault,ConnectionRefusedError,ProtocolError):returnFalse
[docs]deftest_odoo_xmlrpc_server():""" Runs all tests and returns 'True' if they all pass, otherwise 'False'. """return"True"iftest_server_is_running()andtest_xmlrpc_login()andtest_xmlrpc_call()else"False"