Removed last dependencies on unittest. All tests are pytest-only.

This commit is contained in:
Jakub Roztocil 2014-04-25 11:39:59 +02:00
parent f658d24c93
commit 27faf06327
13 changed files with 52 additions and 68 deletions

View File

@ -1,6 +1,4 @@
"""HTTP authentication-related tests.""" """HTTP authentication-related tests."""
from unittest import TestCase
import requests import requests
import pytest import pytest
@ -8,7 +6,7 @@ from tests import http, httpbin, HTTP_OK
import httpie.input import httpie.input
class AuthTest(TestCase): class TestAuth:
def test_basic_auth(self): def test_basic_auth(self):
r = http('--auth=user:password', 'GET', r = http('--auth=user:password', 'GET',
httpbin('/basic-auth/user/password')) httpbin('/basic-auth/user/password'))

View File

@ -1,13 +1,11 @@
"""Tests for dealing with binary request and response data.""" """Tests for dealing with binary request and response data."""
from unittest import TestCase
from httpie.compat import urlopen from httpie.compat import urlopen
from httpie.output import BINARY_SUPPRESSED_NOTICE from httpie.output import BINARY_SUPPRESSED_NOTICE
from tests import TestEnvironment, http, httpbin from tests import TestEnvironment, http, httpbin
from tests.fixtures import BIN_FILE_PATH, BIN_FILE_CONTENT, BIN_FILE_PATH_ARG from tests.fixtures import BIN_FILE_PATH, BIN_FILE_CONTENT, BIN_FILE_PATH_ARG
class BinaryRequestDataTest(TestCase): class TestBinaryRequestData:
def test_binary_stdin(self): def test_binary_stdin(self):
with open(BIN_FILE_PATH, 'rb') as stdin: with open(BIN_FILE_PATH, 'rb') as stdin:
env = TestEnvironment( env = TestEnvironment(
@ -31,7 +29,7 @@ class BinaryRequestDataTest(TestCase):
assert bytes(BIN_FILE_CONTENT) in bytes(r) assert bytes(BIN_FILE_CONTENT) in bytes(r)
class BinaryResponseDataTest(TestCase): class TestBinaryResponseData:
url = 'http://www.google.com/favicon.ico' url = 'http://www.google.com/favicon.ico'
@property @property

View File

@ -1,10 +1,10 @@
"""CLI argument parsing related tests.""" """CLI argument parsing related tests."""
import json import json
from unittest import TestCase
# noinspection PyCompatibility # noinspection PyCompatibility
import argparse import argparse
import pytest
from httpie import input from httpie import input
from httpie.input import KeyValue, KeyValueArgType from httpie.input import KeyValue, KeyValueArgType
from httpie import ExitStatus from httpie import ExitStatus
@ -16,15 +16,15 @@ from tests.fixtures import (
) )
class ItemParsingTest(TestCase): class TestItemParsing:
def setUp(self):
self.key_value_type = KeyValueArgType(*input.SEP_GROUP_ALL_ITEMS) key_value_type = KeyValueArgType(*input.SEP_GROUP_ALL_ITEMS)
def test_invalid_items(self): def test_invalid_items(self):
items = ['no-separator'] items = ['no-separator']
for item in items: for item in items:
self.assertRaises(argparse.ArgumentTypeError, pytest.raises(argparse.ArgumentTypeError,
lambda: self.key_value_type(item)) self.key_value_type, item)
def test_escape(self): def test_escape(self):
headers, data, files, params = input.parse_items([ headers, data, files, params = input.parse_items([
@ -93,7 +93,7 @@ class ItemParsingTest(TestCase):
assert files['file'][1].read().strip().decode('utf8') == FILE_CONTENT assert files['file'][1].read().strip().decode('utf8') == FILE_CONTENT
class QuerystringTest(TestCase): class TestQuerystring:
def test_query_string_params_in_url(self): def test_query_string_params_in_url(self):
r = http('--print=Hhb', 'GET', httpbin('/get?a=1&b=2')) r = http('--print=Hhb', 'GET', httpbin('/get?a=1&b=2'))
path = '/get?a=1&b=2' path = '/get?a=1&b=2'
@ -120,7 +120,7 @@ class QuerystringTest(TestCase):
assert '"url": "%s"' % url in r assert '"url": "%s"' % url in r
class CLIParserTestCase(TestCase): class TestCLIParser:
def test_expand_localhost_shorthand(self): def test_expand_localhost_shorthand(self):
args = parser.parse_args(args=[':'], env=TestEnvironment()) args = parser.parse_args(args=[':'], env=TestEnvironment())
assert args.url == 'http://localhost' assert args.url == 'http://localhost'
@ -164,8 +164,9 @@ class CLIParserTestCase(TestCase):
assert args.url == 'http://0000:0000:0000:0000:0000:0000:0000:0001' assert args.url == 'http://0000:0000:0000:0000:0000:0000:0000:0001'
class ArgumentParserTestCase(TestCase): class TestArgumentParser:
def setUp(self):
def setup_method(self, method):
self.parser = input.Parser() self.parser = input.Parser()
def test_guess_when_method_set_and_valid(self): 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): def test_valid_no_options(self):
r = http('--verbose', '--no-verbose', 'GET', httpbin('/get')) r = http('--verbose', '--no-verbose', 'GET', httpbin('/get'))
assert 'GET /get HTTP/1.1' not in r 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 assert 'GET /get HTTP/1.1' not in r
class IgnoreStdinTest(TestCase): class TestIgnoreStdin:
def test_ignore_stdin(self): def test_ignore_stdin(self):
with open(FILE_PATH) as f: with open(FILE_PATH) as f:
env = TestEnvironment(stdin=f, stdin_isatty=False) env = TestEnvironment(stdin=f, stdin_isatty=False)

View File

@ -2,13 +2,11 @@
Tests for the provided defaults regarding HTTP method, and --json vs. --form. 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 import TestEnvironment, http, httpbin, HTTP_OK
from tests.fixtures import FILE_PATH from tests.fixtures import FILE_PATH
class ImplicitHTTPMethodTest(TestCase): class TestImplicitHTTPMethod:
def test_implicit_GET(self): def test_implicit_GET(self):
r = http(httpbin('/get')) r = http(httpbin('/get'))
assert HTTP_OK in r assert HTTP_OK in r
@ -35,7 +33,7 @@ class ImplicitHTTPMethodTest(TestCase):
assert HTTP_OK in r assert HTTP_OK in r
class AutoContentTypeAndAcceptHeadersTest(TestCase): class TestAutoContentTypeAndAcceptHeaders:
""" """
Test that Accept and Content-Type correctly defaults to JSON, Test that Accept and Content-Type correctly defaults to JSON,
but can still be overridden. The same with Content-Type when --form but can still be overridden. The same with Content-Type when --form

View File

@ -30,7 +30,7 @@ assert filenames
@pytest.mark.skipif(not has_docutils(), reason='docutils not installed') @pytest.mark.skipif(not has_docutils(), reason='docutils not installed')
@pytest.mark.parametrize('filename', filenames) @pytest.mark.parametrize('filename', filenames)
def test_rst_files_syntax(filename): def test_rst_file_syntax(filename):
p = subprocess.Popen( p = subprocess.Popen(
['rst2pseudoxml.py', '--report=1', '--exit-status=1', filename], ['rst2pseudoxml.py', '--report=1', '--exit-status=1', filename],
stderr=subprocess.PIPE, stderr=subprocess.PIPE,

View File

@ -1,6 +1,5 @@
import os import os
import time import time
from unittest import TestCase
import pytest import pytest
from requests.structures import CaseInsensitiveDict from requests.structures import CaseInsensitiveDict
@ -21,7 +20,7 @@ class Response(object):
self.status_code = status_code self.status_code = status_code
class DownloadUtilsTest(TestCase): class TestDownloadUtils:
def test_Content_Range_parsing(self): def test_Content_Range_parsing(self):
parse = parse_content_range parse = parse_content_range
@ -46,18 +45,16 @@ class DownloadUtilsTest(TestCase):
# invalid byte-range-resp-spec # invalid byte-range-resp-spec
pytest.raises(ContentRangeError, parse, 'bytes 100-100/*', 100) pytest.raises(ContentRangeError, parse, 'bytes 100-100/*', 100)
def test_Content_Disposition_parsing(self): @pytest.mark.parametrize('header, expected_filename', [
parse = filename_from_content_disposition ('attachment; filename=hello-WORLD_123.txt', 'hello-WORLD_123.txt'),
assert 'hello-WORLD_123.txt' == parse( ('attachment; filename=".hello-WORLD_123.txt"', 'hello-WORLD_123.txt'),
'attachment; filename=hello-WORLD_123.txt') ('attachment; filename="white space.txt"', 'white space.txt'),
assert 'hello-WORLD_123.txt' == parse( (r'attachment; filename="\"quotes\".txt"', '"quotes".txt'),
'attachment; filename=".hello-WORLD_123.txt"') ('attachment; filename=/etc/hosts', 'hosts'),
assert 'white space.txt' == parse( ('attachment; filename=', None)
'attachment; filename="white space.txt"') ])
assert '"quotes".txt' == parse( def test_Content_Disposition_parsing(self, header, expected_filename):
r'attachment; filename="\"quotes\".txt"') assert filename_from_content_disposition(header) == expected_filename
assert parse('attachment; filename=/etc/hosts') == 'hosts'
assert parse('attachment; filename=') is None
def test_filename_from_url(self): def test_filename_from_url(self):
assert 'foo.txt' == filename_from_url( assert 'foo.txt' == filename_from_url(
@ -94,7 +91,7 @@ class DownloadUtilsTest(TestCase):
assert 'foo.bar-10' == get_unique_filename('foo.bar', attempts(10)) assert 'foo.bar-10' == get_unique_filename('foo.bar', attempts(10))
class DownloadsTest(TestCase): class TestDownloads:
# TODO: more tests # TODO: more tests
def test_actual_download(self): def test_actual_download(self):

View File

@ -1,5 +1,3 @@
from unittest import TestCase
import requests import requests
import pytest import pytest
@ -7,7 +5,7 @@ from httpie import ExitStatus
from tests import TestEnvironment, http, httpbin, HTTP_OK from tests import TestEnvironment, http, httpbin, HTTP_OK
class ExitStatusTest(TestCase): class TestExitStatus:
def test_ok_response_exits_0(self): def test_ok_response_exits_0(self):
r = http('GET', httpbin('/status/200')) r = http('GET', httpbin('/status/200'))
assert HTTP_OK in r assert HTTP_OK in r

View File

@ -1,12 +1,10 @@
"""High-level tests.""" """High-level tests."""
from unittest import TestCase
from tests import TestEnvironment, http, httpbin, HTTP_OK from tests import TestEnvironment, http, httpbin, HTTP_OK
from tests.fixtures import FILE_PATH, FILE_CONTENT from tests.fixtures import FILE_PATH, FILE_CONTENT
import httpie import httpie
class HTTPieTest(TestCase): class TestHTTPie:
def test_debug(self): def test_debug(self):
r = http('--debug') r = http('--debug')

View File

@ -1,10 +1,8 @@
from unittest import TestCase
from httpie import ExitStatus from httpie import ExitStatus
from tests import TestEnvironment, http, httpbin, HTTP_OK, COLOR, CRLF from tests import TestEnvironment, http, httpbin, HTTP_OK, COLOR, CRLF
class VerboseFlagTest(TestCase): class TestVerboseFlag:
def test_verbose(self): def test_verbose(self):
r = http('--verbose', 'GET', httpbin('/get'), 'test-header:__test__') r = http('--verbose', 'GET', httpbin('/get'), 'test-header:__test__')
assert HTTP_OK in r assert HTTP_OK in r
@ -24,7 +22,7 @@ class VerboseFlagTest(TestCase):
assert r'\"baz\": \"bar\"' in r # response assert r'\"baz\": \"bar\"' in r # response
class PrettyOptionsTest(TestCase): class TestPrettyOptions:
"""Test the --pretty flag handling.""" """Test the --pretty flag handling."""
def test_pretty_enabled_by_default(self): def test_pretty_enabled_by_default(self):
@ -72,7 +70,7 @@ class PrettyOptionsTest(TestCase):
assert COLOR not in r assert COLOR not in r
class LineEndingsTest(TestCase): class TestLineEndings:
""" """
Test that CRLF is properly used in headers Test that CRLF is properly used in headers
and as the headers/body separator. and as the headers/body separator.
@ -85,7 +83,7 @@ class LineEndingsTest(TestCase):
break break
assert header.endswith(CRLF), repr(header) assert header.endswith(CRLF), repr(header)
else: 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) body = ''.join(lines)
assert CRLF not in body assert CRLF not in body
return body return body

View File

@ -1,16 +1,16 @@
import os import os
import shutil import shutil
from unittest import TestCase
from tests import TestEnvironment, mk_config_dir, http, httpbin, HTTP_OK from tests import TestEnvironment, mk_config_dir, http, httpbin, HTTP_OK
class SessionsTest(TestCase): class TestSessions:
@property @property
def env(self): def env(self):
return TestEnvironment(config_dir=self.config_dir) 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, # Start a full-blown session with a custom request header,
# authorization, and response cookies. # authorization, and response cookies.
self.config_dir = mk_config_dir() self.config_dir = mk_config_dir()
@ -19,7 +19,7 @@ class SessionsTest(TestCase):
env=self.env) env=self.env)
assert HTTP_OK in r assert HTTP_OK in r
def tearDown(self): def teardown_method(self, method):
shutil.rmtree(self.config_dir) shutil.rmtree(self.config_dir)
def test_session_create(self): def test_session_create(self):

View File

@ -1,5 +1,3 @@
from unittest import TestCase
import pytest import pytest
from httpie.compat import is_windows 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 from tests.fixtures import BIN_FILE_CONTENT, BIN_FILE_PATH
class StreamTest(TestCase): class TestStream:
# GET because httpbin 500s with binary POST body. # GET because httpbin 500s with binary POST body.
@pytest.mark.skipif(is_windows, @pytest.mark.skipif(is_windows,

View File

@ -1,5 +1,4 @@
import os import os
from unittest import TestCase
import pytest 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 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): def test_non_existent_file_raises_parse_error(self):
with pytest.raises(ParseError): with pytest.raises(ParseError):
http('--form', 'POST', httpbin('/post'), 'foo@/__does_not_exist__') http('--form', 'POST', httpbin('/post'), 'foo@/__does_not_exist__')
@ -24,7 +23,7 @@ class MultipartFormDataFileUploadTest(TestCase):
assert '"foo": "bar"' in r assert '"foo": "bar"' in r
class RequestBodyFromFilePathTest(TestCase): class TestRequestBodyFromFilePath:
""" """
`http URL @file' `http URL @file'

View File

@ -1,6 +1,5 @@
import os import os
import tempfile import tempfile
from unittest import TestCase
import pytest import pytest
@ -8,17 +7,19 @@ from tests import TestEnvironment, http, httpbin, Environment
from httpie.compat import is_windows 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): def test_windows_colorized_output(self):
# Spits out the colorized output. # Spits out the colorized output.
http(httpbin('/get'), env=Environment()) http(httpbin('/get'), env=Environment())
class FakeWindowsTest(TestCase): class TestFakeWindows:
def test_output_file_pretty_not_allowed_on_windows(self): def test_output_file_pretty_not_allowed_on_windows(self):
env = TestEnvironment(is_windows=True) env = TestEnvironment(is_windows=True)
r = http('--output', output_file = os.path.join(
os.path.join(tempfile.gettempdir(), '__httpie_test_output__'), tempfile.gettempdir(), '__httpie_test_output__')
r = http('--output', output_file,
'--pretty=all', 'GET', httpbin('/get'), env=env) '--pretty=all', 'GET', httpbin('/get'), env=env)
assert 'Only terminal output can be colorized on Windows' in r.stderr assert 'Only terminal output can be colorized on Windows' in r.stderr