1
0
mirror of https://github.com/httpie/cli.git synced 2025-08-10 22:42:05 +02:00

Changed the way the output filename is generated

When ``--download`` without ``--output`` results in a redirect,
now only the initial URL is considered, not the final one.
This commit is contained in:
Jakub Roztocil
2019-06-24 12:19:29 +02:00
parent e92b831e6e
commit df36d6255d
4 changed files with 64 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
import os
import tempfile
import time
import pytest
@@ -22,6 +23,7 @@ class Response(object):
class TestDownloadUtils:
def test_Content_Range_parsing(self):
parse = parse_content_range
@@ -166,3 +168,15 @@ class TestDownloads:
downloader.finish()
assert downloader.interrupted
downloader._progress_reporter.join()
def test_download_with_redirect_original_url_used_for_filename(self, httpbin):
# Redirect from `/redirect/1` to `/get`.
expected_filename = '1.json'
orig_cwd = os.getcwd()
os.chdir(tempfile.mkdtemp(prefix='httpie_download_test_'))
try:
assert os.listdir('.') == []
http('--download', httpbin.url + '/redirect/1')
assert os.listdir('.') == [expected_filename]
finally:
os.chdir(orig_cwd)