Best Python code snippet using autotest_python
properties.py
Source:properties.py
1##########################################################################2#3# pgAdmin 4 - PostgreSQL Tools4#5# Copyright (C) 2013 - 2021, The pgAdmin Development Team6# This software is released under the PostgreSQL Licence7#8##########################################################################9from gettext import gettext10from os import path11from pgadmin.browser.server_groups.servers.databases.external_tables import \12 map_execution_location13from pgadmin.utils.ajax import internal_server_error14class PropertiesException(Exception):15 def __init__(self, response_object, *args):16 super(PropertiesException, self).__init__(*args)17 self.response_object = response_object18class PropertiesTableNotFoundException(PropertiesException):19 def __init__(self, *args):20 super(PropertiesException, self).__init__(None, *args)21class Properties:22 def __init__(self, render_template, db_connection, sql_template_path):23 self.render_template = render_template24 self.db_connection = db_connection25 self.sql_template_path = sql_template_path26 def retrieve(self, table_oid):27 table_information_sql = self.render_template(28 template_name_or_list=path.join(self.sql_template_path,29 'get_table_information.sql'),30 table_oid=table_oid31 )32 (status, table_information_results) = \33 self.db_connection.execute_2darray(table_information_sql)34 if not status:35 raise PropertiesException(36 internal_server_error(table_information_results))37 if len(table_information_results['rows']) != 1:38 raise PropertiesTableNotFoundException()39 table_information_result = table_information_results['rows'][0]40 execute_on = map_execution_location(41 table_information_result['execlocation'])42 execute_on_text = self.translate_execute_on_text(execute_on)43 response = dict(44 name=table_information_result['name'],45 type=gettext('readable') if not table_information_result[46 'writable'] else gettext('writable'),47 format_type=table_information_result['pg_encoding_to_char'],48 format_options=table_information_result['fmtopts'],49 external_options=table_information_result['options'],50 command=table_information_result['command'],51 execute_on=execute_on_text,52 )53 return response54 @staticmethod55 def translate_execute_on_text(execute_on):56 if execute_on['type'] == 'host':57 return gettext('host {}').format(execute_on['value'])58 elif execute_on['type'] == 'per_host':59 return gettext('per host')60 elif execute_on['type'] == 'master_only':61 return gettext('master segment')62 elif execute_on['type'] == 'all_segments':63 return gettext('all segments')64 elif execute_on['type'] == 'segment':65 return gettext('{} segment').format(execute_on['value'])66 elif execute_on['type'] == 'segments':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!