mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Use get_parameter_status() method instead of Connection.info.parameter_status() (#3119)
The last one is only available since psycopg 2.8, while the first one since 2.0.8. For backward compatibility monkeypatch connection object returned by psycopg3. Close https://github.com/patroni/patroni/issues/3116
This commit is contained in:
+5
-9
@@ -201,20 +201,16 @@ class MockCursor(object):
|
||||
pass
|
||||
|
||||
|
||||
class MockConnectionInfo(object):
|
||||
|
||||
def parameter_status(self, param_name):
|
||||
if param_name == 'is_superuser':
|
||||
return 'on'
|
||||
return '0'
|
||||
|
||||
|
||||
class MockConnect(object):
|
||||
|
||||
server_version = 99999
|
||||
autocommit = False
|
||||
closed = 0
|
||||
info = MockConnectionInfo()
|
||||
|
||||
def get_parameter_status(self, param_name):
|
||||
if param_name == 'is_superuser':
|
||||
return 'on'
|
||||
return '0'
|
||||
|
||||
def cursor(self):
|
||||
return MockCursor(self)
|
||||
|
||||
@@ -3,7 +3,7 @@ import psutil
|
||||
import unittest
|
||||
import yaml
|
||||
|
||||
from . import MockConnect, MockCursor, MockConnectionInfo
|
||||
from . import MockConnect, MockCursor
|
||||
from copy import deepcopy
|
||||
from unittest.mock import MagicMock, Mock, PropertyMock, mock_open as _mock_open, patch
|
||||
|
||||
@@ -282,7 +282,7 @@ class TestGenerateConfig(unittest.TestCase):
|
||||
with patch('sys.argv', ['patroni.py',
|
||||
'--generate-config', '--dsn', 'host=foo port=bar user=foobar password=pwd_from_dsn']), \
|
||||
patch.object(MockCursor, 'rowcount', PropertyMock(return_value=0), create=True), \
|
||||
patch.object(MockConnectionInfo, 'parameter_status', Mock(return_value='off')), \
|
||||
patch.object(MockConnect, 'get_parameter_status', Mock(return_value='off')), \
|
||||
self.assertRaises(SystemExit) as e:
|
||||
_main()
|
||||
self.assertIn('The provided user does not have superuser privilege', e.exception.code)
|
||||
|
||||
Reference in New Issue
Block a user