Skip to content

Commit

Permalink
Move test suite from "util" to "retry"
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeickle committed Jun 3, 2019
1 parent 084ea70 commit ef2c9b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
27 changes: 27 additions & 0 deletions test/test_retry.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import pytest

from urllib3.response import HTTPResponse
from urllib3.packages import six
from urllib3.packages.six.moves import xrange
from urllib3.util.retry import Retry, RequestHistory
from urllib3.exceptions import (
ConnectTimeoutError,
InvalidHeader,
MaxRetryError,
ReadTimeoutError,
ResponseError,
Expand Down Expand Up @@ -271,3 +273,28 @@ def test_retry_set_remove_headers_on_redirect(self):
retry = Retry(remove_headers_on_redirect=["X-API-Secret"])

assert list(retry.remove_headers_on_redirect) == ["x-api-secret"]

@pytest.mark.parametrize("value", ["-1", "+1", "1.0", six.u("\xb2")]) # \xb2 = ^2
def test_parse_retry_after_invalid(self, value):
retry = Retry()
with pytest.raises(InvalidHeader):
retry.parse_retry_after(value)

@pytest.mark.parametrize(
"value, expected", [("0", 0), ("1000", 1000), ("\t42 ", 42)]
)
def test_parse_retry_after(self, value, expected):
retry = Retry()
assert retry.parse_retry_after(value) == expected

@pytest.mark.parametrize('respect_retry_after_header', [
True,
False
])
def test_respect_retry_after_header_propagated(self,
respect_retry_after_header):

retry = Retry(respect_retry_after_header=respect_retry_after_header)
new_retry = retry.new()
assert new_retry.respect_retry_after_header \
== respect_retry_after_header
27 changes: 0 additions & 27 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from urllib3 import add_stderr_logger, disable_warnings
from urllib3.util.request import make_headers, rewind_body, _FAILEDTELL
from urllib3.util.response import assert_header_parsing
from urllib3.util.retry import Retry
from urllib3.util.timeout import Timeout
from urllib3.util.url import get_host, parse_url, split_first, Url
from urllib3.util.ssl_ import (
Expand All @@ -27,7 +26,6 @@
TimeoutStateError,
InsecureRequestWarning,
SNIMissingWarning,
InvalidHeader,
UnrewindableBodyError,
)
from urllib3.util.connection import allowed_gai_family, _has_ipv6
Expand Down Expand Up @@ -782,31 +780,6 @@ def test_ip_family_ipv6_disabled(self):
with patch("urllib3.util.connection.HAS_IPV6", False):
assert allowed_gai_family() == socket.AF_INET

@pytest.mark.parametrize("value", ["-1", "+1", "1.0", six.u("\xb2")]) # \xb2 = ^2
def test_parse_retry_after_invalid(self, value):
retry = Retry()
with pytest.raises(InvalidHeader):
retry.parse_retry_after(value)

@pytest.mark.parametrize(
"value, expected", [("0", 0), ("1000", 1000), ("\t42 ", 42)]
)
def test_parse_retry_after(self, value, expected):
retry = Retry()
assert retry.parse_retry_after(value) == expected

@pytest.mark.parametrize('respect_retry_after_header', [
True,
False
])
def test_respect_retry_after_header_propagated(self,
respect_retry_after_header):

retry = Retry(respect_retry_after_header=respect_retry_after_header)
new_retry = retry.new()
assert new_retry.respect_retry_after_header \
== respect_retry_after_header

@pytest.mark.parametrize("headers", [b"foo", None, object])
def test_assert_header_parsing_throws_typeerror_with_non_headers(self, headers):
with pytest.raises(TypeError):
Expand Down

0 comments on commit ef2c9b7

Please sign in to comment.