Add unit test for sanitized download filenames.

I think this covers the right path despite not using either of the
backend specific download code. They both either call `set_target()`
directly with a guessed filename or from the prompt question. When
called directly though that basename set by `_init_item()` is used.

It's a little high level but we already know that sanitize_filenames
does, I wanted to test that it gets called.
This commit is contained in:
Jimmy 2018-06-04 10:57:16 +12:00
parent 75c6e087c7
commit 2510fde80f

View File

@ -96,3 +96,24 @@ class TestDownloadTarget:
]) ])
def test_class_hierarchy(self, obj): def test_class_hierarchy(self, obj):
assert isinstance(obj, downloads._DownloadTarget) assert isinstance(obj, downloads._DownloadTarget)
@pytest.mark.parametrize('raw, expected', [
('http://foo/bar', 'bar'),
('A *|<>\\: bear!', 'A ______ bear!')
])
def test_sanitized_filenames(raw, expected, config_stub, download_tmpdir):
manager = downloads.AbstractDownloadManager()
target = downloads.FileDownloadTarget(download_tmpdir)
item = downloads.AbstractDownloadItem()
# Don't try to start a timer outside of a QThread
manager._update_timer.isActive = lambda: True
# Abstract methods
item._ensure_can_set_filename = lambda *args: True
item._after_set_filename = lambda *args: True
manager._init_item(item, True, raw)
item.set_target(target)
assert item._filename.endswith(expected)