1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-23 00:07:58 +00:00
vorta/tests/unit/test_repo.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

308 lines
12 KiB
Python
Raw Normal View History

import os
import uuid
from typing import Any, Dict
import pytest
import vorta.borg.borg_job
from PyQt6 import QtCore
from PyQt6.QtWidgets import QMessageBox
from vorta.keyring.abc import VortaKeyring
Improve UX and HIG-conformity. By @real-yfprojects (#1176) * Remove fullstops in the labels of the settings. * src/vorta/store/settings.py (get_misc_setting): Remove fullstops in the `label` fields of each setting. * Fix *Add Profile*-Dialog. * src/vorta/assets/UI/profileadd.ui (label_2): Rename to `profileExplainer`. * src/vorta/assets/UI/profileadd.ui (profileExplainer): Remove unnecessary text and rephrase it in simpler terms. * src/vorta/assets/UI/profileadd.ui (formLayout): Move into frame for better layout in dialog. * src/vorta/assets/UI/profileadd.ui (Dialog): Make dialog modal. * src/vorta/assets/UI/profileadd.ui : Modify spacing a bit and change all widgets to `expanding` mode. * src/vorta/assets/UI/profileadd.ui (Dialog): Set title to `Add Profile`. * src/vorta/assets/UI/profileadd.ui : Make `label_3` a buddy of `profileNameField`. * Add colon after entry label in `Add Profile`-Dialog. * src/vorta/assets/UI/profileadd.ui (label_3): Add colon at the end of label. * Fix capitalization in schedule tab. * src/vorta/assets/UI/scheduletab.ui (pruneCheckBox): Replace `Archive` by `archive`. * Fix tooltips. Ensure sentence capitalization. Rephrase some tooltips that do not mention the action they provide a tip for. (There are still many to go.) Remove fullstop from tooltips that aren't a sentence. Add fullstop to tooltips that are a sentence. * src/vorta/assets/UI/archivetab.ui * src/vorta/assets/UI/mainwindow.ui * src/vorta/assets/UI/repoadd.ui * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/sourcetab.ui * src/vorta/views/export_window.py * src/vorta/views/import_window.py * src/vorta/views/source_tab.py * Replace `n't` by `not` in GUI strings. * src/vorta/application.py * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/scheduletab.ui * src/vorta/assets/UI/sshadd.ui * src/vorta/notifications.py * src/vorta/views/main_window.py * src/vorta/views/main_window.py * src/vorta/views/repo_tab.py * Shorten unlink button tooltip. * src/vorta/assets/UI/repotab.ui (repoRemoveToolbutton): Shorten tooltip by only keeping the most valuable information needed to understand the feature. * Fix entry being embedded in label text. Sentences should not be constructed from text in several controls. Sentences that run from one control to another will often not make sense when translated into other languages. * src/vorta/assets/UI/archivetab.ui * src/vorta/assets/UI/scheduletab.ui * Rewrite tooltips to make them HIG conform. The KDE HIG was used. * src/vorta/assets/UI/exportwindow.ui * src/vorta/assets/UI/importwindow.ui * src/vorta/assets/UI/mainwindow.ui * src/vorta/assets/UI/repoadd.ui * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/sourcetab.ui * src/vorta/views/export_window.py * src/vorta/views/import_window.py (ImportWindow.init_overwrite_profile_checkbox): Make tooltip static as the HIG suggests. * src/vorta/views/main_window.py * Replace `...` with unicode ellipses `…` (U+2028) in GUI text. * src/vorta/borg/break_lock.py * src/vorta/borg/check.py * src/vorta/borg/create.py * src/vorta/borg/delete.py * src/vorta/borg/diff.py * src/vorta/borg/extract.py * src/vorta/borg/info_archive.py * src/vorta/borg/info_repo.py * src/vorta/borg/init.py * src/vorta/borg/list_archive.py * src/vorta/borg/list_archive.py * src/vorta/borg/list_repo.py * Clean prune tab in `archivetab.ui`. * src/vorta/assets/UI/archivetab.ui * Prettify `repotab`. * src/vorta/assets/UI/repotab.ui * Fix tooltips for pruning in `archivetab.ui`. * src/vorta/assets/UI/archivetab.ui * Use affirmative phrase in checkbox for metered networks. * src/vorta/assets/UI/scheduletab.ui (dontRunOnMeteredNetworksCheckbox): Rename to `meteredNetworksCheckBox`. * src/vorta/assets/UI/scheduletab.ui (meteredNetworksCheckBox): Change text into affirmative phrase. * src/vorta/views/schedule_tab.py : Invert values for `meteredNetworksCheckBox`. * Add label in shell commands pane in `scheduletab` and fix placeholders. Placeholders shouldn't be a replacement for a label. * src/vorta/assets/UI/scheduletab.ui * Group settings widgets in `misctab`. * src/vorta/assets/UI/misctab.ui (checkboxLayout): Replace with frame `frameSettings` containing a form layout. * src/vorta/utils.py (search): Added. Searches for a key inside an iterable applying a given function before comparison. * src/vorta/store/models.py (SettingsModel): Add field `group` to assign settings to a group. * src/vorta/store/migrations.py (run_migrations): Add new schema version `19` and implement migration adding the `group` field. * src/vorta/store/connection.py (SCHEMA_VERSION): Update to `19`. * src/vorta/store/settings.py (get_misc_settings): Add and assign settings groups. * src/vorta/store/connection.py (init_db): Update group and type of settings if needed. * src/vorta/views/misc_tab.py (Imports): Import `search` from `..utils`. * src/vorta/views/misc_tab.py : Instanciate logger. * src/vorta/views/misc_tab.py (MiscTab.__init__): Create a checkboxLayout for `frameSettings`. * src/vorta/views/misc_tab.py (populate): Add settings widgets in groups with labels in spacer in between. * Fix tests for `misctab`. * tests/test_misc.py * Fix margins. * src/vorta/assets/UI/archivetab.ui * src/vorta/assets/UI/misctab.ui * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/scheduletab.ui * src/vorta/assets/UI/sourcetab.ui * Morph buttons in `sourcetab` into toolbuttons with icons. Adds gradient buttons along the way. Fixes #933. * src/vorta/assets/UI/sourcetab.ui : Change layout and buttons. Merge buttons with adding capabilities into one toolbutton (with menu). * src/vorta/assets/UI/sourcetab.ui : Rename `sourceRemove` to `removeButton`. Rename `sourceUpdate` to `updateButton`. Add `addButton`. * src/vorta/assets/icons/minus.svg : Add minus sign icon from *fontawesome* v6.0. * src/vorta/views/source_tab.py (SourceTab.set_icons): Added. * src/vorta/views/source_tab.py (SourceTab.__init__): Create Menu for the `addButton` with actions to add files and folders and to paste. * src/vorta/application.py (VortaApp.eventFilter): Call `set_icons` of `sourceTab` as well. * Fix tests for `sourcetab`. * tests/test_source.py * Add paste icon to paste action in `sourcetab`. * src/vorta/assets/icons/paste.svg : Added from fontawesome (paste-solid, v6.0) * src/vorta/views/source_tab.py (SourceTab.__init__): Save paste action in `pasteAction`. * src/vorta/views/source_tab.py (SourceTab.set_icons): Set icon for `pasteAction`. * Add icons to open actions in `sourcetab`. * src/vorta/assets/icons/file.svg : Added `file-solid` from fontawesome, v6.0 * src/vorta/assets/icons/folder.svg : Added `folder-solid` from fontawesome, v6.0 * src/vorta/views/source_tab.py (SourceTab.__init__): Save files and folders action to `addFilesAction` and `addFoldersAction`. * src/vorta/views/source_tab.py (SourceTab.set_icons): Set icons for `addFilesAction` and `addFolderAction`. * Fix icon size of `file.svg`. * src/vorta/assets/icons/file.svg * Set fill of added svgs to `#000000`. * src/vorta/assets/icons/file.svg * src/vorta/assets/icons/folder.svg * src/vorta/assets/icons/minus.svg * src/vorta/assets/icons/paste.svg * Improve UX and consistency within the app for `scheduletab`. * src/vorta/assets/UI/scheduletab.ui : Arrange schedule pane in a form layout. * src/vorta/views/schedule_tab.py (ScheduleTab.__init__): Connect enabled state of entries to radiobuttons and checkboxes. * Workaround scheduletab tests being broken in github actions. For some unknown reason clicking the `scheduleFixedRadio` won't work when running using github action on ubuntu. * tests/test_schedule.py * Fix labels and spacing in `scheduletab`. * src/vorta/assets/UI/scheduletab.ui * Make archive operations more accessible and rename actions of `ArchiveTab`. * src/vorta/views/archive_tab.py (ArchiveTab): Rename `list_action` to `refresh_archive_list`. Rename `refresh_archive_action` to `refresh_archive_info`. Rename `refresh_archive_result` to `info_result`. Rename `list_archive_action` to `extract_action`. Rename `list_archive_result` to `extract_list_result`. * src/vorta/views/main_window.py : Apply renaming. * src/vorta/assets/UI/archivetab.ui : Create own buttons for the archive actions. Remove `archiveActionButton`. And some other layout changes. * src/vorta/assets/UI/archivetab.ui : Rename `pruneButton` to `bPrune`. Rename `checkButton` to `bCheck`. Rename `diffButton` to `bDiff`. Rename `listButton` to `bList`. * tests/test_archives.py : Apply renaming. * src/vorta/views/archive_tab.py : Connect new action buttons. * src/vorta/views/archive_tab.py : Remove `archiveActionButton`. * tests/test_archives.py : Fix tests. * Enable and disable archive actions depending on selection. * src/vorta/assets/UI/archivetab.ui : Put archive actions into a frame. * src/vorta/views/archive_tab.py (ArchiveTab): Added `on_selection_change` that enables/disables the frame depending on the selection count. * src/vorta/views/archive_tab.py (ArchiveTab.populate_from_profile): Clear selection. * src/vorta/views/archive_tab.py (ArchiveTab.__toggle_all_buttons): Add `fArchiveActions`. Call `on_selection_change` at the end. * Fix tests for `archivetab`. * tests/test_archives.py * Replace line by spacer in repotab. * src/vorta/assets/UI/repotab.ui * Show labels for archive action buttons. * src/vorta/assets/UI/archivetab.ui * Add tooltips and ellipses to archivetab. * src/vorta/assets/UI/archivetab.ui * src/vorta/views/archive_tab.py * Fix tooltips. * src/vorta/assets/UI/sourcetab.ui : Add tooltips. * src/vorta/views/archive_tab.py (ArchiveTab.on_selection_change): Add reason for disabled state dynamically to archive action buttons. * Add context menu to source view. * src/vorta/views/source_tab.py (SourceTab): Implement `sourceitem_contextmenu` and `source_copy`. Set context menu policiy of `sourceFilesWidget` to `CustomContextMenu`. * src/vorta/assets/UI/sourcetab.ui: Change size hints. * Add context menu to archive view. * src/vorta/views/archive_tab.py (ArchiveTab): Set context menu policy of `archiveTable` to `CustomContextMenu`. Implement `archiveitem_contextmenu`. * Replace `Type` column in sources view by icon. * src/vorta/views/source_tab.py (SourceColumn): Remove `Type` column. * src/vorta/views/source_tab.py (SourceTab.set_icons): Set icon for each item in source view. * src/vorta/views/source_tab.py (SourceTab.set_path_info): Set icon instead of `Type` column. * src/vorta/assets/UI/sourcetab.ui : Remove `Type` column. * Fix initial sort indicator of source view. * src/vorta/views/source_tab.py * Fix adding items while sorting enabled. * src/vorta/views/source_tab.py * Remove status bar and remove fix size hint for log text label. * src/vorta/assets/UI/mainwindow.ui * src/vorta/views/main_window.py (MainWindow.__init__): Set minimum height of `logText` to two times the height of a line calculated by `QFontMetrics`. * Resize main window height to `670`. * src/vorta/assets/UI/mainwindow.ui * Replace `QToolbutton` by `QPushbutton`. * src/vorta/assets/UI/archivetab.ui * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/sourcetab.ui * src/vorta/views/source_tab.py * Fix flake8 * Improve label of entry for `borg create` extra arguments. * src/vorta/assets/UI/scheduletab.ui * Unify label font size in `repotab`. * src/vorta/assets/UI/repotab.ui * Morph `QPushButton`s into `QToolButton`s. Some exceptions were made, especially in the dialog windows. * src/vorta/assets/UI/archivetab.ui * src/vorta/assets/UI/mainwindow.ui * src/vorta/assets/UI/repotab.ui * src/vorta/assets/UI/sourcetab.ui * Add copy capabilities to archive view and a copy shortcut to it and to source tab. * src/vorta/views/source_tab.py (SourceTab): Add QShortcut for copying. * src/vorta/views/archive_tab.py (ArchiveTab.archiveitem_contextmenu): Add copy action. * src/vorta/views/archive_tab.py (ArchiveTab): Add QShortcut for copying. * Move actions in comboBoxes to buttons. * src/vorta/assets/UI/repotab.ui : Add `bAddSSHKey` and `bAddRepo`. * src/vorta/views/repo_tab.py : Move code out of `ssh_select_action` and `repo_select_action` into `add_existing_repo`, `new_repo` and `create_ssh_key`. * src/vorta/views/repo_tab.py * Make tooltip of `storePassword` checkbox more fluent. * src/vorta/assets/UI/exportwindow.ui * Introduce `QDialogButtonBox` to modal dialogs in vorta. * src/vorta/assets/UI/extractdialog.ui * src/vorta/views/extract_dialog.py * src/vorta/assets/UI/repoadd.ui * src/vorta/views/repo_add_dialog.py * src/vorta/assets/UI/sshadd.ui * src/vorta/views/ssh_dialog.py * Move some options in scheduletab to the side. This results in two columns of options and fixes vertical scrolling. * src/vorta/assets/UI/scheduletab.ui * Changes for macOS layout * Set `sizeAdjustPolicy` of comboBoxes to `AdustToContents`. * src/vorta/assets/UI/mainwindow.ui * src/vorta/assets/UI/repotab.ui * Fix some icons, translations strings and link * Lint Co-authored-by: real-yfprojects <real-yfprojects@users.noreply.github.com> Co-authored-by: Manu <3916435+m3nu@users.noreply.github.com> Co-authored-by: Manu <manu@snapdragon.cc>
2022-03-24 06:27:07 +00:00
from vorta.store.models import ArchiveModel, EventLogModel, RepoModel
LONG_PASSWORD = 'long-password-long'
SHORT_PASSWORD = 'hunter2'
@pytest.mark.parametrize(
"first_password, second_password, validation_error",
[
(SHORT_PASSWORD, SHORT_PASSWORD, 'Passwords must be at least 9 characters long.'),
(LONG_PASSWORD, SHORT_PASSWORD, 'Passwords must be identical.'),
(SHORT_PASSWORD + "1", SHORT_PASSWORD, 'Passwords must be identical and at least 9 characters long.'),
(LONG_PASSWORD, LONG_PASSWORD, ''), # no error, password meets requirements.
],
)
def test_new_repo_password_validation(qapp, qtbot, borg_json_output, first_password, second_password, validation_error):
# Add new repo window
main = qapp.main_window
tab = main.repoTab
tab.new_repo()
add_repo_window = tab._window
qtbot.addWidget(add_repo_window)
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, first_password)
qtbot.keyClicks(add_repo_window.passwordInput.confirmLineEdit, second_password)
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
assert add_repo_window.passwordInput.validation_label.text() == validation_error
@pytest.mark.parametrize(
"repo_name, error_text",
[
('test_repo_name', ''), # valid repo name
('a' * 64, ''), # also valid (<=64 characters)
('a' * 65, 'Repository name must be less than 65 characters.'), # not valid (>64 characters)
],
)
def test_repo_add_name_validation(qapp, qtbot, borg_json_output, repo_name, error_text):
main = qapp.main_window
tab = main.repoTab
tab.new_repo()
add_repo_window = tab._window
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain
qtbot.addWidget(add_repo_window)
qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
qtbot.keyClicks(add_repo_window.repoName, repo_name)
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
assert add_repo_window.errorText.text() == error_text
def test_repo_unlink(qapp, qtbot, monkeypatch):
main = qapp.main_window
tab = main.repoTab
monkeypatch.setattr(QMessageBox, "show", lambda *args: True)
qtbot.mouseClick(tab.repoRemoveToolbutton, QtCore.Qt.MouseButton.LeftButton)
qtbot.waitUntil(lambda: tab.repoSelector.count() == 1, **pytest._wait_defaults)
assert RepoModel.select().count() == 0
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.MouseButton.LeftButton)
# -1 is the repo id in this test
qtbot.waitUntil(lambda: 'Select a backup repository first.' in main.progressText.text(), **pytest._wait_defaults)
assert 'Select a backup repository first.' in main.progressText.text()
def test_password_autofill(qapp, qtbot):
main = qapp.main_window
tab = main.repoTab
tab.new_repo()
add_repo_window = tab._window
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain
keyring = VortaKeyring.get_keyring()
password = str(uuid.uuid4())
keyring.set_password('vorta-repo', test_repo_url, password)
qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
assert add_repo_window.passwordInput.passwordLineEdit.text() == password
def test_repo_add_failure(qapp, qtbot, borg_json_output):
main = qapp.main_window
tab = main.repoTab
tab.new_repo()
add_repo_window = tab._window
qtbot.addWidget(add_repo_window)
# Add repo with invalid URL
qtbot.keyClicks(add_repo_window.repoURL, 'aaa')
qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.MouseButton.LeftButton)
assert add_repo_window.errorText.text().startswith('Please enter a valid repo URL')
def test_repo_add_success(qapp, qtbot, mocker, borg_json_output):
main = qapp.main_window
tab = main.repoTab
tab.new_repo()
add_repo_window = tab._window
test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain
test_repo_name = 'Test Repo'
# Enter valid repo URL, name, and password
qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
qtbot.keyClicks(add_repo_window.repoName, test_repo_name)
qtbot.keyClicks(add_repo_window.passwordInput.passwordLineEdit, LONG_PASSWORD)
qtbot.keyClicks(add_repo_window.passwordInput.confirmLineEdit, LONG_PASSWORD)
2018-11-06 06:47:04 +00:00
stdout, stderr = borg_json_output('info')
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
add_repo_window.run()
qtbot.waitUntil(
lambda: EventLogModel.select().where(EventLogModel.returncode == 0).count() == 2, **pytest._wait_defaults
)
assert RepoModel.get(id=2).url == test_repo_url
keyring = VortaKeyring.get_keyring()
assert keyring.get_password("vorta-repo", RepoModel.get(id=2).url) == LONG_PASSWORD
assert tab.repoSelector.currentText() == f"{test_repo_name} - {test_repo_url}"
def test_ssh_dialog_success(qapp, qtbot, mocker, tmpdir):
main = qapp.main_window
tab = main.repoTab
qtbot.mouseClick(tab.bAddSSHKey, QtCore.Qt.MouseButton.LeftButton)
ssh_dialog = tab._window
ssh_dialog_closed = mocker.spy(ssh_dialog, 'reject')
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)
ssh_dialog.generate_key()
# Ensure new key file was created
qtbot.waitUntil(lambda: ssh_dialog_closed.called, **pytest._wait_defaults)
assert len(ssh_dir.listdir()) == 2
# Ensure new key is populated in SSH combobox
mocker.patch('os.path.expanduser', return_value=str(tmpdir))
tab.init_ssh()
assert tab.sshComboBox.count() == 2
# Ensure valid keys were created
key_tmpfile_content = key_tmpfile.read()
assert key_tmpfile_content.startswith('-----BEGIN OPENSSH PRIVATE KEY-----')
pub_tmpfile_content = pub_tmpfile.read()
assert pub_tmpfile_content.startswith('ssh-ed25519')
def test_ssh_dialog_failure(qapp, qtbot, mocker, monkeypatch, tmpdir):
main = qapp.main_window
tab = main.repoTab
monkeypatch.setattr(QMessageBox, "show", lambda *args: True)
failure_message = mocker.spy(tab, "create_ssh_key_failure")
qtbot.mouseClick(tab.bAddSSHKey, QtCore.Qt.MouseButton.LeftButton)
ssh_dialog = tab._window
ssh_dir = tmpdir
key_tmpfile = ssh_dir.join("invalid///===for_testing")
key_tmpfile_full = os.path.join(key_tmpfile.dirname, key_tmpfile.basename)
ssh_dialog.outputFileTextBox.setText(key_tmpfile_full)
ssh_dialog.generate_key()
qtbot.waitUntil(lambda: failure_message.called, **pytest._wait_defaults)
failure_message.assert_called_once()
# Ensure no new ney file was created
assert len(ssh_dir.listdir()) == 0
# Ensure no new key file in combo box
mocker.patch('os.path.expanduser', return_value=str(tmpdir))
tab.init_ssh()
assert tab.sshComboBox.count() == 1
def test_ssh_copy_to_clipboard_action(qapp, qtbot, mocker, tmpdir):
"""Testing the proper QMessageBox dialogue appears depending on the copy action circumstances."""
tab = qapp.main_window.repoTab
# set mocks to test assertions and prevent test interruptions
text = mocker.patch.object(QMessageBox, "setText")
mocker.patch.object(QMessageBox, "show")
mocker.patch.object(qapp.clipboard(), "setText")
qtbot.mouseClick(tab.bAddSSHKey, QtCore.Qt.MouseButton.LeftButton)
ssh_dialog = tab._window
ssh_dialog_closed = mocker.spy(ssh_dialog, 'reject')
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)
ssh_dialog.generate_key()
# Ensure new key file was created
qtbot.waitUntil(lambda: ssh_dialog_closed.called, **pytest._wait_defaults)
assert len(ssh_dir.listdir()) == 2
# populate the ssh combobox with the ssh key we created in tmpdir
mock_expanduser = mocker.patch('os.path.expanduser', return_value=str(tmpdir))
tab.init_ssh()
assert tab.sshComboBox.count() == 2
# test when no ssh key is selected to copy
assert tab.sshComboBox.currentIndex() == 0
qtbot.mouseClick(tab.sshKeyToClipboardButton, QtCore.Qt.MouseButton.LeftButton)
message = "Select a public key from the dropdown first."
text.assert_called_with(message)
# Select a key and copy it
mock_expanduser.return_value = pub_tmpfile
tab.sshComboBox.setCurrentIndex(1)
assert tab.sshComboBox.currentIndex() == 1
qtbot.mouseClick(tab.sshKeyToClipboardButton, QtCore.Qt.MouseButton.LeftButton)
message = "The selected public SSH key was copied to the clipboard. Use it to set up remote repo permissions."
text.assert_called_with(message)
# handle ssh key file not found
mock_expanduser.return_value = "foobar"
assert tab.sshComboBox.currentIndex() == 1
qtbot.mouseClick(tab.sshKeyToClipboardButton, QtCore.Qt.MouseButton.LeftButton)
message = "Could not find public key."
text.assert_called_with(message)
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')
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
2018-11-06 06:47:04 +00:00
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.MouseButton.LeftButton)
qtbot.waitUntil(lambda: 'Backup finished.' in main.progressText.text(), **pytest._wait_defaults)
qtbot.waitUntil(lambda: main.createStartBtn.isEnabled(), **pytest._wait_defaults)
2018-11-06 06:47:04 +00:00
assert EventLogModel.select().count() == 1
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()
assert main.archiveTab.archiveTable.rowCount() == 3
assert main.scheduleTab.logPage.logPage.rowCount() == 1
@pytest.mark.parametrize(
"response",
[
{
"return_code": 0, # no error
"error": "",
"icon": None,
"info": None,
},
{
"return_code": 1, # warning
"error": "Borg exited with warning status (rc 1).",
"icon": QMessageBox.Icon.Warning,
"info": "",
},
{
"return_code": 2, # critical error
"error": "Repository data check for repo test_repo_url failed. Error code 2",
"icon": QMessageBox.Icon.Critical,
"info": "Consider repairing or recreating the repository soon to avoid missing data.",
},
{
"return_code": 135, # 128 + n = kill signal n
"error": "killed by signal 7",
"icon": QMessageBox.Icon.Critical,
"info": "The process running the check job got a kill signal. Try again.",
},
{"return_code": 130, "error": "", "icon": None, "info": None}, # keyboard interrupt
],
)
def test_repo_check_failed_response(qapp, qtbot, mocker, response):
"""Test the processing of the signal that a repo consistency check has failed."""
mock_result: Dict[str, Any] = {
'params': {'repo_url': 'test_repo_url'},
'returncode': response["return_code"],
'errors': [(0, 'test_error_message')] if response["return_code"] not in [0, 130] else None,
}
mock_exec = mocker.patch.object(QMessageBox, "exec")
mock_text = mocker.patch.object(QMessageBox, "setText")
mock_info = mocker.patch.object(QMessageBox, "setInformativeText")
mock_icon = mocker.patch.object(QMessageBox, "setIcon")
qapp.check_failed_response(mock_result)
# return codes 0 and 130 do not provide a message
# for all other return codes, assert the message is formatted correctly
if mock_exec.call_count != 0:
mock_icon.assert_called_with(response["icon"])
assert response["error"] in mock_text.call_args[0][0]
assert response["info"] in mock_info.call_args[0][0]