mirror of https://github.com/borgbase/vorta
Setting for Full Disk Access check. By @bigtedde (#1653)
This commit is contained in:
parent
e3451ed49e
commit
a64493d254
|
@ -194,6 +194,10 @@ class VortaApp(QtSingleApplication):
|
||||||
This function tries reading a file that is known to be restricted and warn the user about
|
This function tries reading a file that is known to be restricted and warn the user about
|
||||||
incomplete backups.
|
incomplete backups.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not SettingsModel.get(key="check_full_disk_access").value:
|
||||||
|
return
|
||||||
|
|
||||||
test_path = Path('~/Library/Cookies').expanduser()
|
test_path = Path('~/Library/Cookies').expanduser()
|
||||||
if test_path.exists() and not os.access(test_path, os.R_OK):
|
if test_path.exists() and not os.access(test_path, os.R_OK):
|
||||||
msg = QMessageBox()
|
msg = QMessageBox()
|
||||||
|
|
|
@ -115,6 +115,17 @@ def get_misc_settings() -> List[Dict[str, str]]:
|
||||||
'type': 'checkbox',
|
'type': 'checkbox',
|
||||||
'label': trans_late('settings', 'Include pre-release versions when checking for updates'),
|
'label': trans_late('settings', 'Include pre-release versions when checking for updates'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'key': 'check_full_disk_access',
|
||||||
|
'value': True,
|
||||||
|
'type': 'checkbox',
|
||||||
|
'group': startup,
|
||||||
|
'label': trans_late(
|
||||||
|
'settings',
|
||||||
|
'Check for Full Disk Access on startup',
|
||||||
|
),
|
||||||
|
'tooltip': trans_late('settings', 'Alerts user when full disk access permission has not been provided'),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
settings += [
|
settings += [
|
||||||
|
|
|
@ -1,31 +1,19 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from unittest.mock import Mock
|
||||||
import pytest
|
import pytest
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
from PyQt5.QtWidgets import QCheckBox, QFormLayout
|
from PyQt5.QtWidgets import QCheckBox, QFormLayout
|
||||||
|
import vorta.store.models
|
||||||
|
|
||||||
|
|
||||||
def test_autostart(qapp, qtbot):
|
def test_autostart(qapp, qtbot):
|
||||||
'''Check if file exists only on Linux, otherwise just check it doesn't crash'''
|
"""Check if file exists only on Linux, otherwise just check it doesn't crash"""
|
||||||
main = qapp.main_window
|
|
||||||
main.tabWidget.setCurrentIndex(4)
|
|
||||||
tab = main.miscTab
|
|
||||||
|
|
||||||
def click_autostart():
|
setting = "Automatically start Vorta at login"
|
||||||
for x in range(0, tab.checkboxLayout.count()):
|
|
||||||
item = tab.checkboxLayout.itemAt(x, QFormLayout.ItemRole.FieldRole)
|
|
||||||
if not item:
|
|
||||||
continue
|
|
||||||
checkbox = item.itemAt(0).widget()
|
|
||||||
checkbox.__class__ = QCheckBox
|
|
||||||
if checkbox.text().startswith("Automatically"):
|
|
||||||
# Have to use pos to click checkbox correctly
|
|
||||||
# https://stackoverflow.com/questions/19418125/pysides-qtest-not-checking-box/24070484#24070484
|
|
||||||
qtbot.mouseClick(checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2, int(checkbox.height() / 2)))
|
|
||||||
break
|
|
||||||
|
|
||||||
click_autostart()
|
_click_toggle_setting(setting, qapp, qtbot)
|
||||||
|
|
||||||
if sys.platform == 'linux':
|
if sys.platform == 'linux':
|
||||||
autostart_path = (
|
autostart_path = (
|
||||||
|
@ -39,6 +27,57 @@ def test_autostart(qapp, qtbot):
|
||||||
|
|
||||||
assert desktop_file_text.startswith("[Desktop Entry]")
|
assert desktop_file_text.startswith("[Desktop Entry]")
|
||||||
|
|
||||||
click_autostart()
|
_click_toggle_setting(setting, qapp, qtbot)
|
||||||
|
|
||||||
if sys.platform == 'linux':
|
if sys.platform == 'linux':
|
||||||
assert not os.path.exists(autostart_path)
|
assert not os.path.exists(autostart_path)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(sys.platform != 'darwin', reason="Full Disk Access check only on Darwin")
|
||||||
|
def test_check_full_disk_access(qapp, qtbot, mocker):
|
||||||
|
"""Enables/disables 'Check for Full Disk Access on startup' setting and ensures functionality"""
|
||||||
|
|
||||||
|
setting = "Check for Full Disk Access on startup"
|
||||||
|
|
||||||
|
# Set mocks for setting enabled
|
||||||
|
mocker.patch.object(vorta.store.models.SettingsModel, "get", return_value=Mock(value=True))
|
||||||
|
mocker.patch('pathlib.Path.exists', return_value=True)
|
||||||
|
mocker.patch('os.access', return_value=False)
|
||||||
|
mock_qmessagebox = mocker.patch('vorta.application.QMessageBox')
|
||||||
|
|
||||||
|
# See that pop-up occurs
|
||||||
|
qapp.check_darwin_permissions()
|
||||||
|
mock_qmessagebox.assert_called()
|
||||||
|
|
||||||
|
# Reset mocks for setting disabled
|
||||||
|
mock_qmessagebox.reset_mock()
|
||||||
|
mocker.patch.object(vorta.store.models.SettingsModel, "get", return_value=Mock(value=False))
|
||||||
|
|
||||||
|
# See that pop-up does not occur
|
||||||
|
qapp.check_darwin_permissions()
|
||||||
|
mock_qmessagebox.assert_not_called()
|
||||||
|
|
||||||
|
# Checks that setting doesn't crash program when click toggled on then off"""
|
||||||
|
_click_toggle_setting(setting, qapp, qtbot)
|
||||||
|
_click_toggle_setting(setting, qapp, qtbot)
|
||||||
|
|
||||||
|
|
||||||
|
def _click_toggle_setting(setting, qapp, qtbot):
|
||||||
|
"""Click toggle setting in the misc tab"""
|
||||||
|
|
||||||
|
main = qapp.main_window
|
||||||
|
main.tabWidget.setCurrentIndex(4)
|
||||||
|
tab = main.miscTab
|
||||||
|
|
||||||
|
for x in range(0, tab.checkboxLayout.count()):
|
||||||
|
item = tab.checkboxLayout.itemAt(x, QFormLayout.ItemRole.FieldRole)
|
||||||
|
if not item:
|
||||||
|
continue
|
||||||
|
checkbox = item.itemAt(0).widget()
|
||||||
|
checkbox.__class__ = QCheckBox
|
||||||
|
|
||||||
|
if checkbox.text() == setting:
|
||||||
|
# Have to use pos to click checkbox correctly
|
||||||
|
# https://stackoverflow.com/questions/19418125/pysides-qtest-not-checking-box/24070484#24070484
|
||||||
|
qtbot.mouseClick(checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2, int(checkbox.height() / 2)))
|
||||||
|
break
|
||||||
|
|
Loading…
Reference in New Issue