Restore interface of Connector
It was changed in a backwards incompatible way. This change corrects it and issues a deprecation warning on using old arguments. Change-Id: I991ddb50818fd84a4e707204c86d50d3a2b553c8
This commit is contained in:
parent
5a2896699d
commit
7b6f37f73a
@ -26,11 +26,17 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class Connector(object):
|
||||
|
||||
def __init__(self, url, verify=True):
|
||||
def __init__(self, url, username=None, password=None, verify=True):
|
||||
self._url = url
|
||||
self._verify = verify
|
||||
self._session = requests.Session()
|
||||
self._session.verify = self._verify
|
||||
if username or password:
|
||||
LOG.warning('Passing username and password to Connector is '
|
||||
'deprecated. Authentication is passed through '
|
||||
'set_auth now, support for these arguments will '
|
||||
'be removed in the future')
|
||||
self.set_http_basic_auth(username, password)
|
||||
|
||||
def set_auth(self, auth):
|
||||
"""Sets the authentication mechanism for our connector."""
|
||||
|
@ -37,6 +37,12 @@ class ConnectorMethodsTestCase(base.TestCase):
|
||||
self.data = {'fake': 'data'}
|
||||
self.headers = {'X-Fake': 'header'}
|
||||
|
||||
def test_init_with_credentials(self):
|
||||
conn = connector.Connector('http://foo.bar:1234',
|
||||
username='admin',
|
||||
password='password')
|
||||
self.assertEqual(conn._session.auth, ('admin', 'password'))
|
||||
|
||||
@mock.patch.object(connector.Connector, '_op', autospec=True)
|
||||
def test_get(self, mock__op):
|
||||
self.conn.get(path='fake/path', data=self.data.copy(),
|
||||
|
Loading…
Reference in New Issue
Block a user