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/>.
|
|
|
|
|
2016-04-05 11:42:42 +02:00
|
|
|
import os
|
2016-08-03 17:55:52 +02:00
|
|
|
import sys
|
2016-08-04 01:41:50 +02:00
|
|
|
import shlex
|
2016-04-05 11:42:42 +02:00
|
|
|
|
2015-11-09 07:49:11 +01:00
|
|
|
import pytest_bdd as bdd
|
|
|
|
bdd.scenarios('downloads.feature')
|
|
|
|
|
|
|
|
|
2016-03-14 19:06:16 +01:00
|
|
|
@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
|
|
|
|
|
|
|
|
2016-07-05 08:34:03 +02:00
|
|
|
@bdd.when("I download an SSL page")
|
2016-05-05 00:04:58 +02:00
|
|
|
def download_ssl_page(quteproc, ssl_server):
|
|
|
|
quteproc.send_cmd(':download https://localhost:{}/'
|
|
|
|
.format(ssl_server.port))
|
|
|
|
|
|
|
|
|
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()
|
2016-04-05 11:42:42 +02:00
|
|
|
|
|
|
|
|
2016-04-05 12:40:46 +02:00
|
|
|
@bdd.then(bdd.parsers.parse('The download prompt should be shown with '
|
|
|
|
'"{path}"'))
|
2016-04-05 11:42:42 +02:00
|
|
|
def download_prompt(tmpdir, quteproc, path):
|
|
|
|
full_path = path.replace('{downloaddir}', str(tmpdir)).replace('/', os.sep)
|
|
|
|
msg = ("Asking question <qutebrowser.utils.usertypes.Question "
|
2016-07-06 23:16:38 +02:00
|
|
|
"default={full_path!r} mode=<PromptMode.download: 5> "
|
2016-04-05 11:42:42 +02:00
|
|
|
"text='Save file to:'>, *".format(full_path=full_path))
|
|
|
|
quteproc.wait_for(message=msg)
|
|
|
|
quteproc.send_cmd(':leave-mode')
|
2016-08-03 17:55:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
@bdd.when("I open the download")
|
|
|
|
def download_open(quteproc):
|
2016-08-04 01:41:50 +02:00
|
|
|
cmd = '{} -c pass'.format(shlex.quote(sys.executable))
|
2016-08-03 17:55:52 +02:00
|
|
|
quteproc.send_cmd(':download-open {}'.format(cmd))
|
|
|
|
|
|
|
|
@bdd.when("I directly open the download")
|
|
|
|
def download_open(quteproc):
|
2016-08-04 01:41:50 +02:00
|
|
|
cmd = '{} -c pass'.format(shlex.quote(sys.executable))
|
2016-08-03 17:55:52 +02:00
|
|
|
quteproc.send_cmd(':prompt-open-download {}'.format(cmd))
|