2021-03-29 23:47:27 +00:00
|
|
|
import pytest
|
2022-05-05 09:21:54 +00:00
|
|
|
from PyQt5.QtCore import QItemSelectionModel
|
|
|
|
|
2021-03-29 23:47:27 +00:00
|
|
|
import vorta.borg
|
|
|
|
import vorta.utils
|
2022-05-05 09:21:54 +00:00
|
|
|
import vorta.views.archive_tab
|
2021-03-29 23:47:27 +00:00
|
|
|
|
|
|
|
|
2021-04-12 14:54:32 +00:00
|
|
|
@pytest.mark.parametrize('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):
|
2021-03-29 23:47:27 +00:00
|
|
|
main = qapp.main_window
|
|
|
|
tab = main.archiveTab
|
|
|
|
main.tabWidget.setCurrentIndex(3)
|
|
|
|
|
|
|
|
tab.populate_from_profile()
|
|
|
|
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() == 2)
|
|
|
|
|
2021-04-12 14:54:32 +00:00
|
|
|
stdout, stderr = borg_json_output(json_mock_file)
|
2021-03-29 23:47:27 +00:00
|
|
|
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
|
2021-10-04 11:31:41 +00:00
|
|
|
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
|
2021-03-29 23:47:27 +00:00
|
|
|
|
2022-05-05 09:21:54 +00:00
|
|
|
selection_model: QItemSelectionModel = tab.archiveTable.selectionModel()
|
|
|
|
model = tab.archiveTable.model()
|
|
|
|
|
|
|
|
flags = QItemSelectionModel.SelectionFlag.Rows
|
|
|
|
flags |= QItemSelectionModel.SelectionFlag.Select
|
|
|
|
|
|
|
|
selection_model.select(model.index(0, 0), flags)
|
|
|
|
selection_model.select(model.index(1, 0), flags)
|
|
|
|
|
2021-03-29 23:47:27 +00:00
|
|
|
tab.diff_action()
|
|
|
|
|
|
|
|
qtbot.waitUntil(lambda: hasattr(tab, '_resultwindow'), **pytest._wait_defaults)
|
|
|
|
|
2021-04-12 14:54:32 +00:00
|
|
|
assert tab._resultwindow.treeView.model().rootItem.childItems[0].data(0) == folder_root
|
2021-03-29 23:47:27 +00:00
|
|
|
tab._resultwindow.treeView.model().rootItem.childItems[0].load_children()
|
|
|
|
|
|
|
|
assert tab._resultwindow.archiveNameLabel_1.text() == 'test-archive'
|
|
|
|
tab._resultwindow.accept()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('line, expected', [
|
|
|
|
('changed link some/changed/link',
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, 'changed', 'link', 'some/changed', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
(' +77.8 kB -77.8 kB some/changed/file',
|
2021-06-20 10:15:19 +00:00
|
|
|
(77800, 'modified', 'file', 'some/changed', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
(' +77.8 kB -77.8 kB [-rw-rw-rw- -> -rw-r--r--] some/changed/file',
|
2021-06-20 10:15:19 +00:00
|
|
|
(77800, '[-rw-rw-rw- -> -rw-r--r--]', 'file', 'some/changed', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
('[-rw-rw-rw- -> -rw-r--r--] some/changed/file',
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, '[-rw-rw-rw- -> -rw-r--r--]', 'file', 'some/changed', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
|
|
|
|
('added directory some/changed/dir',
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, 'added', 'dir', 'some/changed', 'd')),
|
2021-03-29 23:47:27 +00:00
|
|
|
('removed directory some/changed/dir',
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, 'removed', 'dir', 'some/changed', 'd')),
|
2021-03-29 23:47:27 +00:00
|
|
|
|
|
|
|
# Example from https://github.com/borgbase/vorta/issues/521
|
|
|
|
('[user:user -> nfsnobody:nfsnobody] home/user/arrays/test.txt',
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, 'modified', 'test.txt', 'home/user/arrays', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
|
|
|
|
# Very short owner change, to check stripping whitespace from file path
|
|
|
|
('[a:a -> b:b] home/user/arrays/test.txt',
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, 'modified', 'test.txt', 'home/user/arrays', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
|
|
|
|
# All file-related changes in one test
|
|
|
|
(' +77.8 kB -77.8 kB [user:user -> nfsnobody:nfsnobody] [-rw-rw-rw- -> -rw-r--r--] home/user/arrays/test.txt',
|
2021-06-20 10:15:19 +00:00
|
|
|
(77800, '[-rw-rw-rw- -> -rw-r--r--]', 'test.txt', 'home/user/arrays', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
])
|
|
|
|
def test_archive_diff_parser(line, expected):
|
|
|
|
files_with_attributes, nested_file_list = vorta.views.diff_result.parse_diff_lines([line])
|
|
|
|
assert files_with_attributes == [expected]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('line, expected', [
|
|
|
|
({'path': 'some/changed/link', 'changes': [{'type': 'changed link'}]},
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, 'changed', 'link', 'some/changed', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
({'path': 'some/changed/file', 'changes': [{'type': 'modified', 'added': 77800, 'removed': 77800}]},
|
2021-06-20 10:15:19 +00:00
|
|
|
(77800, 'modified', 'file', 'some/changed', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
({'path': 'some/changed/file', 'changes': [{'type': 'modified', 'added': 77800, 'removed': 77800},
|
|
|
|
{'type': 'mode', 'old_mode': '-rw-rw-rw-', 'new_mode': '-rw-r--r--'}]},
|
2021-06-20 10:15:19 +00:00
|
|
|
(77800, '[-rw-rw-rw- -> -rw-r--r--]', 'file', 'some/changed', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
({'path': 'some/changed/file', 'changes': [{'type': 'mode', 'old_mode': '-rw-rw-rw-', 'new_mode': '-rw-r--r--'}]},
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, '[-rw-rw-rw- -> -rw-r--r--]', 'file', 'some/changed', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
({'path': 'some/changed/dir', 'changes': [{'type': 'added directory'}]},
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, 'added', 'dir', 'some/changed', 'd')),
|
2021-03-29 23:47:27 +00:00
|
|
|
({'path': 'some/changed/dir', 'changes': [{'type': 'removed directory'}]},
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, 'removed', 'dir', 'some/changed', 'd')),
|
2021-03-29 23:47:27 +00:00
|
|
|
|
|
|
|
# Example from https://github.com/borgbase/vorta/issues/521
|
|
|
|
({'path': 'home/user/arrays/test.txt', 'changes': [{'type': 'owner', 'old_user': 'user', 'new_user': 'nfsnobody',
|
|
|
|
'old_group': 'user', 'new_group': 'nfsnobody'}]},
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, 'modified', 'test.txt', 'home/user/arrays', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
|
|
|
|
# Very short owner change, to check stripping whitespace from file path
|
|
|
|
({'path': 'home/user/arrays/test.txt', 'changes': [{'type': 'owner', 'old_user': 'a', 'new_user': 'b',
|
|
|
|
'old_group': 'a', 'new_group': 'b'}]},
|
2021-06-20 10:15:19 +00:00
|
|
|
(0, 'modified', 'test.txt', 'home/user/arrays', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
|
|
|
|
# All file-related changes in one test
|
|
|
|
({'path': 'home/user/arrays/test.txt', 'changes': [{'type': 'modified', 'added': 77800, 'removed': 77800},
|
|
|
|
{'type': 'mode', 'old_mode': '-rw-rw-rw-',
|
|
|
|
'new_mode': '-rw-r--r--'},
|
|
|
|
{'type': 'owner', 'old_user': 'user', 'new_user': 'nfsnobody',
|
|
|
|
'old_group': 'user', 'new_group': 'nfsnobody'}]},
|
2021-06-20 10:15:19 +00:00
|
|
|
(77800, '[-rw-rw-rw- -> -rw-r--r--]', 'test.txt', 'home/user/arrays', '-')),
|
2021-03-29 23:47:27 +00:00
|
|
|
])
|
|
|
|
def test_archive_diff_json_parser(line, expected):
|
|
|
|
files_with_attributes, _nested_file_list = vorta.views.diff_result.parse_diff_json_lines([line])
|
|
|
|
assert files_with_attributes == [expected]
|