2018-11-30 00:40:18 +00:00
|
|
|
import os
|
2018-12-04 02:58:12 +00:00
|
|
|
import uuid
|
2018-10-30 17:46:37 +00:00
|
|
|
from PyQt5 import QtCore
|
2018-12-04 02:58:12 +00:00
|
|
|
from PyQt5.QtWidgets import QMessageBox
|
2018-10-30 17:46:37 +00:00
|
|
|
|
2018-11-03 08:55:38 +00:00
|
|
|
import vorta.borg.borg_thread
|
2018-10-30 17:46:37 +00:00
|
|
|
import vorta.models
|
2018-11-27 11:33:16 +00:00
|
|
|
from vorta.views.repo_add_dialog import AddRepoWindow
|
2018-11-30 00:40:18 +00:00
|
|
|
from vorta.views.ssh_dialog import SSHAddWindow
|
2018-11-22 01:35:59 +00:00
|
|
|
from vorta.models import EventLogModel, RepoModel, ArchiveModel
|
2018-10-30 17:46:37 +00:00
|
|
|
|
2018-11-05 10:30:59 +00:00
|
|
|
|
2020-03-03 05:19:36 +00:00
|
|
|
def test_repo_add_failures(qapp, qtbot, mocker, borg_json_output):
|
2018-10-30 17:46:37 +00:00
|
|
|
# Add new repo window
|
2020-03-03 05:19:36 +00:00
|
|
|
main = qapp.main_window
|
2018-12-04 02:58:12 +00:00
|
|
|
add_repo_window = AddRepoWindow(main)
|
|
|
|
qtbot.addWidget(add_repo_window)
|
|
|
|
|
2018-10-30 17:46:37 +00:00
|
|
|
qtbot.keyClicks(add_repo_window.repoURL, 'aaa')
|
|
|
|
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.LeftButton)
|
2018-11-17 11:36:44 +00:00
|
|
|
assert add_repo_window.errorText.text().startswith('Please enter a valid')
|
2018-10-30 17:46:37 +00:00
|
|
|
|
|
|
|
qtbot.keyClicks(add_repo_window.repoURL, 'bbb.com:repo')
|
|
|
|
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.LeftButton)
|
2019-06-22 01:35:53 +00:00
|
|
|
assert add_repo_window.errorText.text() == 'Please use a longer passphrase.'
|
2018-10-30 17:46:37 +00:00
|
|
|
|
2018-12-04 02:58:12 +00:00
|
|
|
|
2020-03-03 05:19:36 +00:00
|
|
|
def test_repo_unlink(qapp, qtbot, monkeypatch):
|
|
|
|
monkeypatch.setattr(QMessageBox, "exec_", lambda *args: QMessageBox.Yes)
|
|
|
|
main = qapp.main_window
|
|
|
|
tab = main.repoTab
|
|
|
|
|
|
|
|
main.tabWidget.setCurrentIndex(0)
|
|
|
|
qtbot.mouseClick(tab.repoRemoveToolbutton, QtCore.Qt.LeftButton)
|
|
|
|
qtbot.waitUntil(lambda: tab.repoSelector.count() == 4, timeout=5000)
|
|
|
|
assert RepoModel.select().count() == 0
|
|
|
|
|
|
|
|
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
|
|
|
|
assert main.createProgressText.text() == 'Add a backup repository first.'
|
|
|
|
|
|
|
|
|
|
|
|
def test_repo_add_success(qapp, qtbot, mocker, borg_json_output):
|
2018-12-14 08:03:26 +00:00
|
|
|
LONG_PASSWORD = 'long-password-long'
|
2020-03-03 05:19:36 +00:00
|
|
|
|
2018-12-04 02:58:12 +00:00
|
|
|
# Add new repo window
|
2020-03-03 05:19:36 +00:00
|
|
|
main = qapp.main_window
|
|
|
|
main.repoTab.repo_added.disconnect()
|
2018-12-04 02:58:12 +00:00
|
|
|
add_repo_window = AddRepoWindow(main)
|
|
|
|
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain
|
|
|
|
|
|
|
|
qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
|
2018-12-14 08:03:26 +00:00
|
|
|
qtbot.keyClicks(add_repo_window.passwordLineEdit, LONG_PASSWORD)
|
2018-10-30 17:46:37 +00:00
|
|
|
|
2018-11-06 06:47:04 +00:00
|
|
|
stdout, stderr = borg_json_output('info')
|
2018-11-22 00:43:37 +00:00
|
|
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
2018-11-03 08:55:38 +00:00
|
|
|
mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result)
|
2018-10-30 17:46:37 +00:00
|
|
|
|
|
|
|
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.LeftButton)
|
|
|
|
|
2018-11-27 11:33:16 +00:00
|
|
|
with qtbot.waitSignal(add_repo_window.thread.result, timeout=3000) as blocker:
|
2018-10-30 17:46:37 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
main.repoTab.process_new_repo(blocker.args[0])
|
|
|
|
|
2020-03-03 05:19:36 +00:00
|
|
|
assert EventLogModel.select().count() == 1
|
2018-12-04 02:58:12 +00:00
|
|
|
assert RepoModel.get(id=2).url == test_repo_url
|
2018-11-03 08:55:38 +00:00
|
|
|
|
2018-12-14 08:03:26 +00:00
|
|
|
from vorta.utils import keyring
|
|
|
|
assert keyring.get_password("vorta-repo", RepoModel.get(id=2).url) == LONG_PASSWORD
|
|
|
|
|
2018-11-22 00:43:37 +00:00
|
|
|
|
2018-11-30 00:40:18 +00:00
|
|
|
def test_ssh_dialog(qtbot, tmpdir):
|
|
|
|
ssh_dialog = SSHAddWindow()
|
|
|
|
ssh_dir = tmpdir
|
|
|
|
key_tmpfile = ssh_dir.join("id_rsa-test")
|
|
|
|
pub_tmpfile = ssh_dir.join("id_rsa-test.pub")
|
|
|
|
key_tmpfile_full = os.path.join(key_tmpfile.dirname, key_tmpfile.basename)
|
|
|
|
ssh_dialog.outputFileTextBox.setText(key_tmpfile_full)
|
|
|
|
qtbot.mouseClick(ssh_dialog.generateButton, QtCore.Qt.LeftButton)
|
|
|
|
|
|
|
|
qtbot.waitUntil(lambda: key_tmpfile.check(file=1))
|
2020-03-03 05:19:36 +00:00
|
|
|
qtbot.waitUntil(lambda: pub_tmpfile.check(file=1))
|
2018-11-30 00:40:18 +00:00
|
|
|
|
|
|
|
key_tmpfile_content = key_tmpfile.read()
|
|
|
|
pub_tmpfile_content = pub_tmpfile.read()
|
|
|
|
assert key_tmpfile_content.startswith('-----BEGIN OPENSSH PRIVATE KEY-----')
|
|
|
|
assert pub_tmpfile_content.startswith('ssh-ed25519')
|
|
|
|
qtbot.waitUntil(lambda: ssh_dialog.errors.text().startswith('New key was copied'))
|
|
|
|
|
|
|
|
qtbot.mouseClick(ssh_dialog.generateButton, QtCore.Qt.LeftButton)
|
|
|
|
qtbot.waitUntil(lambda: ssh_dialog.errors.text().startswith('Key file already'))
|
|
|
|
|
|
|
|
|
2020-03-03 05:19:36 +00:00
|
|
|
def test_create(qapp, borg_json_output, mocker, qtbot):
|
|
|
|
main = qapp.main_window
|
2018-11-06 06:47:04 +00:00
|
|
|
stdout, stderr = borg_json_output('create')
|
2018-11-22 00:43:37 +00:00
|
|
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
2018-11-06 06:47:04 +00:00
|
|
|
mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result)
|
|
|
|
|
|
|
|
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
|
2018-11-27 11:33:16 +00:00
|
|
|
qtbot.waitUntil(lambda: main.createProgressText.text().startswith('Backup finished.'), timeout=3000)
|
|
|
|
qtbot.waitUntil(lambda: main.createStartBtn.isEnabled(), timeout=3000)
|
2018-11-06 06:47:04 +00:00
|
|
|
assert EventLogModel.select().count() == 1
|
2020-03-23 06:20:09 +00:00
|
|
|
assert ArchiveModel.select().count() == 3
|
2018-11-06 06:47:04 +00:00
|
|
|
assert RepoModel.get(id=1).unique_size == 15520474
|
|
|
|
assert main.createStartBtn.isEnabled()
|
2020-03-23 06:20:09 +00:00
|
|
|
assert main.archiveTab.archiveTable.rowCount() == 3
|
2018-11-06 06:47:04 +00:00
|
|
|
assert main.scheduleTab.logTableWidget.rowCount() == 1
|