mirror of
https://github.com/httpie/cli.git
synced 2024-11-28 08:38:44 +02:00
Added additional tests to verify downloads work properly with quiet flag
This commit is contained in:
parent
c90d039a0b
commit
2c7f24e3e5
@ -191,11 +191,44 @@ class TestDownloads:
|
|||||||
finally:
|
finally:
|
||||||
os.chdir(orig_cwd)
|
os.chdir(orig_cwd)
|
||||||
|
|
||||||
def test_download_with_quiet_flag(self, httpbin_both, httpbin):
|
def test_download_with_quiet_flag(self, httpbin):
|
||||||
robots_txt = '/robots.txt'
|
robots_txt = '/robots.txt'
|
||||||
body = requests.get(httpbin + robots_txt).text
|
expected_body = requests.get(httpbin + robots_txt).text
|
||||||
env = MockEnvironment(stdin_isatty=True, stdout_isatty=False)
|
expected_filename = 'robots.txt'
|
||||||
r = http('--quiet', '--download', httpbin_both.url + robots_txt, env=env)
|
env = MockEnvironment(stdin_isatty=True, stdout_isatty=True)
|
||||||
assert r.stderr == ''
|
orig_cwd = os.getcwd()
|
||||||
assert env.devnull == env.stderr
|
os.chdir(tempfile.mkdtemp(prefix='httpie_download_quiet_test_'))
|
||||||
assert env.devnull == env.stdout
|
try:
|
||||||
|
assert os.listdir('.') == []
|
||||||
|
r = http('--quiet', '--download', httpbin + robots_txt, env=env)
|
||||||
|
assert os.listdir('.') == [expected_filename]
|
||||||
|
assert r.stderr == ''
|
||||||
|
assert env.devnull == env.stderr
|
||||||
|
assert env.devnull == env.stdout
|
||||||
|
with open(expected_filename, 'r') as f:
|
||||||
|
assert f.read() == expected_body
|
||||||
|
finally:
|
||||||
|
os.chdir(orig_cwd)
|
||||||
|
|
||||||
|
def test_download_with_quiet_and_output_flag(self, httpbin):
|
||||||
|
robots_txt = '/robots.txt'
|
||||||
|
expected_body = requests.get(httpbin + robots_txt).text
|
||||||
|
expected_filename = 'test.txt'
|
||||||
|
env = MockEnvironment(stdin_isatty=True, stdout_isatty=True)
|
||||||
|
orig_cwd = os.getcwd()
|
||||||
|
os.chdir(tempfile.mkdtemp(prefix='httpie_download_quiet_test_'))
|
||||||
|
try:
|
||||||
|
assert os.listdir('.') == []
|
||||||
|
r = http('--quiet',
|
||||||
|
'--download',
|
||||||
|
'--output=' + expected_filename,
|
||||||
|
httpbin + robots_txt,
|
||||||
|
env=env)
|
||||||
|
assert os.listdir('.') == [expected_filename]
|
||||||
|
assert r.stderr == ''
|
||||||
|
assert env.devnull == env.stderr
|
||||||
|
assert env.devnull == env.stdout
|
||||||
|
with open(expected_filename, 'r') as f:
|
||||||
|
assert f.read() == expected_body
|
||||||
|
finally:
|
||||||
|
os.chdir(orig_cwd)
|
||||||
|
@ -2,11 +2,13 @@ import argparse
|
|||||||
import mock
|
import mock
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
import io
|
import io
|
||||||
from tempfile import gettempdir
|
from tempfile import gettempdir
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import requests
|
||||||
|
|
||||||
from httpie.cli.argtypes import (
|
from httpie.cli.argtypes import (
|
||||||
PARSED_DEFAULT_FORMAT_OPTIONS,
|
PARSED_DEFAULT_FORMAT_OPTIONS,
|
||||||
@ -80,6 +82,28 @@ class TestQuietFlag:
|
|||||||
assert str(r) == ''
|
assert str(r) == ''
|
||||||
assert r.stderr == ''
|
assert r.stderr == ''
|
||||||
|
|
||||||
|
def test_quiet_flag_with_output_redirection(self, httpbin):
|
||||||
|
robots_txt = '/robots.txt'
|
||||||
|
expected_body = requests.get(httpbin + robots_txt).text
|
||||||
|
expected_filename = 'test.txt'
|
||||||
|
env = MockEnvironment(stdin_isatty=True, stdout_isatty=True)
|
||||||
|
orig_cwd = os.getcwd()
|
||||||
|
os.chdir(tempfile.mkdtemp(prefix='httpie_download_quiet_test_'))
|
||||||
|
try:
|
||||||
|
assert os.listdir('.') == []
|
||||||
|
r = http('--quiet',
|
||||||
|
'--output=' + expected_filename,
|
||||||
|
httpbin + robots_txt,
|
||||||
|
env=env)
|
||||||
|
assert os.listdir('.') == [expected_filename]
|
||||||
|
assert r.stderr == ''
|
||||||
|
assert env.devnull == env.stderr
|
||||||
|
assert env.devnull != env.stdout
|
||||||
|
with open(expected_filename, 'r') as f:
|
||||||
|
assert f.read() == expected_body
|
||||||
|
finally:
|
||||||
|
os.chdir(orig_cwd)
|
||||||
|
|
||||||
|
|
||||||
class TestVerboseFlag:
|
class TestVerboseFlag:
|
||||||
def test_verbose(self, httpbin):
|
def test_verbose(self, httpbin):
|
||||||
|
Loading…
Reference in New Issue
Block a user