improve test coverage: provide tests for Service.proxy_http_request #1

Merged
hjacobs merged 1 commits from piontec/pykube-ng:test-proxy-request into main 12 months ago
  1. 759
      poetry.lock
  2. 1
      pyproject.toml
  3. 42
      tests/test_objects.py

759
poetry.lock

File diff suppressed because it is too large

1
pyproject.toml

@ -44,3 +44,4 @@ sphinx-rtd-theme = "^0.4.3"
sphinx-autodoc-annotation = "^1.0-1"
flake8 = "^3.7"
pre-commit = "^1.21.0"
pytest-mock = "^3.1.1"

42
tests/test_objects.py

@ -1,6 +1,8 @@
from typing import Dict, Any, Optional
from unittest.mock import MagicMock
import pytest
from pytest_mock import MockFixture
import pykube
from pykube.objects import NamespacedAPIObject
@ -67,3 +69,43 @@ def test_update():
pod.update(is_strategic=False)
assert pod.metadata == {"name": "john"}
assert pod.annotations == {}
@pytest.mark.parametrize(
"port,expected_request_kwargs",
[
# empty port - default service port should be used
(
None,
{"url": "services/test_service:9090/proxy//", "namespace": "test_namespace", "version": "v1"}
),
# override the default port, should be included in url
(
8080,
{"url": "services/test_service:8080/proxy//", "namespace": "test_namespace", "version": "v1"},
),
],
)
def test_service_proxy_http_request(mocker: MockFixture, port: Optional[int],
expected_request_kwargs: Dict[str, Any]) -> None:
mock_client = mocker.MagicMock(spec=pykube.http.HTTPClient)
service = pykube.Service(mock_client, {
"apiVersion": "core/v1",
"kind": "Service",
"metadata": {
"name": "test_service",
"namespace": "test_namespace",
},
"spec": {
"ports": [
{"port": 9090}
]
}
})
service.proxy_http_request("GET", "/", port)
request = mock_client.request
assert request.called
assert request.call_args_list[0][0] == ("GET",)
assert request.call_args_list[0][1] == expected_request_kwargs

Loading…
Cancel
Save