mirror of
https://github.com/httpie/cli.git
synced 2024-11-24 08:22:22 +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:
|
||||
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'
|
||||
body = requests.get(httpbin + robots_txt).text
|
||||
env = MockEnvironment(stdin_isatty=True, stdout_isatty=False)
|
||||
r = http('--quiet', '--download', httpbin_both.url + robots_txt, env=env)
|
||||
assert r.stderr == ''
|
||||
assert env.devnull == env.stderr
|
||||
assert env.devnull == env.stdout
|
||||
expected_body = requests.get(httpbin + robots_txt).text
|
||||
expected_filename = 'robots.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', 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 json
|
||||
import os
|
||||
import tempfile
|
||||
import io
|
||||
from tempfile import gettempdir
|
||||
from urllib.request import urlopen
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from httpie.cli.argtypes import (
|
||||
PARSED_DEFAULT_FORMAT_OPTIONS,
|
||||
@ -80,6 +82,28 @@ class TestQuietFlag:
|
||||
assert str(r) == ''
|
||||
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:
|
||||
def test_verbose(self, httpbin):
|
||||
|
Loading…
Reference in New Issue
Block a user