Adding tests for advanced auth options for requests
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import six
|
||||
import time
|
||||
import warnings
|
||||
try:
|
||||
@@ -9,7 +8,7 @@ except ImportError:
|
||||
|
||||
from .base import Connection
|
||||
from ..exceptions import ConnectionError, ImproperlyConfigured, ConnectionTimeout, SSLError
|
||||
from ..compat import urlencode
|
||||
from ..compat import urlencode, string_types
|
||||
|
||||
class RequestsHttpConnection(Connection):
|
||||
"""
|
||||
@@ -35,9 +34,8 @@ class RequestsHttpConnection(Connection):
|
||||
if http_auth is not None:
|
||||
if isinstance(http_auth, (tuple, list)):
|
||||
http_auth = tuple(http_auth)
|
||||
elif isinstance(http_auth, six.string_types):
|
||||
elif isinstance(http_auth, string_types):
|
||||
http_auth = tuple(http_auth.split(':', 1))
|
||||
http_auth = tuple(http_auth)
|
||||
self.session.auth = http_auth
|
||||
self.base_url = 'http%s://%s:%d%s' % (
|
||||
's' if use_ssl else '',
|
||||
|
||||
@@ -2,6 +2,7 @@ import re
|
||||
from mock import Mock, patch
|
||||
import urllib3
|
||||
import warnings
|
||||
from requests.auth import AuthBase
|
||||
|
||||
from elasticsearch.exceptions import TransportError, ConflictError, RequestError, NotFoundError
|
||||
from elasticsearch.connection import RequestsHttpConnection, \
|
||||
@@ -87,6 +88,12 @@ class TestRequestsConnection(TestCase):
|
||||
self.assertEquals(1, len(args))
|
||||
return args[0]
|
||||
|
||||
def test_custom_http_auth_is_allowed(self):
|
||||
auth = AuthBase()
|
||||
c = RequestsHttpConnection(http_auth=auth)
|
||||
|
||||
self.assertEquals(auth, c.session.auth)
|
||||
|
||||
def test_timeout_set(self):
|
||||
con = RequestsHttpConnection(timeout=42)
|
||||
self.assertEquals(42, con.timeout)
|
||||
|
||||
Reference in New Issue
Block a user