def test_invalid_inckey(self, mock_connect): tables = [{'value': 'public.table1'}] inst = Postgres(self.source, OPTIONS) inst.tables = tables mock_connector = mock.Mock() mock_connector.cursor.execute.side_effect = \ psycopg2.errors.UndefinedColumn('column does not exist') inst.connector = mock_connector with self.assertRaises(PostgresInckeyError): inst.read()
def test_reset_query_on_error(self): inst = Postgres(self.source, OPTIONS) mock_connector = mock.Mock() mock_connector.cursor.execute.side_effect = \ psycopg2.DatabaseError('oh noes!') inst.connector = mock_connector with self.assertRaises(psycopg2.DatabaseError): inst.execute('SELECT 1') # The connector.loaded variable should have been reset to 0 in order to # reset the query and start from the begining. self.assertEqual(inst.connector.loaded, 0) self.assertEqual(inst.connector.cursor, None)