def test_force_remove_trigger_function_with_dependent_triggers( self, connection): trigger_function_still_installed = True trigger_installed = False trigger.uninstall_trigger_function(connection, force=True) try: execute( connection, "SELECT pg_get_functiondef('public.psycopg2_pgevents_create_event'::regproc);" ) except ProgrammingError: trigger_function_still_installed = False statement = """ SELECT * FROM information_schema.triggers WHERE event_object_schema = 'settings' AND event_object_table = 'public'; """ result = execute(connection, statement) if not result: trigger_installed = False assert not trigger_function_still_installed assert not trigger_installed
def query_db(self): if self.conn is not None: self.conn.autocommit = True install_trigger_function(self.conn) install_trigger(self.conn, self.table_name) register_event_channel(self.conn) try: print("LIStening for event...") while True: row_ids = [] for evt in poll(self.conn): print('New Event: {}'.format(evt)) row_id = vars(evt)['row_id'] row_ids.append(row_id) if len(row_ids) > 0: self.row_id = max(row_ids) self.query_db_basic() self.transform_and_scale() if self.img is not None: self.send(text_data=self.img.decode('utf-8')) except KeyboardInterrupt: print('User exit via Ctrl-C; Shutting down...') unregister_event_channel(connection) uninstall_trigger(connection, table_name) uninstall_trigger_function(connection) print('Shutdown complete.')
def test_remove_trigger_function_extended(self, connection, rowid, rowidtype, triggerid, success): try: trigger.uninstall_trigger_function(connection, triggerid=triggerid) installed = trigger.trigger_function_installed( connection, triggerid) # the function should no longer be installed, so not success assert not installed == success except Exception as e: # assert that it should fail i.e. not success assert not success
def test_remove_trigger_function(self, connection): trigger_function_installed = True trigger.uninstall_trigger_function(connection) try: execute( connection, "SELECT pg_get_functiondef('public.psycopg2_pgevents_create_event'::regproc);" ) except ProgrammingError: trigger_function_installed = False assert not trigger_function_installed
def test_remove_trigger_function_with_dependent_triggers(self, connection): trigger_function_removal_failed = False trigger_function_still_installed = False try: trigger.uninstall_trigger_function(connection) except InternalError: trigger_function_removal_failed = True try: execute( connection, "SELECT pg_get_functiondef('public.psycopg2_pgevents_create_event'::regproc);" ) trigger_function_still_installed = True except: # noqa: E722 # Ignore error, its only use in this test is cause following # assertion to fail pass assert trigger_function_removal_failed assert trigger_function_still_installed