mirror of
https://github.com/httpie/cli.git
synced 2024-12-23 23:09:17 +01:00
Removed last dependencies on unittest. All tests are pytest-only.
This commit is contained in:
parent
f658d24c93
commit
27faf06327
@ -1,6 +1,4 @@
|
||||
"""HTTP authentication-related tests."""
|
||||
from unittest import TestCase
|
||||
|
||||
import requests
|
||||
import pytest
|
||||
|
||||
@ -8,7 +6,7 @@ from tests import http, httpbin, HTTP_OK
|
||||
import httpie.input
|
||||
|
||||
|
||||
class AuthTest(TestCase):
|
||||
class TestAuth:
|
||||
def test_basic_auth(self):
|
||||
r = http('--auth=user:password', 'GET',
|
||||
httpbin('/basic-auth/user/password'))
|
||||
|
@ -1,13 +1,11 @@
|
||||
"""Tests for dealing with binary request and response data."""
|
||||
from unittest import TestCase
|
||||
|
||||
from httpie.compat import urlopen
|
||||
from httpie.output import BINARY_SUPPRESSED_NOTICE
|
||||
from tests import TestEnvironment, http, httpbin
|
||||
from tests.fixtures import BIN_FILE_PATH, BIN_FILE_CONTENT, BIN_FILE_PATH_ARG
|
||||
|
||||
|
||||
class BinaryRequestDataTest(TestCase):
|
||||
class TestBinaryRequestData:
|
||||
def test_binary_stdin(self):
|
||||
with open(BIN_FILE_PATH, 'rb') as stdin:
|
||||
env = TestEnvironment(
|
||||
@ -31,7 +29,7 @@ class BinaryRequestDataTest(TestCase):
|
||||
assert bytes(BIN_FILE_CONTENT) in bytes(r)
|
||||
|
||||
|
||||
class BinaryResponseDataTest(TestCase):
|
||||
class TestBinaryResponseData:
|
||||
url = 'http://www.google.com/favicon.ico'
|
||||
|
||||
@property
|
||||
|
@ -1,10 +1,10 @@
|
||||
"""CLI argument parsing related tests."""
|
||||
import json
|
||||
from unittest import TestCase
|
||||
|
||||
# noinspection PyCompatibility
|
||||
import argparse
|
||||
|
||||
import pytest
|
||||
|
||||
from httpie import input
|
||||
from httpie.input import KeyValue, KeyValueArgType
|
||||
from httpie import ExitStatus
|
||||
@ -16,15 +16,15 @@ from tests.fixtures import (
|
||||
)
|
||||
|
||||
|
||||
class ItemParsingTest(TestCase):
|
||||
def setUp(self):
|
||||
self.key_value_type = KeyValueArgType(*input.SEP_GROUP_ALL_ITEMS)
|
||||
class TestItemParsing:
|
||||
|
||||
key_value_type = KeyValueArgType(*input.SEP_GROUP_ALL_ITEMS)
|
||||
|
||||
def test_invalid_items(self):
|
||||
items = ['no-separator']
|
||||
for item in items:
|
||||
self.assertRaises(argparse.ArgumentTypeError,
|
||||
lambda: self.key_value_type(item))
|
||||
pytest.raises(argparse.ArgumentTypeError,
|
||||
self.key_value_type, item)
|
||||
|
||||
def test_escape(self):
|
||||
headers, data, files, params = input.parse_items([
|
||||
@ -93,7 +93,7 @@ class ItemParsingTest(TestCase):
|
||||
assert files['file'][1].read().strip().decode('utf8') == FILE_CONTENT
|
||||
|
||||
|
||||
class QuerystringTest(TestCase):
|
||||
class TestQuerystring:
|
||||
def test_query_string_params_in_url(self):
|
||||
r = http('--print=Hhb', 'GET', httpbin('/get?a=1&b=2'))
|
||||
path = '/get?a=1&b=2'
|
||||
@ -120,7 +120,7 @@ class QuerystringTest(TestCase):
|
||||
assert '"url": "%s"' % url in r
|
||||
|
||||
|
||||
class CLIParserTestCase(TestCase):
|
||||
class TestCLIParser:
|
||||
def test_expand_localhost_shorthand(self):
|
||||
args = parser.parse_args(args=[':'], env=TestEnvironment())
|
||||
assert args.url == 'http://localhost'
|
||||
@ -164,8 +164,9 @@ class CLIParserTestCase(TestCase):
|
||||
assert args.url == 'http://0000:0000:0000:0000:0000:0000:0000:0001'
|
||||
|
||||
|
||||
class ArgumentParserTestCase(TestCase):
|
||||
def setUp(self):
|
||||
class TestArgumentParser:
|
||||
|
||||
def setup_method(self, method):
|
||||
self.parser = input.Parser()
|
||||
|
||||
def test_guess_when_method_set_and_valid(self):
|
||||
@ -256,7 +257,7 @@ class ArgumentParserTestCase(TestCase):
|
||||
]
|
||||
|
||||
|
||||
class TestNoOptions(TestCase):
|
||||
class TestNoOptions:
|
||||
def test_valid_no_options(self):
|
||||
r = http('--verbose', '--no-verbose', 'GET', httpbin('/get'))
|
||||
assert 'GET /get HTTP/1.1' not in r
|
||||
@ -268,7 +269,7 @@ class TestNoOptions(TestCase):
|
||||
assert 'GET /get HTTP/1.1' not in r
|
||||
|
||||
|
||||
class IgnoreStdinTest(TestCase):
|
||||
class TestIgnoreStdin:
|
||||
def test_ignore_stdin(self):
|
||||
with open(FILE_PATH) as f:
|
||||
env = TestEnvironment(stdin=f, stdin_isatty=False)
|
||||
|
@ -2,13 +2,11 @@
|
||||
Tests for the provided defaults regarding HTTP method, and --json vs. --form.
|
||||
|
||||
"""
|
||||
from unittest import TestCase
|
||||
|
||||
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||
from tests.fixtures import FILE_PATH
|
||||
|
||||
|
||||
class ImplicitHTTPMethodTest(TestCase):
|
||||
class TestImplicitHTTPMethod:
|
||||
def test_implicit_GET(self):
|
||||
r = http(httpbin('/get'))
|
||||
assert HTTP_OK in r
|
||||
@ -35,7 +33,7 @@ class ImplicitHTTPMethodTest(TestCase):
|
||||
assert HTTP_OK in r
|
||||
|
||||
|
||||
class AutoContentTypeAndAcceptHeadersTest(TestCase):
|
||||
class TestAutoContentTypeAndAcceptHeaders:
|
||||
"""
|
||||
Test that Accept and Content-Type correctly defaults to JSON,
|
||||
but can still be overridden. The same with Content-Type when --form
|
||||
|
@ -30,7 +30,7 @@ assert filenames
|
||||
|
||||
@pytest.mark.skipif(not has_docutils(), reason='docutils not installed')
|
||||
@pytest.mark.parametrize('filename', filenames)
|
||||
def test_rst_files_syntax(filename):
|
||||
def test_rst_file_syntax(filename):
|
||||
p = subprocess.Popen(
|
||||
['rst2pseudoxml.py', '--report=1', '--exit-status=1', filename],
|
||||
stderr=subprocess.PIPE,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import os
|
||||
import time
|
||||
from unittest import TestCase
|
||||
|
||||
import pytest
|
||||
from requests.structures import CaseInsensitiveDict
|
||||
@ -21,7 +20,7 @@ class Response(object):
|
||||
self.status_code = status_code
|
||||
|
||||
|
||||
class DownloadUtilsTest(TestCase):
|
||||
class TestDownloadUtils:
|
||||
def test_Content_Range_parsing(self):
|
||||
parse = parse_content_range
|
||||
|
||||
@ -46,18 +45,16 @@ class DownloadUtilsTest(TestCase):
|
||||
# invalid byte-range-resp-spec
|
||||
pytest.raises(ContentRangeError, parse, 'bytes 100-100/*', 100)
|
||||
|
||||
def test_Content_Disposition_parsing(self):
|
||||
parse = filename_from_content_disposition
|
||||
assert 'hello-WORLD_123.txt' == parse(
|
||||
'attachment; filename=hello-WORLD_123.txt')
|
||||
assert 'hello-WORLD_123.txt' == parse(
|
||||
'attachment; filename=".hello-WORLD_123.txt"')
|
||||
assert 'white space.txt' == parse(
|
||||
'attachment; filename="white space.txt"')
|
||||
assert '"quotes".txt' == parse(
|
||||
r'attachment; filename="\"quotes\".txt"')
|
||||
assert parse('attachment; filename=/etc/hosts') == 'hosts'
|
||||
assert parse('attachment; filename=') is None
|
||||
@pytest.mark.parametrize('header, expected_filename', [
|
||||
('attachment; filename=hello-WORLD_123.txt', 'hello-WORLD_123.txt'),
|
||||
('attachment; filename=".hello-WORLD_123.txt"', 'hello-WORLD_123.txt'),
|
||||
('attachment; filename="white space.txt"', 'white space.txt'),
|
||||
(r'attachment; filename="\"quotes\".txt"', '"quotes".txt'),
|
||||
('attachment; filename=/etc/hosts', 'hosts'),
|
||||
('attachment; filename=', None)
|
||||
])
|
||||
def test_Content_Disposition_parsing(self, header, expected_filename):
|
||||
assert filename_from_content_disposition(header) == expected_filename
|
||||
|
||||
def test_filename_from_url(self):
|
||||
assert 'foo.txt' == filename_from_url(
|
||||
@ -94,7 +91,7 @@ class DownloadUtilsTest(TestCase):
|
||||
assert 'foo.bar-10' == get_unique_filename('foo.bar', attempts(10))
|
||||
|
||||
|
||||
class DownloadsTest(TestCase):
|
||||
class TestDownloads:
|
||||
# TODO: more tests
|
||||
|
||||
def test_actual_download(self):
|
||||
|
@ -1,5 +1,3 @@
|
||||
from unittest import TestCase
|
||||
|
||||
import requests
|
||||
import pytest
|
||||
|
||||
@ -7,7 +5,7 @@ from httpie import ExitStatus
|
||||
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||
|
||||
|
||||
class ExitStatusTest(TestCase):
|
||||
class TestExitStatus:
|
||||
def test_ok_response_exits_0(self):
|
||||
r = http('GET', httpbin('/status/200'))
|
||||
assert HTTP_OK in r
|
||||
|
@ -1,12 +1,10 @@
|
||||
"""High-level tests."""
|
||||
from unittest import TestCase
|
||||
|
||||
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||
from tests.fixtures import FILE_PATH, FILE_CONTENT
|
||||
import httpie
|
||||
|
||||
|
||||
class HTTPieTest(TestCase):
|
||||
class TestHTTPie:
|
||||
|
||||
def test_debug(self):
|
||||
r = http('--debug')
|
||||
|
@ -1,10 +1,8 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from httpie import ExitStatus
|
||||
from tests import TestEnvironment, http, httpbin, HTTP_OK, COLOR, CRLF
|
||||
|
||||
|
||||
class VerboseFlagTest(TestCase):
|
||||
class TestVerboseFlag:
|
||||
def test_verbose(self):
|
||||
r = http('--verbose', 'GET', httpbin('/get'), 'test-header:__test__')
|
||||
assert HTTP_OK in r
|
||||
@ -24,7 +22,7 @@ class VerboseFlagTest(TestCase):
|
||||
assert r'\"baz\": \"bar\"' in r # response
|
||||
|
||||
|
||||
class PrettyOptionsTest(TestCase):
|
||||
class TestPrettyOptions:
|
||||
"""Test the --pretty flag handling."""
|
||||
|
||||
def test_pretty_enabled_by_default(self):
|
||||
@ -72,7 +70,7 @@ class PrettyOptionsTest(TestCase):
|
||||
assert COLOR not in r
|
||||
|
||||
|
||||
class LineEndingsTest(TestCase):
|
||||
class TestLineEndings:
|
||||
"""
|
||||
Test that CRLF is properly used in headers
|
||||
and as the headers/body separator.
|
||||
@ -85,7 +83,7 @@ class LineEndingsTest(TestCase):
|
||||
break
|
||||
assert header.endswith(CRLF), repr(header)
|
||||
else:
|
||||
self.fail('CRLF between headers and body not found in %r' % msg)
|
||||
assert 0, 'CRLF between headers and body not found in %r' % msg
|
||||
body = ''.join(lines)
|
||||
assert CRLF not in body
|
||||
return body
|
||||
|
@ -1,16 +1,16 @@
|
||||
import os
|
||||
import shutil
|
||||
from unittest import TestCase
|
||||
|
||||
from tests import TestEnvironment, mk_config_dir, http, httpbin, HTTP_OK
|
||||
|
||||
|
||||
class SessionsTest(TestCase):
|
||||
class TestSessions:
|
||||
|
||||
@property
|
||||
def env(self):
|
||||
return TestEnvironment(config_dir=self.config_dir)
|
||||
|
||||
def setUp(self):
|
||||
def setup_method(self, method):
|
||||
# Start a full-blown session with a custom request header,
|
||||
# authorization, and response cookies.
|
||||
self.config_dir = mk_config_dir()
|
||||
@ -19,7 +19,7 @@ class SessionsTest(TestCase):
|
||||
env=self.env)
|
||||
assert HTTP_OK in r
|
||||
|
||||
def tearDown(self):
|
||||
def teardown_method(self, method):
|
||||
shutil.rmtree(self.config_dir)
|
||||
|
||||
def test_session_create(self):
|
||||
|
@ -1,5 +1,3 @@
|
||||
from unittest import TestCase
|
||||
|
||||
import pytest
|
||||
|
||||
from httpie.compat import is_windows
|
||||
@ -8,7 +6,7 @@ from tests import http, httpbin, TestEnvironment
|
||||
from tests.fixtures import BIN_FILE_CONTENT, BIN_FILE_PATH
|
||||
|
||||
|
||||
class StreamTest(TestCase):
|
||||
class TestStream:
|
||||
# GET because httpbin 500s with binary POST body.
|
||||
|
||||
@pytest.mark.skipif(is_windows,
|
||||
|
@ -1,5 +1,4 @@
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
import pytest
|
||||
|
||||
@ -8,7 +7,7 @@ from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||
from tests.fixtures import FILE_PATH_ARG, FILE_PATH, FILE_CONTENT
|
||||
|
||||
|
||||
class MultipartFormDataFileUploadTest(TestCase):
|
||||
class TestMultipartFormDataFileUpload:
|
||||
def test_non_existent_file_raises_parse_error(self):
|
||||
with pytest.raises(ParseError):
|
||||
http('--form', 'POST', httpbin('/post'), 'foo@/__does_not_exist__')
|
||||
@ -24,7 +23,7 @@ class MultipartFormDataFileUploadTest(TestCase):
|
||||
assert '"foo": "bar"' in r
|
||||
|
||||
|
||||
class RequestBodyFromFilePathTest(TestCase):
|
||||
class TestRequestBodyFromFilePath:
|
||||
"""
|
||||
`http URL @file'
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import os
|
||||
import tempfile
|
||||
from unittest import TestCase
|
||||
|
||||
import pytest
|
||||
|
||||
@ -8,17 +7,19 @@ from tests import TestEnvironment, http, httpbin, Environment
|
||||
from httpie.compat import is_windows
|
||||
|
||||
|
||||
class WindowsOnlyTests(TestCase):
|
||||
@pytest.mark.skipif(not is_windows, reason='windows-only')
|
||||
@pytest.mark.skipif(not is_windows, reason='windows-only')
|
||||
class TestWindowsOnly:
|
||||
|
||||
def test_windows_colorized_output(self):
|
||||
# Spits out the colorized output.
|
||||
http(httpbin('/get'), env=Environment())
|
||||
|
||||
|
||||
class FakeWindowsTest(TestCase):
|
||||
class TestFakeWindows:
|
||||
def test_output_file_pretty_not_allowed_on_windows(self):
|
||||
env = TestEnvironment(is_windows=True)
|
||||
r = http('--output',
|
||||
os.path.join(tempfile.gettempdir(), '__httpie_test_output__'),
|
||||
output_file = os.path.join(
|
||||
tempfile.gettempdir(), '__httpie_test_output__')
|
||||
r = http('--output', output_file,
|
||||
'--pretty=all', 'GET', httpbin('/get'), env=env)
|
||||
assert 'Only terminal output can be colorized on Windows' in r.stderr
|
||||
|
Loading…
Reference in New Issue
Block a user