Move example URL in a global variable for tests

This commit is contained in:
Mickaël Schoentgen 2021-09-01 16:52:10 +02:00
parent fdd486415a
commit 85110643e7
2 changed files with 5 additions and 4 deletions

View File

@ -9,7 +9,7 @@ from httpie.output.streams import BINARY_SUPPRESSED_NOTICE
from httpie.plugins import ConverterPlugin from httpie.plugins import ConverterPlugin
from httpie.plugins.registry import plugin_manager from httpie.plugins.registry import plugin_manager
from .utils import StdinBytesIO, http, MockEnvironment from .utils import StdinBytesIO, http, MockEnvironment, URL_EXAMPLE
from .fixtures import BIN_FILE_CONTENT, BIN_FILE_PATH from .fixtures import BIN_FILE_CONTENT, BIN_FILE_PATH
PRETTY_OPTIONS = list(PRETTY_MAP.keys()) PRETTY_OPTIONS = list(PRETTY_MAP.keys())
@ -64,12 +64,11 @@ def test_pretty_options_with_and_without_stream_with_converter(pretty, stream):
# Cover PluginManager.__repr__() # Cover PluginManager.__repr__()
assert 'SortJSONConverterPlugin' in str(plugin_manager) assert 'SortJSONConverterPlugin' in str(plugin_manager)
url = 'http://example.org' # Note: URL never fetched
body = b'\x00{"foo":42,\n"bar":"baz"}' body = b'\x00{"foo":42,\n"bar":"baz"}'
responses.add(responses.GET, url, body=body, responses.add(responses.GET, URL_EXAMPLE, body=body,
stream=True, content_type='json/bytes') stream=True, content_type='json/bytes')
args = ['--pretty=' + pretty, 'GET', url] args = ['--pretty=' + pretty, 'GET', URL_EXAMPLE]
if stream: if stream:
args.insert(0, '--stream') args.insert(0, '--stream')
r = http(*args) r = http(*args)

View File

@ -33,6 +33,8 @@ HTTP_OK_COLOR = (
'\x1b[39m\x1b[38;5;245m \x1b[39m\x1b[38;5;136mOK' '\x1b[39m\x1b[38;5;245m \x1b[39m\x1b[38;5;136mOK'
) )
URL_EXAMPLE = 'http://example.org' # Note: URL never fetched
def mk_config_dir() -> Path: def mk_config_dir() -> Path:
dirname = tempfile.mkdtemp(prefix='httpie_config_') dirname = tempfile.mkdtemp(prefix='httpie_config_')