2023-08-05 13:49:45 +00:00
|
|
|
"""
|
|
|
|
This file contains tests for the Archive tab to test the various archive related borg commands.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
import psutil
|
|
|
|
import pytest
|
|
|
|
import vorta.borg
|
|
|
|
import vorta.utils
|
|
|
|
import vorta.views.archive_tab
|
|
|
|
from PyQt6 import QtCore
|
|
|
|
from vorta.store.models import ArchiveModel
|
|
|
|
|
|
|
|
|
|
|
|
def test_repo_list(qapp, qtbot):
|
|
|
|
"""Test that the archives are created and repo list is populated correctly"""
|
|
|
|
main = qapp.main_window
|
|
|
|
tab = main.archiveTab
|
|
|
|
main.tabWidget.setCurrentIndex(3)
|
|
|
|
tab.refresh_archive_list()
|
|
|
|
qtbot.waitUntil(lambda: not tab.bCheck.isEnabled(), **pytest._wait_defaults)
|
|
|
|
assert not tab.bCheck.isEnabled()
|
|
|
|
|
|
|
|
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
|
|
|
|
assert ArchiveModel.select().count() == 6
|
|
|
|
assert 'Refreshing archives done.' in main.progressText.text()
|
|
|
|
assert tab.bCheck.isEnabled()
|
|
|
|
|
|
|
|
|
2023-08-17 10:05:52 +00:00
|
|
|
def test_repo_prune(qapp, qtbot, archive_env):
|
2023-08-05 13:49:45 +00:00
|
|
|
"""Test for archive pruning"""
|
2023-08-17 10:05:52 +00:00
|
|
|
main, tab = archive_env
|
2023-08-05 13:49:45 +00:00
|
|
|
qtbot.mouseClick(tab.bPrune, QtCore.Qt.MouseButton.LeftButton)
|
|
|
|
qtbot.waitUntil(lambda: 'Pruning old archives' in main.progressText.text(), **pytest._wait_defaults)
|
|
|
|
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.min_borg_version('1.2.0a1')
|
2023-08-17 10:05:52 +00:00
|
|
|
def test_repo_compact(qapp, qtbot, archive_env):
|
2023-08-05 13:49:45 +00:00
|
|
|
"""Test for archive compaction"""
|
2023-08-17 10:05:52 +00:00
|
|
|
main, tab = archive_env
|
2023-08-05 13:49:45 +00:00
|
|
|
qtbot.waitUntil(lambda: tab.compactButton.isEnabled(), **pytest._wait_defaults)
|
|
|
|
assert tab.compactButton.isEnabled()
|
|
|
|
|
|
|
|
qtbot.mouseClick(tab.compactButton, QtCore.Qt.MouseButton.LeftButton)
|
|
|
|
qtbot.waitUntil(lambda: 'compaction freed about' in main.logText.text().lower(), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
|
2023-08-17 10:05:52 +00:00
|
|
|
def test_check(qapp, qtbot, archive_env):
|
2023-08-05 13:49:45 +00:00
|
|
|
"""Test for archive consistency check"""
|
2023-08-17 10:05:52 +00:00
|
|
|
main, tab = archive_env
|
2023-08-05 13:49:45 +00:00
|
|
|
|
|
|
|
qapp.check_failed_event.disconnect()
|
|
|
|
|
|
|
|
qtbot.waitUntil(lambda: tab.bCheck.isEnabled(), **pytest._wait_defaults)
|
|
|
|
qtbot.mouseClick(tab.bCheck, QtCore.Qt.MouseButton.LeftButton)
|
|
|
|
success_text = 'INFO: Archive consistency check complete'
|
|
|
|
|
|
|
|
qtbot.waitUntil(lambda: success_text in main.logText.text(), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(sys.platform == 'darwin', reason="Macos fuse support is uncertain")
|
2023-08-17 10:05:52 +00:00
|
|
|
def test_mount(qapp, qtbot, monkeypatch, choose_file_dialog, tmpdir, archive_env):
|
2023-08-05 13:49:45 +00:00
|
|
|
"""Test for archive mounting and unmounting"""
|
|
|
|
|
|
|
|
def psutil_disk_partitions(**kwargs):
|
|
|
|
DiskPartitions = namedtuple('DiskPartitions', ['device', 'mountpoint'])
|
|
|
|
return [DiskPartitions('borgfs', str(tmpdir))]
|
|
|
|
|
|
|
|
monkeypatch.setattr(psutil, "disk_partitions", psutil_disk_partitions)
|
|
|
|
monkeypatch.setattr(vorta.views.archive_tab, "choose_file_dialog", choose_file_dialog)
|
|
|
|
|
2023-08-17 10:05:52 +00:00
|
|
|
main, tab = archive_env
|
2023-08-05 13:49:45 +00:00
|
|
|
tab.archiveTable.selectRow(0)
|
|
|
|
|
|
|
|
qtbot.waitUntil(lambda: tab.bMountRepo.isEnabled(), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
qtbot.mouseClick(tab.bMountArchive, QtCore.Qt.MouseButton.LeftButton)
|
|
|
|
qtbot.waitUntil(lambda: tab.mountErrors.text().startswith('Mounted'), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
tab.bmountarchive_clicked()
|
|
|
|
qtbot.waitUntil(lambda: tab.mountErrors.text().startswith('Un-mounted successfully.'), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
tab.bmountrepo_clicked()
|
|
|
|
qtbot.waitUntil(lambda: tab.mountErrors.text().startswith('Mounted'), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
tab.bmountrepo_clicked()
|
|
|
|
qtbot.waitUntil(lambda: tab.mountErrors.text().startswith('Un-mounted successfully.'), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
|
2023-08-17 10:05:52 +00:00
|
|
|
def test_archive_extract(qapp, qtbot, monkeypatch, choose_file_dialog, tmpdir, archive_env):
|
2023-08-05 13:49:45 +00:00
|
|
|
"""Test for archive extraction"""
|
2023-08-17 10:05:52 +00:00
|
|
|
main, tab = archive_env
|
2023-08-05 13:49:45 +00:00
|
|
|
|
|
|
|
tab.archiveTable.selectRow(2)
|
|
|
|
tab.extract_action()
|
|
|
|
|
|
|
|
qtbot.waitUntil(lambda: hasattr(tab, '_window'), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
# Select all files
|
|
|
|
tree_view = tab._window.treeView.model()
|
|
|
|
tree_view.setData(tree_view.index(0, 0), QtCore.Qt.CheckState.Checked, QtCore.Qt.ItemDataRole.CheckStateRole)
|
|
|
|
monkeypatch.setattr(vorta.views.archive_tab, "choose_file_dialog", choose_file_dialog)
|
|
|
|
qtbot.mouseClick(tab._window.extractButton, QtCore.Qt.MouseButton.LeftButton)
|
|
|
|
|
|
|
|
qtbot.waitUntil(lambda: 'Restored files from archive.' in main.progressText.text(), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
assert [item.basename for item in tmpdir.listdir()] == ['private' if sys.platform == 'darwin' else 'tmp']
|
|
|
|
|
|
|
|
|
2023-08-17 10:05:52 +00:00
|
|
|
def test_archive_delete(qapp, qtbot, mocker, archive_env):
|
2023-08-05 13:49:45 +00:00
|
|
|
"""Test for archive deletion"""
|
2023-08-17 10:05:52 +00:00
|
|
|
main, tab = archive_env
|
2023-08-05 13:49:45 +00:00
|
|
|
|
|
|
|
archivesCount = tab.archiveTable.rowCount()
|
|
|
|
|
|
|
|
mocker.patch.object(vorta.views.archive_tab.ArchiveTab, 'confirm_dialog', lambda x, y, z: True)
|
|
|
|
|
|
|
|
tab.archiveTable.selectRow(0)
|
|
|
|
tab.delete_action()
|
|
|
|
qtbot.waitUntil(lambda: 'Archive deleted.' in main.progressText.text(), **pytest._wait_defaults)
|
|
|
|
|
|
|
|
assert ArchiveModel.select().count() == archivesCount - 1
|
|
|
|
assert tab.archiveTable.rowCount() == archivesCount - 1
|
|
|
|
|
|
|
|
|
2023-08-17 10:05:52 +00:00
|
|
|
def test_archive_rename(qapp, qtbot, mocker, archive_env):
|
2023-08-05 13:49:45 +00:00
|
|
|
"""Test for archive renaming"""
|
2023-08-17 10:05:52 +00:00
|
|
|
main, tab = archive_env
|
2023-08-05 13:49:45 +00:00
|
|
|
|
|
|
|
tab.archiveTable.selectRow(0)
|
|
|
|
new_archive_name = 'idf89d8f9d8fd98'
|
2023-08-15 11:38:51 +00:00
|
|
|
pos = tab.archiveTable.visualRect(tab.archiveTable.model().index(0, 4)).center()
|
|
|
|
qtbot.mouseClick(tab.archiveTable.viewport(), QtCore.Qt.MouseButton.LeftButton, pos=pos)
|
|
|
|
qtbot.mouseDClick(tab.archiveTable.viewport(), QtCore.Qt.MouseButton.LeftButton, pos=pos)
|
|
|
|
qtbot.keyClicks(tab.archiveTable.viewport().focusWidget(), new_archive_name)
|
|
|
|
qtbot.keyClick(tab.archiveTable.viewport().focusWidget(), QtCore.Qt.Key.Key_Return)
|
2023-08-05 13:49:45 +00:00
|
|
|
|
|
|
|
# Successful rename case
|
2023-08-15 11:38:51 +00:00
|
|
|
qtbot.waitUntil(lambda: tab.archiveTable.model().index(0, 4).data() == new_archive_name, **pytest._wait_defaults)
|