mirror of
https://github.com/httpie/cli.git
synced 2025-02-15 13:33:39 +02:00
Moved fixture constants to tests.fixtures.
This commit is contained in:
parent
b880e996d0
commit
941c0a8c3c
@ -28,11 +28,6 @@ from httpie.core import main
|
|||||||
from httpie.compat import bytes, str
|
from httpie.compat import bytes, str
|
||||||
|
|
||||||
|
|
||||||
def patharg(path):
|
|
||||||
"""Back slashes need to be escaped in ITEM args, even in Windows paths."""
|
|
||||||
return path.replace('\\', '\\\\\\')
|
|
||||||
|
|
||||||
|
|
||||||
HTTPBIN_URL = os.environ.get('HTTPBIN_URL',
|
HTTPBIN_URL = os.environ.get('HTTPBIN_URL',
|
||||||
'http://httpbin.org').rstrip('/')
|
'http://httpbin.org').rstrip('/')
|
||||||
|
|
||||||
@ -46,27 +41,6 @@ OK_COLOR = (
|
|||||||
)
|
)
|
||||||
COLOR = '\x1b['
|
COLOR = '\x1b['
|
||||||
|
|
||||||
### Test files
|
|
||||||
FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'file.txt')
|
|
||||||
FILE2_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'file2.txt')
|
|
||||||
BIN_FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'file.bin')
|
|
||||||
JSON_FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'test.json')
|
|
||||||
|
|
||||||
FILE_PATH_ARG = patharg(FILE_PATH)
|
|
||||||
FILE2_PATH_ARG = patharg(FILE2_PATH)
|
|
||||||
BIN_FILE_PATH_ARG = patharg(BIN_FILE_PATH)
|
|
||||||
JSON_FILE_PATH_ARG = patharg(JSON_FILE_PATH)
|
|
||||||
|
|
||||||
with open(FILE_PATH) as f:
|
|
||||||
# Strip because we don't want new lines in the data so that we can
|
|
||||||
# easily count occurrences also when embedded in JSON (where the new
|
|
||||||
# line would be escaped).
|
|
||||||
FILE_CONTENT = f.read().strip()
|
|
||||||
with open(BIN_FILE_PATH, 'rb') as f:
|
|
||||||
BIN_FILE_CONTENT = f.read()
|
|
||||||
with open(JSON_FILE_PATH, 'rb') as f:
|
|
||||||
JSON_FILE_CONTENT = f.read()
|
|
||||||
|
|
||||||
|
|
||||||
def httpbin(path):
|
def httpbin(path):
|
||||||
url = HTTPBIN_URL + path
|
url = HTTPBIN_URL + path
|
||||||
|
30
tests/fixtures/__init__.py
vendored
Normal file
30
tests/fixtures/__init__.py
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from tests import TESTS_ROOT
|
||||||
|
|
||||||
|
|
||||||
|
def patharg(path):
|
||||||
|
"""Back slashes need to be escaped in ITEM args, even in Windows paths."""
|
||||||
|
return path.replace('\\', '\\\\\\')
|
||||||
|
|
||||||
|
|
||||||
|
### Test files
|
||||||
|
FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'file.txt')
|
||||||
|
FILE2_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'file2.txt')
|
||||||
|
BIN_FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'file.bin')
|
||||||
|
JSON_FILE_PATH = os.path.join(TESTS_ROOT, 'fixtures', 'test.json')
|
||||||
|
|
||||||
|
FILE_PATH_ARG = patharg(FILE_PATH)
|
||||||
|
FILE2_PATH_ARG = patharg(FILE2_PATH)
|
||||||
|
BIN_FILE_PATH_ARG = patharg(BIN_FILE_PATH)
|
||||||
|
JSON_FILE_PATH_ARG = patharg(JSON_FILE_PATH)
|
||||||
|
|
||||||
|
with open(FILE_PATH) as f:
|
||||||
|
# Strip because we don't want new lines in the data so that we can
|
||||||
|
# easily count occurrences also when embedded in JSON (where the new
|
||||||
|
# line would be escaped).
|
||||||
|
FILE_CONTENT = f.read().strip()
|
||||||
|
with open(BIN_FILE_PATH, 'rb') as f:
|
||||||
|
BIN_FILE_CONTENT = f.read()
|
||||||
|
with open(JSON_FILE_PATH, 'rb') as f:
|
||||||
|
JSON_FILE_CONTENT = f.read()
|
@ -3,11 +3,8 @@ 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 (
|
from tests import TestEnvironment, http, httpbin
|
||||||
TestEnvironment, http, httpbin,
|
from tests.fixtures import BIN_FILE_PATH, BIN_FILE_CONTENT, BIN_FILE_PATH_ARG
|
||||||
BIN_FILE_PATH, BIN_FILE_CONTENT, BIN_FILE_PATH_ARG,
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class BinaryRequestDataTest(TestCase):
|
class BinaryRequestDataTest(TestCase):
|
||||||
|
@ -5,11 +5,12 @@ from unittest import TestCase
|
|||||||
# noinspection PyCompatibility
|
# noinspection PyCompatibility
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from tests import (
|
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||||
TestEnvironment, http, httpbin,
|
from tests.fixtures import (
|
||||||
FILE_PATH_ARG, JSON_FILE_PATH_ARG,
|
FILE_PATH_ARG, JSON_FILE_PATH_ARG,
|
||||||
JSON_FILE_CONTENT, FILE_CONTENT, HTTP_OK, FILE_PATH
|
JSON_FILE_CONTENT, FILE_CONTENT, FILE_PATH
|
||||||
)
|
)
|
||||||
|
|
||||||
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
|
||||||
|
@ -4,11 +4,8 @@ Tests for the provided defaults regarding HTTP method, and --json vs. --form.
|
|||||||
"""
|
"""
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from tests import (
|
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||||
TestEnvironment,
|
from tests.fixtures import FILE_PATH
|
||||||
http, httpbin,
|
|
||||||
HTTP_OK, FILE_PATH,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ImplicitHTTPMethodTest(TestCase):
|
class ImplicitHTTPMethodTest(TestCase):
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
"""High-level tests."""
|
"""High-level tests."""
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from tests import (
|
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||||
TestEnvironment,
|
from tests.fixtures import FILE_PATH, FILE_CONTENT
|
||||||
http, httpbin, HTTP_OK,
|
|
||||||
FILE_PATH, FILE_CONTENT
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPieTest(TestCase):
|
class HTTPieTest(TestCase):
|
||||||
|
@ -2,11 +2,7 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from tests import (
|
from tests import TestEnvironment, mk_config_dir, http, httpbin, HTTP_OK
|
||||||
TestEnvironment,
|
|
||||||
mk_config_dir, http, httpbin,
|
|
||||||
HTTP_OK,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SessionsTest(TestCase):
|
class SessionsTest(TestCase):
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from httpie.compat import is_windows
|
from httpie.compat import is_windows
|
||||||
from httpie.output import BINARY_SUPPRESSED_NOTICE
|
from httpie.output import BINARY_SUPPRESSED_NOTICE
|
||||||
from tests import (
|
from tests import http, httpbin, TestEnvironment
|
||||||
http, httpbin, skipIf,
|
from tests.fixtures import BIN_FILE_CONTENT, BIN_FILE_PATH
|
||||||
TestEnvironment,
|
|
||||||
BIN_FILE_CONTENT, BIN_FILE_PATH
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class StreamTest(TestCase):
|
class StreamTest(TestCase):
|
||||||
# GET because httpbin 500s with binary POST body.
|
# GET because httpbin 500s with binary POST body.
|
||||||
|
|
||||||
@skipIf(is_windows, 'Pretty redirect not supported under Windows')
|
@pytest.mark.skipif(is_windows,
|
||||||
|
reason='Pretty redirect not supported under Windows')
|
||||||
def test_pretty_redirected_stream(self):
|
def test_pretty_redirected_stream(self):
|
||||||
"""Test that --stream works with prettified redirected output."""
|
"""Test that --stream works with prettified redirected output."""
|
||||||
with open(BIN_FILE_PATH, 'rb') as f:
|
with open(BIN_FILE_PATH, 'rb') as f:
|
||||||
|
@ -2,10 +2,8 @@ import os
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from httpie.input import ParseError
|
from httpie.input import ParseError
|
||||||
from tests import (
|
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||||
TestEnvironment, http, httpbin,
|
from tests.fixtures import FILE_PATH_ARG, FILE_PATH, FILE_CONTENT
|
||||||
FILE_PATH_ARG, FILE_PATH, HTTP_OK, FILE_CONTENT,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class MultipartFormDataFileUploadTest(TestCase):
|
class MultipartFormDataFileUploadTest(TestCase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user