Ejemplo n.º 1
0
def test_set_in():
    orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
    new = orig.set_in(['a', 1], 'yyy')
    assert new == {'a': ['x', 'yyy', 'z'], 'b': 2, 'c': 3}

    orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
    new = orig.set_in(['a'], 'yyy')
    assert new == {'a': 'yyy', 'b': 2, 'c': 3}

    orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
    new = orig.set_in([], 'yyy')
    assert new == 'yyy'
Ejemplo n.º 2
0
def test_delete_in():
    orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
    new = orig.delete_in(['a', 1])
    assert new == {'a': ['x', 'z'], 'b': 2, 'c': 3}

    orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
    new = orig.delete_in(['a'])
    assert new == {'b': 2, 'c': 3}

    orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
    new = orig.delete_in([])
    assert new is None
Ejemplo n.º 3
0
 def __init__(self,
              credentials=None,
              headers=None,
              session=None,
              request_callback=None,
              response_callback=None):
     if headers:
         headers = {key.lower(): value for key, value in headers.items()}
     if session is None:
         session = requests.Session()
     self._credentials = itypes.Dict(credentials or {})
     self._headers = itypes.Dict(headers or {})
     self._session = session
     self._request_callback = request_callback
     self._response_callback = response_callback
Ejemplo n.º 4
0
    def __init__(self,
                 credentials=None,
                 headers=None,
                 auth=None,
                 session=None,
                 request_callback=None,
                 response_callback=None):
        if headers:
            headers = {key.lower(): value for key, value in headers.items()}
        if session is None:
            session = requests.Session()
        if auth is not None:
            session.auth = auth
        if not getattr(session.auth, 'allow_cookies', False):
            session.cookies.set_policy(BlockAll())

        if credentials is not None:
            warnings.warn(
                "The 'credentials' argument is now deprecated in favor of 'auth'.",
                DeprecationWarning)
            auth = DomainCredentials(credentials)
        if request_callback is not None or response_callback is not None:
            warnings.warn(
                "The 'request_callback' and 'response_callback' arguments are now deprecated. "
                "Use a custom 'session' instance instead.", DeprecationWarning)
            session.mount('https://',
                          CallbackAdapter(request_callback, response_callback))
            session.mount('http://',
                          CallbackAdapter(request_callback, response_callback))

        self._headers = itypes.Dict(headers or {})
        self._session = session
Ejemplo n.º 5
0
    def __init__(self,
                 credentials=None,
                 headers=None,
                 session=None,
                 request_callback=None,
                 response_callback=None):
        if headers:
            headers = {key.lower(): value for key, value in headers.items()}
        if session is None:
            session = requests.Session()
        self._credentials = itypes.Dict(credentials or {})
        self._headers = itypes.Dict(headers or {})
        self._session = session

        # Fallback for v1.x overrides.
        # Will be removed at some point, most likely in a 2.1 release.
        self._request_callback = request_callback
        self._response_callback = response_callback
Ejemplo n.º 6
0
    def __init__(self,
                 headers=None,
                 auth=None,
                 params_callback=None,
                 message_callback=None):
        self._auth = auth

        if headers:
            headers = {key.lower(): value for key, value in headers.items()}

        self._headers = itypes.Dict(headers or {})
        self._params_callback = params_callback
        self._message_callback = message_callback

        urllib3.disable_warnings()
Ejemplo n.º 7
0
def test_dict_get():
    orig = itypes.Dict({'a': 1, 'b': 2, 'c': 3})
    assert orig.get('a') == 1
    assert orig.get('z') is None
Ejemplo n.º 8
0
def test_get_in():
    orig = itypes.Dict({'a': ['x', 'y', 'z'], 'b': 2, 'c': 3})
    assert orig.get_in(['a', -1]) == 'z'
    assert orig.get_in(['dummy', -1]) is None
    assert orig.get_in(['a', 999]) is None
Ejemplo n.º 9
0
def test_dict_set():
    orig = itypes.Dict({'a': 1, 'b': 2, 'c': 3})
    new = orig.set('d', 4)
    assert new == {'a': 1, 'b': 2, 'c': 3, 'd': 4}
Ejemplo n.º 10
0
def test_dict_delete():
    orig = itypes.Dict({'a': 1, 'b': 2, 'c': 3})
    new = orig.delete('a')
    assert new == {'b': 2, 'c': 3}
Ejemplo n.º 11
0
def test_dict_lookup():
    orig = itypes.Dict({'a': 1, 'b': 2, 'c': 3})
    assert orig['a'] == 1
    with pytest.raises(KeyError):
        orig['zzz']