Skip tests with permission changes if they didn't work
This e.g. wouldn't work inside of a Docker container otherwise.
This commit is contained in:
parent
2f26490536
commit
3b53ec1cb6
@ -579,9 +579,9 @@ Feature: Downloading things from a website.
|
|||||||
And I wait until the download is finished
|
And I wait until the download is finished
|
||||||
Then the downloaded file content-size should exist
|
Then the downloaded file content-size should exist
|
||||||
|
|
||||||
@posix
|
|
||||||
Scenario: Downloading to unwritable destination
|
Scenario: Downloading to unwritable destination
|
||||||
When I set storage -> prompt-download-directory to false
|
When the unwritable dir is unwritable
|
||||||
|
And I set storage -> prompt-download-directory to false
|
||||||
And I run :download http://localhost:(port)/data/downloads/download.bin --dest (tmpdir)/downloads/unwritable
|
And I run :download http://localhost:(port)/data/downloads/download.bin --dest (tmpdir)/downloads/unwritable
|
||||||
Then the error "Download error: Permission denied" should be shown
|
Then the error "Download error: Permission denied" should be shown
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
|
import pytest
|
||||||
import pytest_bdd as bdd
|
import pytest_bdd as bdd
|
||||||
bdd.scenarios('downloads.feature')
|
bdd.scenarios('downloads.feature')
|
||||||
|
|
||||||
@ -53,6 +54,14 @@ def clean_old_downloads(quteproc):
|
|||||||
quteproc.send_cmd(':download-clear')
|
quteproc.send_cmd(':download-clear')
|
||||||
|
|
||||||
|
|
||||||
|
@bdd.when("the unwritable dir is unwritable")
|
||||||
|
def check_unwritable(tmpdir):
|
||||||
|
unwritable = tmpdir / 'downloads' / 'unwritable'
|
||||||
|
if os.access(str(unwritable), os.W_OK):
|
||||||
|
# Docker container or similar
|
||||||
|
pytest.skip("Unwritable dir was writable")
|
||||||
|
|
||||||
|
|
||||||
@bdd.when("I wait until the download is finished")
|
@bdd.when("I wait until the download is finished")
|
||||||
def wait_for_download_finished(quteproc):
|
def wait_for_download_finished(quteproc):
|
||||||
quteproc.wait_for(category='downloads', message='Download * finished')
|
quteproc.wait_for(category='downloads', message='Download * finished')
|
||||||
|
@ -123,24 +123,30 @@ class TestFileHandling:
|
|||||||
|
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
|
||||||
@pytest.mark.posix
|
|
||||||
def test_unreadable(self, message_mock, editor, caplog):
|
def test_unreadable(self, message_mock, editor, caplog):
|
||||||
"""Test file handling when closing with an unreadable file."""
|
"""Test file handling when closing with an unreadable file."""
|
||||||
editor.edit("")
|
editor.edit("")
|
||||||
filename = editor._file.name
|
filename = editor._file.name
|
||||||
assert os.path.exists(filename)
|
assert os.path.exists(filename)
|
||||||
os.chmod(filename, 0o077)
|
os.chmod(filename, 0o077)
|
||||||
|
if os.access(filename, os.R_OK):
|
||||||
|
# Docker container or similar
|
||||||
|
pytest.skip("File was still readable")
|
||||||
|
|
||||||
with caplog.at_level(logging.ERROR):
|
with caplog.at_level(logging.ERROR):
|
||||||
editor._proc.finished.emit(0, QProcess.NormalExit)
|
editor._proc.finished.emit(0, QProcess.NormalExit)
|
||||||
assert not os.path.exists(filename)
|
assert not os.path.exists(filename)
|
||||||
msg = message_mock.getmsg(usertypes.MessageLevel.error)
|
msg = message_mock.getmsg(usertypes.MessageLevel.error)
|
||||||
assert msg.text.startswith("Failed to read back edited file: ")
|
assert msg.text.startswith("Failed to read back edited file: ")
|
||||||
|
|
||||||
@pytest.mark.posix
|
|
||||||
def test_unwritable(self, monkeypatch, message_mock, editor, tmpdir,
|
def test_unwritable(self, monkeypatch, message_mock, editor, tmpdir,
|
||||||
caplog):
|
caplog):
|
||||||
"""Test file handling when the initial file is not writable."""
|
"""Test file handling when the initial file is not writable."""
|
||||||
tmpdir.chmod(0)
|
tmpdir.chmod(0)
|
||||||
|
if os.access(str(tmpdir), os.W_OK):
|
||||||
|
# Docker container or similar
|
||||||
|
pytest.skip("File was still writable")
|
||||||
|
|
||||||
monkeypatch.setattr(editormod.tempfile, 'tempdir', str(tmpdir))
|
monkeypatch.setattr(editormod.tempfile, 'tempdir', str(tmpdir))
|
||||||
|
|
||||||
with caplog.at_level(logging.ERROR):
|
with caplog.at_level(logging.ERROR):
|
||||||
|
Loading…
Reference in New Issue
Block a user