| |
@@ -0,0 +1,182 @@
|
| |
+ From 218062ce064f51ec5aa52ce7b178bc9b3446ae98 Mon Sep 17 00:00:00 2001
|
| |
+ From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
|
| |
+ Date: Thu, 27 May 2021 17:26:01 +0200
|
| |
+ Subject: [PATCH] Skip http://pie.dev tests when offline
|
| |
+
|
| |
+ ---
|
| |
+ tests/conftest.py | 19 +++++++++++++++++++
|
| |
+ tests/test_tokens.py | 6 +++---
|
| |
+ tests/test_uploads.py | 26 +++++++++++++-------------
|
| |
+ tests/utils/__init__.py | 6 ------
|
| |
+ 4 files changed, 35 insertions(+), 22 deletions(-)
|
| |
+
|
| |
+ diff --git a/tests/conftest.py b/tests/conftest.py
|
| |
+ index ea08746..f489328 100644
|
| |
+ --- a/tests/conftest.py
|
| |
+ +++ b/tests/conftest.py
|
| |
+ @@ -1,3 +1,4 @@
|
| |
+ +import socket
|
| |
+ import pytest
|
| |
+ from pytest_httpbin import certs
|
| |
+
|
| |
+ @@ -22,3 +23,22 @@ def httpbin_secure_untrusted(monkeypatch, httpbin_secure):
|
| |
+ """
|
| |
+ monkeypatch.delenv('REQUESTS_CA_BUNDLE')
|
| |
+ return httpbin_secure
|
| |
+ +
|
| |
+ +
|
| |
+ +# pytest-httpbin currently does not support chunked requests:
|
| |
+ +# <https://github.com/kevin1024/pytest-httpbin/issues/33>
|
| |
+ +# <https://github.com/kevin1024/pytest-httpbin/issues/28>
|
| |
+ +@pytest.fixture(scope='session')
|
| |
+ +def _httpbin_with_chunked_support_available():
|
| |
+ + try:
|
| |
+ + socket.gethostbyname('pie.dev')
|
| |
+ + return True
|
| |
+ + except OSError:
|
| |
+ + return False
|
| |
+ +
|
| |
+ +
|
| |
+ +@pytest.fixture(scope='function')
|
| |
+ +def httpbin_with_chunked_support(_httpbin_with_chunked_support_available):
|
| |
+ + if _httpbin_with_chunked_support_available:
|
| |
+ + return 'http://pie.dev'
|
| |
+ + pytest.skip('pie.dev not resolvable')
|
| |
+ diff --git a/tests/test_tokens.py b/tests/test_tokens.py
|
| |
+ index 65e7248..874653a 100644
|
| |
+ --- a/tests/test_tokens.py
|
| |
+ +++ b/tests/test_tokens.py
|
| |
+ @@ -10,7 +10,7 @@ TODO: cover more scenarios
|
| |
+
|
| |
+ """
|
| |
+ from tests.utils.matching import assert_output_matches, Expect
|
| |
+ -from utils import http, HTTP_OK, MockEnvironment, HTTPBIN_WITH_CHUNKED_SUPPORT
|
| |
+ +from utils import http, HTTP_OK, MockEnvironment
|
| |
+
|
| |
+
|
| |
+ RAW_REQUEST = [
|
| |
+ @@ -129,8 +129,8 @@ def test_redirected_headers_multipart_no_separator():
|
| |
+ assert_output_matches(r, RAW_REQUEST)
|
| |
+
|
| |
+
|
| |
+ -def test_verbose_chunked():
|
| |
+ - r = http('--verbose', '--chunked', HTTPBIN_WITH_CHUNKED_SUPPORT + '/post', 'hello=world')
|
| |
+ +def test_verbose_chunked(httpbin_with_chunked_support):
|
| |
+ + r = http('--verbose', '--chunked', httpbin_with_chunked_support + '/post', 'hello=world')
|
| |
+ assert HTTP_OK in r
|
| |
+ assert 'Transfer-Encoding: chunked' in r
|
| |
+ assert_output_matches(r, TERMINAL_EXCHANGE)
|
| |
+ diff --git a/tests/test_uploads.py b/tests/test_uploads.py
|
| |
+ index 05fb200..24a8459 100644
|
| |
+ --- a/tests/test_uploads.py
|
| |
+ +++ b/tests/test_uploads.py
|
| |
+ @@ -6,17 +6,17 @@ from httpie.cli.exceptions import ParseError
|
| |
+ from httpie.client import FORM_CONTENT_TYPE
|
| |
+ from httpie.status import ExitStatus
|
| |
+ from utils import (
|
| |
+ - HTTPBIN_WITH_CHUNKED_SUPPORT, MockEnvironment, StdinBytesIO, http,
|
| |
+ + MockEnvironment, StdinBytesIO, http,
|
| |
+ HTTP_OK,
|
| |
+ )
|
| |
+ from fixtures import FILE_PATH_ARG, FILE_PATH, FILE_CONTENT
|
| |
+
|
| |
+
|
| |
+ -def test_chunked_json():
|
| |
+ +def test_chunked_json(httpbin_with_chunked_support):
|
| |
+ r = http(
|
| |
+ '--verbose',
|
| |
+ '--chunked',
|
| |
+ - HTTPBIN_WITH_CHUNKED_SUPPORT + '/post',
|
| |
+ + httpbin_with_chunked_support + '/post',
|
| |
+ 'hello=world',
|
| |
+ )
|
| |
+ assert HTTP_OK in r
|
| |
+ @@ -24,12 +24,12 @@ def test_chunked_json():
|
| |
+ assert r.count('hello') == 3
|
| |
+
|
| |
+
|
| |
+ -def test_chunked_form():
|
| |
+ +def test_chunked_form(httpbin_with_chunked_support):
|
| |
+ r = http(
|
| |
+ '--verbose',
|
| |
+ '--chunked',
|
| |
+ '--form',
|
| |
+ - HTTPBIN_WITH_CHUNKED_SUPPORT + '/post',
|
| |
+ + httpbin_with_chunked_support + '/post',
|
| |
+ 'hello=world',
|
| |
+ )
|
| |
+ assert HTTP_OK in r
|
| |
+ @@ -37,11 +37,11 @@ def test_chunked_form():
|
| |
+ assert r.count('hello') == 2
|
| |
+
|
| |
+
|
| |
+ -def test_chunked_stdin():
|
| |
+ +def test_chunked_stdin(httpbin_with_chunked_support):
|
| |
+ r = http(
|
| |
+ '--verbose',
|
| |
+ '--chunked',
|
| |
+ - HTTPBIN_WITH_CHUNKED_SUPPORT + '/post',
|
| |
+ + httpbin_with_chunked_support + '/post',
|
| |
+ env=MockEnvironment(
|
| |
+ stdin=StdinBytesIO(FILE_PATH.read_bytes()),
|
| |
+ stdin_isatty=False,
|
| |
+ @@ -52,12 +52,12 @@ def test_chunked_stdin():
|
| |
+ assert r.count(FILE_CONTENT) == 2
|
| |
+
|
| |
+
|
| |
+ -def test_chunked_stdin_multiple_chunks():
|
| |
+ +def test_chunked_stdin_multiple_chunks(httpbin_with_chunked_support):
|
| |
+ stdin_bytes = FILE_PATH.read_bytes() + b'\n' + FILE_PATH.read_bytes()
|
| |
+ r = http(
|
| |
+ '--verbose',
|
| |
+ '--chunked',
|
| |
+ - HTTPBIN_WITH_CHUNKED_SUPPORT + '/post',
|
| |
+ + httpbin_with_chunked_support + '/post',
|
| |
+ env=MockEnvironment(
|
| |
+ stdin=StdinBytesIO(stdin_bytes),
|
| |
+ stdin_isatty=False,
|
| |
+ @@ -182,12 +182,12 @@ class TestMultipartFormDataFileUpload:
|
| |
+ assert f'multipart/magic; boundary={boundary_in_header}' in r
|
| |
+ assert r.count(boundary_in_body) == 3
|
| |
+
|
| |
+ - def test_multipart_chunked(self, httpbin):
|
| |
+ + def test_multipart_chunked(self, httpbin_with_chunked_support):
|
| |
+ r = http(
|
| |
+ '--verbose',
|
| |
+ '--multipart',
|
| |
+ '--chunked',
|
| |
+ - HTTPBIN_WITH_CHUNKED_SUPPORT + '/post',
|
| |
+ + httpbin_with_chunked_support + '/post',
|
| |
+ 'AAA=AAA',
|
| |
+ )
|
| |
+ assert 'Transfer-Encoding: chunked' in r
|
| |
+ @@ -231,10 +231,10 @@ class TestRequestBodyFromFilePath:
|
| |
+ assert r.count(FILE_CONTENT) == 2
|
| |
+ assert '"Content-Type": "text/plain"' in r
|
| |
+
|
| |
+ - def test_request_body_from_file_by_path_chunked(self, httpbin):
|
| |
+ + def test_request_body_from_file_by_path_chunked(self, httpbin_with_chunked_support):
|
| |
+ r = http(
|
| |
+ '--verbose', '--chunked',
|
| |
+ - HTTPBIN_WITH_CHUNKED_SUPPORT + '/post',
|
| |
+ + httpbin_with_chunked_support + '/post',
|
| |
+ '@' + FILE_PATH_ARG,
|
| |
+ )
|
| |
+ assert HTTP_OK in r
|
| |
+ diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py
|
| |
+ index 575f1e2..a30c3ca 100644
|
| |
+ --- a/tests/utils/__init__.py
|
| |
+ +++ b/tests/utils/__init__.py
|
| |
+ @@ -16,12 +16,6 @@ from httpie.context import Environment
|
| |
+ from httpie.core import main
|
| |
+
|
| |
+
|
| |
+ -# pytest-httpbin currently does not support chunked requests:
|
| |
+ -# <https://github.com/kevin1024/pytest-httpbin/issues/33>
|
| |
+ -# <https://github.com/kevin1024/pytest-httpbin/issues/28>
|
| |
+ -HTTPBIN_WITH_CHUNKED_SUPPORT = 'http://pie.dev'
|
| |
+ -
|
| |
+ -
|
| |
+ TESTS_ROOT = Path(__file__).parent.parent
|
| |
+ CRLF = '\r\n'
|
| |
+ COLOR = '\x1b['
|
| |
The version change seems large, but the release is pretty backwards compatible, the most incompatible stuff is dropped Python 2 support, which we don't use anyway.