qutebrowser/tests/integration/features/test_downloads.py

64 lines
2.3 KiB
Python
Raw Normal View History

2015-11-09 07:49:11 +01:00
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
2016-01-04 07:12:39 +01:00
# Copyright 2015-2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
2015-11-09 07:49:11 +01:00
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import os
2015-11-09 07:49:11 +01:00
import pytest_bdd as bdd
bdd.scenarios('downloads.feature')
@bdd.given("I set up a temporary download dir")
def temporary_download_dir(quteproc, tmpdir):
quteproc.set_setting('storage', 'prompt-download-directory', 'false')
quteproc.set_setting('storage', 'remember-download-directory', 'false')
quteproc.set_setting('storage', 'download-directory', str(tmpdir))
@bdd.given("I clean old downloads")
def clean_old_downloads(quteproc):
quteproc.send_cmd(':download-cancel --all')
quteproc.send_cmd(':download-clear')
2015-11-09 07:49:11 +01:00
@bdd.when("I wait until the download is finished")
def wait_for_download_finished(quteproc):
quteproc.wait_for(category='downloads', message='Download finished')
2016-03-14 19:06:42 +01:00
@bdd.then(bdd.parsers.parse("The downloaded file {filename} should not exist"))
def download_should_not_exist(filename, tmpdir):
path = tmpdir / filename
assert not path.check()
@bdd.then(bdd.parsers.parse("The downloaded file {filename} should exist"))
def download_should_exist(filename, tmpdir):
path = tmpdir / filename
assert path.check()
@bdd.then(bdd.parsers.parse('The download prompt should be shown with "{path}"'))
def download_prompt(tmpdir, quteproc, path):
full_path = path.replace('{downloaddir}', str(tmpdir)).replace('/', os.sep)
msg = ("Asking question <qutebrowser.utils.usertypes.Question "
"default='{full_path}' mode=<PromptMode.text: 2> "
"text='Save file to:'>, *".format(full_path=full_path))
quteproc.wait_for(message=msg)
quteproc.send_cmd(':leave-mode')