mirror of https://github.com/borgbase/vorta
DRY tests, increase coverage. By @bigtedde (#1769)
This commit is contained in:
parent
fb42614524
commit
ee71bcae9a
|
@ -19,7 +19,7 @@ from vorta.store.models import (
|
||||||
WifiSettingModel,
|
WifiSettingModel,
|
||||||
)
|
)
|
||||||
from vorta.utils import borg_compat
|
from vorta.utils import borg_compat
|
||||||
from vorta.views.main_window import MainWindow
|
from vorta.views.main_window import ArchiveTab, MainWindow
|
||||||
|
|
||||||
models = [
|
models = [
|
||||||
RepoModel,
|
RepoModel,
|
||||||
|
@ -206,6 +206,19 @@ def rootdir():
|
||||||
return os.path.dirname(os.path.abspath(__file__))
|
return os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def archive_env(qapp, qtbot):
|
||||||
|
"""
|
||||||
|
Common setup for integration tests involving the archive tab.
|
||||||
|
"""
|
||||||
|
main: MainWindow = qapp.main_window
|
||||||
|
tab: ArchiveTab = main.archiveTab
|
||||||
|
main.tabWidget.setCurrentIndex(3)
|
||||||
|
tab.refresh_archive_list()
|
||||||
|
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() > 0, **pytest._wait_defaults)
|
||||||
|
return main, tab
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def min_borg_version(borg_version, request):
|
def min_borg_version(borg_version, request):
|
||||||
if request.node.get_closest_marker('min_borg_version'):
|
if request.node.get_closest_marker('min_borg_version'):
|
||||||
|
|
|
@ -18,11 +18,9 @@ def test_repo_list(qapp, qtbot):
|
||||||
"""Test that the archives are created and repo list is populated correctly"""
|
"""Test that the archives are created and repo list is populated correctly"""
|
||||||
main = qapp.main_window
|
main = qapp.main_window
|
||||||
tab = main.archiveTab
|
tab = main.archiveTab
|
||||||
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
main.tabWidget.setCurrentIndex(3)
|
||||||
tab.refresh_archive_list()
|
tab.refresh_archive_list()
|
||||||
qtbot.waitUntil(lambda: not tab.bCheck.isEnabled(), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: not tab.bCheck.isEnabled(), **pytest._wait_defaults)
|
||||||
|
|
||||||
assert not tab.bCheck.isEnabled()
|
assert not tab.bCheck.isEnabled()
|
||||||
|
|
||||||
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
|
||||||
|
@ -31,30 +29,18 @@ def test_repo_list(qapp, qtbot):
|
||||||
assert tab.bCheck.isEnabled()
|
assert tab.bCheck.isEnabled()
|
||||||
|
|
||||||
|
|
||||||
def test_repo_prune(qapp, qtbot):
|
def test_repo_prune(qapp, qtbot, archive_env):
|
||||||
"""Test for archive pruning"""
|
"""Test for archive pruning"""
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.refresh_archive_list()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() > 0, **pytest._wait_defaults)
|
|
||||||
|
|
||||||
qtbot.mouseClick(tab.bPrune, QtCore.Qt.MouseButton.LeftButton)
|
qtbot.mouseClick(tab.bPrune, QtCore.Qt.MouseButton.LeftButton)
|
||||||
qtbot.waitUntil(lambda: 'Pruning old archives' in main.progressText.text(), **pytest._wait_defaults)
|
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)
|
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.min_borg_version('1.2.0a1')
|
@pytest.mark.min_borg_version('1.2.0a1')
|
||||||
def test_repo_compact(qapp, qtbot):
|
def test_repo_compact(qapp, qtbot, archive_env):
|
||||||
"""Test for archive compaction"""
|
"""Test for archive compaction"""
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.refresh_archive_list()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() > 0, **pytest._wait_defaults)
|
|
||||||
|
|
||||||
qtbot.waitUntil(lambda: tab.compactButton.isEnabled(), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: tab.compactButton.isEnabled(), **pytest._wait_defaults)
|
||||||
assert tab.compactButton.isEnabled()
|
assert tab.compactButton.isEnabled()
|
||||||
|
|
||||||
|
@ -62,14 +48,9 @@ def test_repo_compact(qapp, qtbot):
|
||||||
qtbot.waitUntil(lambda: 'compaction freed about' in main.logText.text().lower(), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: 'compaction freed about' in main.logText.text().lower(), **pytest._wait_defaults)
|
||||||
|
|
||||||
|
|
||||||
def test_check(qapp, qtbot):
|
def test_check(qapp, qtbot, archive_env):
|
||||||
"""Test for archive consistency check"""
|
"""Test for archive consistency check"""
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.refresh_archive_list()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() > 0, **pytest._wait_defaults)
|
|
||||||
|
|
||||||
qapp.check_failed_event.disconnect()
|
qapp.check_failed_event.disconnect()
|
||||||
|
|
||||||
|
@ -81,7 +62,7 @@ def test_check(qapp, qtbot):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.platform == 'darwin', reason="Macos fuse support is uncertain")
|
@pytest.mark.skipif(sys.platform == 'darwin', reason="Macos fuse support is uncertain")
|
||||||
def test_mount(qapp, qtbot, monkeypatch, choose_file_dialog, tmpdir):
|
def test_mount(qapp, qtbot, monkeypatch, choose_file_dialog, tmpdir, archive_env):
|
||||||
"""Test for archive mounting and unmounting"""
|
"""Test for archive mounting and unmounting"""
|
||||||
|
|
||||||
def psutil_disk_partitions(**kwargs):
|
def psutil_disk_partitions(**kwargs):
|
||||||
|
@ -91,12 +72,7 @@ def test_mount(qapp, qtbot, monkeypatch, choose_file_dialog, tmpdir):
|
||||||
monkeypatch.setattr(psutil, "disk_partitions", psutil_disk_partitions)
|
monkeypatch.setattr(psutil, "disk_partitions", psutil_disk_partitions)
|
||||||
monkeypatch.setattr(vorta.views.archive_tab, "choose_file_dialog", choose_file_dialog)
|
monkeypatch.setattr(vorta.views.archive_tab, "choose_file_dialog", choose_file_dialog)
|
||||||
|
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.refresh_archive_list()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() > 0, **pytest._wait_defaults)
|
|
||||||
tab.archiveTable.selectRow(0)
|
tab.archiveTable.selectRow(0)
|
||||||
|
|
||||||
qtbot.waitUntil(lambda: tab.bMountRepo.isEnabled(), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: tab.bMountRepo.isEnabled(), **pytest._wait_defaults)
|
||||||
|
@ -114,14 +90,9 @@ def test_mount(qapp, qtbot, monkeypatch, choose_file_dialog, tmpdir):
|
||||||
qtbot.waitUntil(lambda: tab.mountErrors.text().startswith('Un-mounted successfully.'), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: tab.mountErrors.text().startswith('Un-mounted successfully.'), **pytest._wait_defaults)
|
||||||
|
|
||||||
|
|
||||||
def test_archive_extract(qapp, qtbot, monkeypatch, choose_file_dialog, tmpdir):
|
def test_archive_extract(qapp, qtbot, monkeypatch, choose_file_dialog, tmpdir, archive_env):
|
||||||
"""Test for archive extraction"""
|
"""Test for archive extraction"""
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.refresh_archive_list()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() > 0, **pytest._wait_defaults)
|
|
||||||
|
|
||||||
tab.archiveTable.selectRow(2)
|
tab.archiveTable.selectRow(2)
|
||||||
tab.extract_action()
|
tab.extract_action()
|
||||||
|
@ -139,14 +110,9 @@ def test_archive_extract(qapp, qtbot, monkeypatch, choose_file_dialog, tmpdir):
|
||||||
assert [item.basename for item in tmpdir.listdir()] == ['private' if sys.platform == 'darwin' else 'tmp']
|
assert [item.basename for item in tmpdir.listdir()] == ['private' if sys.platform == 'darwin' else 'tmp']
|
||||||
|
|
||||||
|
|
||||||
def test_archive_delete(qapp, qtbot, mocker):
|
def test_archive_delete(qapp, qtbot, mocker, archive_env):
|
||||||
"""Test for archive deletion"""
|
"""Test for archive deletion"""
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.refresh_archive_list()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() > 0, **pytest._wait_defaults)
|
|
||||||
|
|
||||||
archivesCount = tab.archiveTable.rowCount()
|
archivesCount = tab.archiveTable.rowCount()
|
||||||
|
|
||||||
|
@ -160,14 +126,9 @@ def test_archive_delete(qapp, qtbot, mocker):
|
||||||
assert tab.archiveTable.rowCount() == archivesCount - 1
|
assert tab.archiveTable.rowCount() == archivesCount - 1
|
||||||
|
|
||||||
|
|
||||||
def test_archive_rename(qapp, qtbot, mocker):
|
def test_archive_rename(qapp, qtbot, mocker, archive_env):
|
||||||
"""Test for archive renaming"""
|
"""Test for archive renaming"""
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.refresh_archive_list()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() > 0, **pytest._wait_defaults)
|
|
||||||
|
|
||||||
tab.archiveTable.selectRow(0)
|
tab.archiveTable.selectRow(0)
|
||||||
new_archive_name = 'idf89d8f9d8fd98'
|
new_archive_name = 'idf89d8f9d8fd98'
|
||||||
|
|
|
@ -24,7 +24,6 @@ def test_borg_prune(qapp, qtbot):
|
||||||
assert blocker.args[0]['returncode'] == 0
|
assert blocker.args[0]['returncode'] == 0
|
||||||
|
|
||||||
|
|
||||||
# test borg info
|
|
||||||
def test_borg_repo_info(qapp, qtbot, tmpdir):
|
def test_borg_repo_info(qapp, qtbot, tmpdir):
|
||||||
"""This test runs borg info on a test repo directly without UI"""
|
"""This test runs borg info on a test repo directly without UI"""
|
||||||
repo_info = {
|
repo_info = {
|
||||||
|
@ -45,14 +44,8 @@ def test_borg_repo_info(qapp, qtbot, tmpdir):
|
||||||
assert blocker.args[0]['returncode'] == 0
|
assert blocker.args[0]['returncode'] == 0
|
||||||
|
|
||||||
|
|
||||||
def test_borg_archive_info(qapp, qtbot, tmpdir):
|
def test_borg_archive_info(qapp, qtbot, archive_env):
|
||||||
"""Check that archive info command works"""
|
"""Check that archive info command works"""
|
||||||
main = qapp.main_window
|
|
||||||
tab = main.archiveTab
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.refresh_archive_list()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() > 0, **pytest._wait_defaults)
|
|
||||||
|
|
||||||
params = BorgInfoArchiveJob.prepare(vorta.store.models.BackupProfileModel.select().first(), "test-archive1")
|
params = BorgInfoArchiveJob.prepare(vorta.store.models.BackupProfileModel.select().first(), "test-archive1")
|
||||||
thread = BorgInfoArchiveJob(params['cmd'], params, qapp)
|
thread = BorgInfoArchiveJob(params['cmd'], params, qapp)
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,9 @@ from PyQt6 import QtCore
|
||||||
from vorta.store.models import ArchiveModel, EventLogModel
|
from vorta.store.models import ArchiveModel, EventLogModel
|
||||||
|
|
||||||
|
|
||||||
def test_create(qapp, qtbot):
|
def test_create(qapp, qtbot, archive_env):
|
||||||
"""Test for manual archive creation"""
|
"""Test for manual archive creation"""
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
main.archiveTab.refresh_archive_list()
|
|
||||||
qtbot.waitUntil(lambda: main.archiveTab.archiveTable.rowCount() > 0, **pytest._wait_defaults)
|
|
||||||
|
|
||||||
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.MouseButton.LeftButton)
|
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.MouseButton.LeftButton)
|
||||||
qtbot.waitUntil(lambda: 'Backup finished.' in main.progressText.text(), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: 'Backup finished.' in main.progressText.text(), **pytest._wait_defaults)
|
||||||
|
|
|
@ -17,7 +17,7 @@ from vorta.store.models import (
|
||||||
SourceFileModel,
|
SourceFileModel,
|
||||||
WifiSettingModel,
|
WifiSettingModel,
|
||||||
)
|
)
|
||||||
from vorta.views.main_window import MainWindow
|
from vorta.views.main_window import ArchiveTab, MainWindow
|
||||||
|
|
||||||
models = [
|
models = [
|
||||||
RepoModel,
|
RepoModel,
|
||||||
|
@ -105,3 +105,16 @@ def borg_json_output():
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def rootdir():
|
def rootdir():
|
||||||
return os.path.dirname(os.path.abspath(__file__))
|
return os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def archive_env(qapp, qtbot):
|
||||||
|
"""
|
||||||
|
Common setup for unit tests involving the archive tab.
|
||||||
|
"""
|
||||||
|
main: MainWindow = qapp.main_window
|
||||||
|
tab: ArchiveTab = main.archiveTab
|
||||||
|
main.tabWidget.setCurrentIndex(3)
|
||||||
|
tab.populate_from_profile()
|
||||||
|
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() == 2, **pytest._wait_defaults)
|
||||||
|
return main, tab
|
||||||
|
|
|
@ -30,18 +30,15 @@ def test_prune_intervals(qapp, qtbot):
|
||||||
assert getattr(profile, f'prune_{i}') == 9
|
assert getattr(profile, f'prune_{i}') == 9
|
||||||
|
|
||||||
|
|
||||||
def test_repo_list(qapp, qtbot, mocker, borg_json_output):
|
def test_repo_list(qapp, qtbot, mocker, borg_json_output, archive_env):
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
|
|
||||||
stdout, stderr = borg_json_output('list')
|
stdout, stderr = borg_json_output('list')
|
||||||
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
||||||
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
|
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
|
||||||
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.refresh_archive_list()
|
tab.refresh_archive_list()
|
||||||
qtbot.waitUntil(lambda: not tab.bCheck.isEnabled(), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: not tab.bCheck.isEnabled(), **pytest._wait_defaults)
|
||||||
|
|
||||||
assert not tab.bCheck.isEnabled()
|
assert not tab.bCheck.isEnabled()
|
||||||
|
|
||||||
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
|
||||||
|
@ -50,11 +47,9 @@ def test_repo_list(qapp, qtbot, mocker, borg_json_output):
|
||||||
assert tab.bCheck.isEnabled()
|
assert tab.bCheck.isEnabled()
|
||||||
|
|
||||||
|
|
||||||
def test_repo_prune(qapp, qtbot, mocker, borg_json_output):
|
def test_repo_prune(qapp, qtbot, mocker, borg_json_output, archive_env):
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.populate_from_profile()
|
|
||||||
stdout, stderr = borg_json_output('prune')
|
stdout, stderr = borg_json_output('prune')
|
||||||
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
||||||
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
|
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
|
||||||
|
@ -64,12 +59,10 @@ def test_repo_prune(qapp, qtbot, mocker, borg_json_output):
|
||||||
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: 'Refreshing archives done.' in main.progressText.text(), **pytest._wait_defaults)
|
||||||
|
|
||||||
|
|
||||||
def test_repo_compact(qapp, qtbot, mocker, borg_json_output):
|
def test_repo_compact(qapp, qtbot, mocker, borg_json_output, archive_env):
|
||||||
main = qapp.main_window
|
|
||||||
tab = main.archiveTab
|
|
||||||
vorta.utils.borg_compat.version = '1.2.0'
|
vorta.utils.borg_compat.version = '1.2.0'
|
||||||
main.tabWidget.setCurrentIndex(3)
|
main, tab = archive_env
|
||||||
tab.populate_from_profile()
|
|
||||||
stdout, stderr = borg_json_output('compact')
|
stdout, stderr = borg_json_output('compact')
|
||||||
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
||||||
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
|
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
|
||||||
|
@ -82,11 +75,8 @@ def test_repo_compact(qapp, qtbot, mocker, borg_json_output):
|
||||||
vorta.utils.borg_compat.version = '1.1.0'
|
vorta.utils.borg_compat.version = '1.1.0'
|
||||||
|
|
||||||
|
|
||||||
def test_check(qapp, mocker, borg_json_output, qtbot):
|
def test_check(qapp, mocker, borg_json_output, qtbot, archive_env):
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.populate_from_profile()
|
|
||||||
|
|
||||||
stdout, stderr = borg_json_output('check')
|
stdout, stderr = borg_json_output('check')
|
||||||
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
||||||
|
@ -97,17 +87,13 @@ def test_check(qapp, mocker, borg_json_output, qtbot):
|
||||||
qtbot.waitUntil(lambda: success_text in main.logText.text(), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: success_text in main.logText.text(), **pytest._wait_defaults)
|
||||||
|
|
||||||
|
|
||||||
def test_mount(qapp, qtbot, mocker, borg_json_output, monkeypatch, choose_file_dialog):
|
def test_mount(qapp, qtbot, mocker, borg_json_output, monkeypatch, choose_file_dialog, archive_env):
|
||||||
def psutil_disk_partitions(**kwargs):
|
def psutil_disk_partitions(**kwargs):
|
||||||
DiskPartitions = namedtuple('DiskPartitions', ['device', 'mountpoint'])
|
DiskPartitions = namedtuple('DiskPartitions', ['device', 'mountpoint'])
|
||||||
return [DiskPartitions('borgfs', '/tmp')]
|
return [DiskPartitions('borgfs', '/tmp')]
|
||||||
|
|
||||||
monkeypatch.setattr(psutil, "disk_partitions", psutil_disk_partitions)
|
monkeypatch.setattr(psutil, "disk_partitions", psutil_disk_partitions)
|
||||||
|
main, tab = archive_env
|
||||||
main = qapp.main_window
|
|
||||||
tab = main.archiveTab
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
tab.populate_from_profile()
|
|
||||||
tab.archiveTable.selectRow(0)
|
tab.archiveTable.selectRow(0)
|
||||||
|
|
||||||
stdout, stderr = borg_json_output('prune') # TODO: fully mock mount command?
|
stdout, stderr = borg_json_output('prune') # TODO: fully mock mount command?
|
||||||
|
@ -129,14 +115,8 @@ def test_mount(qapp, qtbot, mocker, borg_json_output, monkeypatch, choose_file_d
|
||||||
qtbot.waitUntil(lambda: tab.mountErrors.text().startswith('Un-mounted successfully.'), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: tab.mountErrors.text().startswith('Un-mounted successfully.'), **pytest._wait_defaults)
|
||||||
|
|
||||||
|
|
||||||
def test_archive_extract(qapp, qtbot, mocker, borg_json_output):
|
def test_archive_extract(qapp, qtbot, mocker, borg_json_output, archive_env):
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
|
|
||||||
tab.populate_from_profile()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() == 2)
|
|
||||||
|
|
||||||
tab.archiveTable.selectRow(0)
|
tab.archiveTable.selectRow(0)
|
||||||
stdout, stderr = borg_json_output('list_archive')
|
stdout, stderr = borg_json_output('list_archive')
|
||||||
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
||||||
|
@ -144,20 +124,14 @@ def test_archive_extract(qapp, qtbot, mocker, borg_json_output):
|
||||||
tab.extract_action()
|
tab.extract_action()
|
||||||
|
|
||||||
qtbot.waitUntil(lambda: hasattr(tab, '_window'), **pytest._wait_defaults)
|
qtbot.waitUntil(lambda: hasattr(tab, '_window'), **pytest._wait_defaults)
|
||||||
# qtbot.waitUntil(lambda: tab._window == qapp.activeWindow(), **pytest._wait_defaults)
|
|
||||||
|
|
||||||
model = tab._window.model
|
model = tab._window.model
|
||||||
assert model.root.children[0].subpath == 'home'
|
assert model.root.children[0].subpath == 'home'
|
||||||
assert 'test-archive, 2000' in tab._window.archiveNameLabel.text()
|
assert 'test-archive, 2000' in tab._window.archiveNameLabel.text()
|
||||||
|
|
||||||
|
|
||||||
def test_archive_delete(qapp, qtbot, mocker, borg_json_output):
|
def test_archive_delete(qapp, qtbot, mocker, borg_json_output, archive_env):
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
|
|
||||||
tab.populate_from_profile()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() == 2)
|
|
||||||
|
|
||||||
tab.archiveTable.selectRow(0)
|
tab.archiveTable.selectRow(0)
|
||||||
stdout, stderr = borg_json_output('delete')
|
stdout, stderr = borg_json_output('delete')
|
||||||
|
@ -170,13 +144,43 @@ def test_archive_delete(qapp, qtbot, mocker, borg_json_output):
|
||||||
assert tab.archiveTable.rowCount() == 1
|
assert tab.archiveTable.rowCount() == 1
|
||||||
|
|
||||||
|
|
||||||
def test_archive_rename(qapp, qtbot, mocker, borg_json_output):
|
def test_archive_copy(qapp, qtbot, monkeypatch, mocker, archive_env):
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
|
|
||||||
tab.populate_from_profile()
|
# mock the clipboard to ensure no changes are made to it during testing
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() == 2)
|
mocker.patch.object(qapp.clipboard(), "setMimeData")
|
||||||
|
clipboard_spy = mocker.spy(qapp.clipboard(), "setMimeData")
|
||||||
|
|
||||||
|
# test 'archive_copy()' by passing it an index to copy
|
||||||
|
index = tab.archiveTable.model().index(0, 0)
|
||||||
|
tab.archive_copy(index)
|
||||||
|
assert clipboard_spy.call_count == 1
|
||||||
|
actual_data = clipboard_spy.call_args[0][0] # retrieves the QMimeData() object used in method call
|
||||||
|
assert actual_data.text() == "test-archive"
|
||||||
|
|
||||||
|
# test 'archive_copy()' by selecting a row to copy
|
||||||
|
tab.archiveTable.selectRow(1)
|
||||||
|
tab.archive_copy()
|
||||||
|
assert clipboard_spy.call_count == 2
|
||||||
|
actual_data = clipboard_spy.call_args[0][0] # retrieves the QMimeData() object used in method call
|
||||||
|
assert actual_data.text() == "test-archive1"
|
||||||
|
|
||||||
|
|
||||||
|
def test_refresh_archive_info(qapp, qtbot, mocker, borg_json_output, archive_env):
|
||||||
|
main, tab = archive_env
|
||||||
|
tab.archiveTable.selectRow(0)
|
||||||
|
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)
|
||||||
|
|
||||||
|
with qtbot.waitSignal(tab.bRefreshArchive.clicked, timeout=5000):
|
||||||
|
qtbot.mouseClick(tab.bRefreshArchive, QtCore.Qt.MouseButton.LeftButton)
|
||||||
|
|
||||||
|
qtbot.waitUntil(lambda: tab.mountErrors.text() == 'Refreshed archives.', **pytest._wait_defaults)
|
||||||
|
|
||||||
|
|
||||||
|
def test_archive_rename(qapp, qtbot, mocker, borg_json_output, archive_env):
|
||||||
|
main, tab = archive_env
|
||||||
|
|
||||||
tab.archiveTable.selectRow(0)
|
tab.archiveTable.selectRow(0)
|
||||||
new_archive_name = 'idf89d8f9d8fd98'
|
new_archive_name = 'idf89d8f9d8fd98'
|
||||||
|
|
|
@ -18,13 +18,8 @@ from vorta.views.diff_result import (
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'json_mock_file,folder_root', [('diff_archives', 'test'), ('diff_archives_dict_issue', 'Users')]
|
'json_mock_file,folder_root', [('diff_archives', 'test'), ('diff_archives_dict_issue', 'Users')]
|
||||||
)
|
)
|
||||||
def test_archive_diff(qapp, qtbot, mocker, borg_json_output, json_mock_file, folder_root):
|
def test_archive_diff(qapp, qtbot, mocker, borg_json_output, json_mock_file, folder_root, archive_env):
|
||||||
main = qapp.main_window
|
main, tab = archive_env
|
||||||
tab = main.archiveTab
|
|
||||||
main.tabWidget.setCurrentIndex(3)
|
|
||||||
|
|
||||||
tab.populate_from_profile()
|
|
||||||
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() == 2)
|
|
||||||
|
|
||||||
stdout, stderr = borg_json_output(json_mock_file)
|
stdout, stderr = borg_json_output(json_mock_file)
|
||||||
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
||||||
|
|
Loading…
Reference in New Issue