2021-02-17 02:14:58 +00:00
|
|
|
import pytest
|
2021-02-17 01:58:42 +00:00
|
|
|
from PyQt5 import QtCore
|
2021-10-04 11:31:41 +00:00
|
|
|
import vorta.borg.borg_job
|
2021-02-17 01:58:42 +00:00
|
|
|
import vorta.application
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_perm_error(qapp, borg_json_output, mocker, qtbot):
|
|
|
|
main = qapp.main_window
|
|
|
|
mocker.patch.object(vorta.application.QMessageBox, 'show')
|
|
|
|
|
|
|
|
stdout, stderr = borg_json_output('create_perm')
|
|
|
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
2021-10-04 11:31:41 +00:00
|
|
|
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
|
2021-02-17 01:58:42 +00:00
|
|
|
|
|
|
|
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
|
|
|
|
|
2021-02-17 02:14:58 +00:00
|
|
|
qtbot.waitUntil(lambda: hasattr(qapp, '_msg'), **pytest._wait_defaults)
|
2021-02-17 01:58:42 +00:00
|
|
|
assert qapp._msg.text().startswith("You do not have permission")
|
|
|
|
del qapp._msg
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_lock(qapp, borg_json_output, mocker, qtbot):
|
|
|
|
main = qapp.main_window
|
|
|
|
mocker.patch.object(vorta.application.QMessageBox, 'show')
|
|
|
|
|
|
|
|
# Trigger locked repo
|
|
|
|
stdout, stderr = borg_json_output('create_lock')
|
|
|
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
2021-10-04 11:31:41 +00:00
|
|
|
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
|
2021-02-17 01:58:42 +00:00
|
|
|
|
|
|
|
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
|
|
|
|
|
2021-02-17 02:14:58 +00:00
|
|
|
qtbot.waitUntil(lambda: hasattr(qapp, '_msg'), **pytest._wait_defaults)
|
2021-02-17 01:58:42 +00:00
|
|
|
assert "The repository at" in qapp._msg.text()
|
|
|
|
|
|
|
|
# Break locked repo
|
|
|
|
stdout, stderr = borg_json_output('create_break')
|
|
|
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
2021-10-04 11:31:41 +00:00
|
|
|
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
|
2021-02-17 01:58:42 +00:00
|
|
|
|
2021-02-17 02:14:58 +00:00
|
|
|
qtbot.waitUntil(lambda: main.createStartBtn.isEnabled(), **pytest._wait_defaults) # Prevent thread collision
|
2021-02-17 01:58:42 +00:00
|
|
|
qapp._msg.accept()
|
|
|
|
exp_message_text = 'Repository lock broken. Please redo your last action.'
|
2021-02-17 02:14:58 +00:00
|
|
|
qtbot.waitUntil(lambda: main.progressText.text() == exp_message_text, **pytest._wait_defaults)
|