mirror of
https://github.com/httpie/cli.git
synced 2024-11-24 08:22:22 +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
|
||||
|
||||
|
||||
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',
|
||||
'http://httpbin.org').rstrip('/')
|
||||
|
||||
@ -46,27 +41,6 @@ OK_COLOR = (
|
||||
)
|
||||
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):
|
||||
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.output import BINARY_SUPPRESSED_NOTICE
|
||||
from tests import (
|
||||
TestEnvironment, http, httpbin,
|
||||
BIN_FILE_PATH, BIN_FILE_CONTENT, BIN_FILE_PATH_ARG,
|
||||
|
||||
)
|
||||
from tests import TestEnvironment, http, httpbin
|
||||
from tests.fixtures import BIN_FILE_PATH, BIN_FILE_CONTENT, BIN_FILE_PATH_ARG
|
||||
|
||||
|
||||
class BinaryRequestDataTest(TestCase):
|
||||
|
@ -5,11 +5,12 @@ from unittest import TestCase
|
||||
# noinspection PyCompatibility
|
||||
import argparse
|
||||
|
||||
from tests import (
|
||||
TestEnvironment, http, httpbin,
|
||||
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||
from tests.fixtures import (
|
||||
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.input import KeyValue, KeyValueArgType
|
||||
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 tests import (
|
||||
TestEnvironment,
|
||||
http, httpbin,
|
||||
HTTP_OK, FILE_PATH,
|
||||
)
|
||||
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||
from tests.fixtures import FILE_PATH
|
||||
|
||||
|
||||
class ImplicitHTTPMethodTest(TestCase):
|
||||
|
@ -1,11 +1,8 @@
|
||||
"""High-level tests."""
|
||||
from unittest import TestCase
|
||||
|
||||
from tests import (
|
||||
TestEnvironment,
|
||||
http, httpbin, HTTP_OK,
|
||||
FILE_PATH, FILE_CONTENT
|
||||
)
|
||||
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||
from tests.fixtures import FILE_PATH, FILE_CONTENT
|
||||
|
||||
|
||||
class HTTPieTest(TestCase):
|
||||
|
@ -2,11 +2,7 @@ import os
|
||||
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):
|
||||
|
@ -1,18 +1,18 @@
|
||||
from unittest import TestCase
|
||||
|
||||
import pytest
|
||||
|
||||
from httpie.compat import is_windows
|
||||
from httpie.output import BINARY_SUPPRESSED_NOTICE
|
||||
from tests import (
|
||||
http, httpbin, skipIf,
|
||||
TestEnvironment,
|
||||
BIN_FILE_CONTENT, BIN_FILE_PATH
|
||||
)
|
||||
from tests import http, httpbin, TestEnvironment
|
||||
from tests.fixtures import BIN_FILE_CONTENT, BIN_FILE_PATH
|
||||
|
||||
|
||||
class StreamTest(TestCase):
|
||||
# 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):
|
||||
"""Test that --stream works with prettified redirected output."""
|
||||
with open(BIN_FILE_PATH, 'rb') as f:
|
||||
|
@ -2,10 +2,8 @@ import os
|
||||
from unittest import TestCase
|
||||
|
||||
from httpie.input import ParseError
|
||||
from tests import (
|
||||
TestEnvironment, http, httpbin,
|
||||
FILE_PATH_ARG, FILE_PATH, HTTP_OK, FILE_CONTENT,
|
||||
)
|
||||
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||
from tests.fixtures import FILE_PATH_ARG, FILE_PATH, FILE_CONTENT
|
||||
|
||||
|
||||
class MultipartFormDataFileUploadTest(TestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user