From 41b6f68fd71e92f0bbf3b92a14ca41ea7dc5352d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 14 Mar 2016 19:06:42 +0100 Subject: [PATCH] bdd: Add some more tests for downloads --- tests/integration/features/downloads.feature | 74 ++++++++++++++++++++ tests/integration/features/test_downloads.py | 12 ++++ 2 files changed, 86 insertions(+) diff --git a/tests/integration/features/downloads.feature b/tests/integration/features/downloads.feature index da26e8d43..b812514bc 100644 --- a/tests/integration/features/downloads.feature +++ b/tests/integration/features/downloads.feature @@ -87,3 +87,77 @@ Feature: Downloading things from a website. And I run :download --mhtml --dest mhtml-response-headers.mht And I wait for "File successfully written." in the log Then no crash should happen + + ## :download-cancel + + Scenario: Cancelling a download + When I run :download http://localhost:(port)/drip?numbytes=128&duration=5 + And I run :download-cancel + Then "cancelled" should be logged + + Scenario: Cancelling a download which does not exist + When I run :download-cancel with count 42 + Then the error "There's no download 42!" should be shown + + Scenario: Cancelling a download which is already done + When I open data/downloads/download.bin + And I wait until the download is finished + And I run :download-cancel + Then the error "Download 1 is already done!" should be shown + + Scenario: Cancelling a download which is already done (with count) + When I open data/downloads/download.bin + And I wait until the download is finished + And I run :download-cancel with count 1 + Then the error "Download 1 is already done!" should be shown + + Scenario: Cancelling all downloads + When I run :download http://localhost:(port)/drip?numbytes=128&duration=5 + And I run :download http://localhost:(port)/drip?numbytes=128&duration=5 + And I run :download-cancel --all + Then "cancelled" should be logged + And "cancelled" should be logged + + ## :download-delete + + Scenario: Deleting a download + When I open data/downloads/download.bin + And I wait until the download is finished + And I run :download-delete + Then the downloaded file download.bin should not exist + + Scenario: Deleting a download which does not exist + When I run :download-delete with count 42 + Then the error "There's no download 42!" should be shown + + Scenario: Deleting a download which is not done yet + When I run :download http://localhost:(port)/drip?numbytes=128&duration=5 + And I run :download-delete + Then the error "Download 1 is not done!" should be shown + + Scenario: Deleting a download which is not done yet (with count) + When I run :download http://localhost:(port)/drip?numbytes=128&duration=5 + And I run :download-delete with count 1 + Then the error "Download 1 is not done!" should be shown + + ## :download-open + + # Scenario: Opening a download + # When I open data/downloads/download.bin + # And I wait until the download is finished + # And I run :download-open + # Then ... + + Scenario: Opening a download which does not exist + When I run :download-open with count 42 + Then the error "There's no download 42!" should be shown + + Scenario: Opening a download which is not done yet + When I run :download http://localhost:(port)/drip?numbytes=128&duration=5 + And I run :download-open + Then the error "Download 1 is not done!" should be shown + + Scenario: Opening a download which is not done yet (with count) + When I run :download http://localhost:(port)/drip?numbytes=128&duration=5 + And I run :download-open with count 1 + Then the error "Download 1 is not done!" should be shown diff --git a/tests/integration/features/test_downloads.py b/tests/integration/features/test_downloads.py index d2bc7eb7b..51613dc61 100644 --- a/tests/integration/features/test_downloads.py +++ b/tests/integration/features/test_downloads.py @@ -37,3 +37,15 @@ def clean_old_downloads(quteproc): @bdd.when("I wait until the download is finished") def wait_for_download_finished(quteproc): quteproc.wait_for(category='downloads', message='Download finished') + + +@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()