File: test_source_adapter.py

package info (click to toggle)
python-requests-toolbelt 1.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 876 kB
  • sloc: python: 3,653; makefile: 166; sh: 7
file content (41 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
from requests.adapters import DEFAULT_POOLSIZE, DEFAULT_POOLBLOCK
try:
    from unittest.mock import patch
except ImportError:
    from mock import patch
from requests_toolbelt.adapters.source import SourceAddressAdapter

import pytest


@patch('requests_toolbelt.adapters.source.poolmanager')
def test_source_address_adapter_string(poolmanager):
    SourceAddressAdapter('10.10.10.10')

    poolmanager.PoolManager.assert_called_once_with(
        num_pools=DEFAULT_POOLSIZE,
        maxsize=DEFAULT_POOLSIZE,
        block=DEFAULT_POOLBLOCK,
        source_address=('10.10.10.10', 0)
    )


@patch('requests_toolbelt.adapters.source.poolmanager')
def test_source_address_adapter_tuple(poolmanager):
    SourceAddressAdapter(('10.10.10.10', 80))

    poolmanager.PoolManager.assert_called_once_with(
        num_pools=DEFAULT_POOLSIZE,
        maxsize=DEFAULT_POOLSIZE,
        block=DEFAULT_POOLBLOCK,
        source_address=('10.10.10.10', 80)
    )


@patch('requests_toolbelt.adapters.source.poolmanager')
def test_source_address_adapter_type_error(poolmanager):
    with pytest.raises(TypeError):
        SourceAddressAdapter({'10.10.10.10': 80})

    assert not poolmanager.PoolManager.called