Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Nov 24, 2019
1 parent 52ef1a8 commit 6538d11
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/unit/test_operations_prepare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import hashlib
import logging
import os
import shutil
import sys
Expand All @@ -16,6 +17,7 @@
Downloader,
_copy_source_tree,
_download_http_url,
_prepare_download,
parse_content_disposition,
sanitize_content_filename,
unpack_file_url,
Expand Down Expand Up @@ -246,6 +248,36 @@ def test_download_http_url__no_directory_traversal(tmpdir):
assert actual == ['out_dir_file']


@pytest.mark.parametrize("url, headers, from_cache, expected", [
('http://example.com/foo.tgz', {}, False,
"Downloading http://example.com/foo.tgz"),
('http://example.com/foo.tgz', {'content-length': 2}, False,
"Downloading http://example.com/foo.tgz (2bytes)"),
('http://example.com/foo.tgz', {'content-length': 2}, True,
"Using cached http://example.com/foo.tgz (2bytes)"),
('https://files.pythonhosted.org/foo.tgz', {}, False,
"Downloading foo.tgz"),
('https://files.pythonhosted.org/foo.tgz', {'content-length': 2}, False,
"Downloading foo.tgz (2bytes)"),
('https://files.pythonhosted.org/foo.tgz', {'content-length': 2}, True,
"Using cached foo.tgz"),
])
def test_prepare_download__log(caplog, url, headers, from_cache, expected):
caplog.set_level(logging.INFO)
resp = MockResponse(b'')
resp.url = url
resp.headers = headers
if from_cache:
resp.from_cache = from_cache
link = Link(url)
_prepare_download(resp, link, progress_bar="on")

assert len(caplog.records) == 1
record = caplog.records[0]
assert record.levelname == 'INFO'
assert expected in record.message


@pytest.fixture
def clean_project(tmpdir_factory, data):
tmpdir = Path(str(tmpdir_factory.mktemp("clean_project")))
Expand Down

0 comments on commit 6538d11

Please sign in to comment.