1
0
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:
Jakub Roztocil 2014-04-24 15:17:04 +02:00
parent b880e996d0
commit 941c0a8c3c
9 changed files with 49 additions and 59 deletions

View File

@ -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
View 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()

View File

@ -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):

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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:

View File

@ -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):