Source code for odoo_xmlrpc_twisted.support.support_get_label
"""Supporting program to test the module :func:`odoo_xmlrpc_twisted.functions.get_label`."""importsysimportosimportioimportbase64fromPILimportImage# Add functions directory to path for importing custom modulessys.path.append(os.path.join(os.path.dirname(__file__),'..','functions'))fromget_labelimportget_label
[docs]defsupport_get_label(custom_partner_id,custom_image_name):""" Function to test the module "get_label" A picture stored in the current directory will be captured to a stream and will be handled over to the function "get_label" from that module. Result is the translated text. """# for the capturing of the image to a BytesIO streamstream=io.BytesIO()# Construct path to test directory where the image is locatedrepo_root=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))test_dir=os.path.join(repo_root,'test')image_path=os.path.join(test_dir,custom_image_name)image=Image.open(image_path)image.save(stream,format="JPEG")# convert PIL image to base64 stringimg_str=base64.b64encode(stream.getvalue())custom_datas=img_str.decode('ascii')# call the function get_label to get the name and other information from the picturecustom_label=get_label(custom_partner_id,custom_datas)custom_name=custom_label[0]custom_desc=custom_label[1]return(custom_name,custom_desc)