Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
test that default HTTP timeout was set
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Mar 3, 2019
1 parent 10273f2 commit a9bb51e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@
from unittest.mock import MagicMock

from pykube import __version__
from pykube.http import HTTPClient
from pykube.http import HTTPClient, DEFAULT_HTTP_TIMEOUT
from pykube.config import KubeConfig

GOOD_CONFIG_FILE_PATH = os.path.sep.join(["tests", "test_config_with_context.yaml"])


def test_http(monkeypatch):
cfg = KubeConfig.from_file(GOOD_CONFIG_FILE_PATH)
session = HTTPClient(cfg).session
api = HTTPClient(cfg)

mock_send = MagicMock()
mock_send.side_effect = Exception('MOCK HTTP')
monkeypatch.setattr('pykube.http.KubernetesHTTPAdapter._do_send', mock_send)

with pytest.raises(Exception):
session.get('http://localhost:9090/test')
api.get(url='test')

mock_send.assert_called_once()
assert mock_send.call_args[0][0].headers['Authorization'] == 'Basic YWRtOnNvbWVwYXNzd29yZA=='
assert mock_send.call_args[0][0].headers['User-Agent'] == f'pykube-ng/{__version__}'
# check that the default HTTP timeout was set
assert mock_send.call_args[1]['timeout'] == DEFAULT_HTTP_TIMEOUT

0 comments on commit a9bb51e

Please sign in to comment.