Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create(app, borg_json_output, mocker, qtbot):
main = app.main_window
stdout, stderr = borg_json_output('create')
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result)
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
qtbot.waitUntil(lambda: main.createProgressText.text().startswith('Backup finished.'), timeout=3000)
qtbot.waitUntil(lambda: main.createStartBtn.isEnabled(), timeout=3000)
assert EventLogModel.select().count() == 1
assert ArchiveModel.select().count() == 2
assert RepoModel.get(id=1).unique_size == 15520474
assert main.createStartBtn.isEnabled()
assert main.archiveTab.archiveTable.rowCount() == 2
assert main.scheduleTab.logTableWidget.rowCount() == 1
def test_repo_list(app, qtbot, mocker, borg_json_output):
main = app.main_window
tab = main.archiveTab
main.tabWidget.setCurrentIndex(3)
tab.list_action()
assert not tab.checkButton.isEnabled()
stdout, stderr = borg_json_output('list')
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result)
qtbot.waitUntil(lambda: main.createProgressText.text() == 'Refreshing archives done.', timeout=3000)
assert ArchiveModel.select().count() == 6
assert main.createProgressText.text() == 'Refreshing archives done.'
assert tab.checkButton.isEnabled()
def test_repo_unlink(app, qtbot, monkeypatch):
monkeypatch.setattr(QMessageBox, "exec_", lambda *args: QMessageBox.Yes)
main = app.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.'
qtbot.keyClicks(add_repo_window.passwordLineEdit, LONG_PASSWORD)
stdout, stderr = borg_json_output('info')
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result)
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.LeftButton)
with qtbot.waitSignal(add_repo_window.thread.result, timeout=3000) as blocker:
pass
main.repoTab.process_new_repo(blocker.args[0])
qtbot.waitUntil(lambda: EventLogModel.select().count() == 2)
assert EventLogModel.select().count() == 2
assert RepoModel.get(id=2).url == test_repo_url
from vorta.utils import keyring
assert keyring.get_password("vorta-repo", RepoModel.get(id=2).url) == LONG_PASSWORD
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result)
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.LeftButton)
with qtbot.waitSignal(add_repo_window.thread.result, timeout=3000) as blocker:
pass
main.repoTab.process_new_repo(blocker.args[0])
qtbot.waitUntil(lambda: EventLogModel.select().count() == 2)
assert EventLogModel.select().count() == 2
assert RepoModel.get(id=2).url == test_repo_url
from vorta.utils import keyring
assert keyring.get_password("vorta-repo", RepoModel.get(id=2).url) == LONG_PASSWORD
def test_create(app, borg_json_output, mocker, qtbot):
main = app.main_window
stdout, stderr = borg_json_output('create')
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result)
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
qtbot.waitUntil(lambda: main.createProgressText.text().startswith('Backup finished.'), timeout=3000)
qtbot.waitUntil(lambda: main.createStartBtn.isEnabled(), timeout=3000)
assert EventLogModel.select().count() == 1
assert ArchiveModel.select().count() == 2
assert RepoModel.get(id=1).unique_size == 15520474
assert main.createStartBtn.isEnabled()
assert main.archiveTab.archiveTable.rowCount() == 2
assert main.scheduleTab.logTableWidget.rowCount() == 1
qtbot.waitUntil(lambda: EventLogModel.select().count() == 2)
assert EventLogModel.select().count() == 2
def test_create(app, borg_json_output, mocker, qtbot):
main = app.main_window
stdout, stderr = borg_json_output('create')
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result)
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
qtbot.waitUntil(lambda: main.createProgressText.text().startswith('Backup finished.'), timeout=3000)
qtbot.waitUntil(lambda: main.createStartBtn.isEnabled(), timeout=3000)
assert EventLogModel.select().count() == 1
assert ArchiveModel.select().count() == 2
assert RepoModel.get(id=1).unique_size == 15520474
assert main.createStartBtn.isEnabled()
assert main.archiveTab.archiveTable.rowCount() == 2
assert main.scheduleTab.logTableWidget.rowCount() == 1
def test_prune_intervals(app, qtbot):
prune_intervals = ['hour', 'day', 'week', 'month', 'year']
main = app.main_window
tab = main.archiveTab
profile = BackupProfileModel.get(id=1)
for i in prune_intervals:
getattr(tab, f'prune_{i}').setValue(9)
tab.save_prune_setting(None)
profile = profile.refresh()
assert getattr(profile, f'prune_{i}') == 9
def app(tmpdir):
tmp_db = tmpdir.join('settings.sqlite')
mock_db = peewee.SqliteDatabase(str(tmp_db))
vorta.models.init_db(mock_db)
return VortaApp([])