2018-10-30 17:46:37 +00:00
|
|
|
from PyQt5 import QtCore
|
|
|
|
|
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-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
|
|
|
|
2018-11-17 10:34:38 +00:00
|
|
|
def test_create_fail(app, qtbot):
|
2018-11-03 08:55:38 +00:00
|
|
|
main = app.main_window
|
2018-10-30 17:46:37 +00:00
|
|
|
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
|
2018-11-21 13:03:09 +00:00
|
|
|
assert main.createProgressText.text() == 'Add a backup repository first.'
|
2018-10-30 17:46:37 +00:00
|
|
|
|
|
|
|
|
2018-11-06 06:47:04 +00:00
|
|
|
def test_repo_add(app, qtbot, mocker, borg_json_output):
|
2018-10-30 17:46:37 +00:00
|
|
|
# Add new repo window
|
2018-11-03 08:55:38 +00:00
|
|
|
main = app.main_window
|
|
|
|
add_repo_window = AddRepoWindow(main.repoTab)
|
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)
|
|
|
|
assert add_repo_window.errorText.text() == 'Please use a longer password.'
|
|
|
|
|
|
|
|
qtbot.keyClicks(add_repo_window.passwordLineEdit, 'long-password-long')
|
|
|
|
|
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])
|
|
|
|
|
2018-11-04 15:37:46 +00:00
|
|
|
# assert EventLogModel.select().count() == 2
|
2018-10-30 17:46:37 +00:00
|
|
|
assert RepoModel.get(id=1).url == 'aaabbb.com:repo'
|
2018-11-03 08:55:38 +00:00
|
|
|
|
2018-11-22 00:43:37 +00:00
|
|
|
|
2018-11-06 06:47:04 +00:00
|
|
|
def test_create(app_with_repo, borg_json_output, mocker, qtbot):
|
|
|
|
main = app_with_repo.main_window
|
|
|
|
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
|
2018-11-22 01:35:59 +00:00
|
|
|
assert ArchiveModel.select().count() == 1
|
2018-11-06 06:47:04 +00:00
|
|
|
assert RepoModel.get(id=1).unique_size == 15520474
|
|
|
|
assert main.createStartBtn.isEnabled()
|
2018-11-22 01:18:12 +00:00
|
|
|
assert main.archiveTab.archiveTable.rowCount() == 1
|
2018-11-06 06:47:04 +00:00
|
|
|
assert main.scheduleTab.logTableWidget.rowCount() == 1
|