2021-02-17 02:14:58 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import pytest
|
2020-08-10 18:39:51 +00:00
|
|
|
from PyQt5 import QtCore
|
|
|
|
from PyQt5.QtWidgets import QCheckBox
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
2020-11-18 23:42:21 +00:00
|
|
|
def test_autostart(qapp, qtbot):
|
|
|
|
''' Check if file exists only on Linux, otherwise just check it doesn't crash '''
|
2020-08-10 18:39:51 +00:00
|
|
|
main = qapp.main_window
|
|
|
|
main.tabWidget.setCurrentIndex(4)
|
|
|
|
tab = main.miscTab
|
|
|
|
|
2020-11-18 23:42:21 +00:00
|
|
|
def click_autostart():
|
|
|
|
for x in range(0, tab.checkboxLayout.count()):
|
|
|
|
checkbox = tab.checkboxLayout.itemAt(x).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, checkbox.height() / 2))
|
|
|
|
break
|
2020-08-10 18:39:51 +00:00
|
|
|
|
2020-11-18 23:42:21 +00:00
|
|
|
click_autostart()
|
2020-08-10 18:39:51 +00:00
|
|
|
|
2020-11-18 23:42:21 +00:00
|
|
|
if sys.platform == 'linux':
|
|
|
|
autostart_path = Path(os.environ.get(
|
|
|
|
"XDG_CONFIG_HOME", os.path.expanduser("~") + '/.config') + "/autostart") / "vorta.desktop"
|
2021-02-17 02:14:58 +00:00
|
|
|
qtbot.waitUntil(lambda: autostart_path.exists(), **pytest._wait_defaults)
|
2020-11-18 23:42:21 +00:00
|
|
|
|
|
|
|
with open(autostart_path) as desktop_file:
|
|
|
|
desktop_file_text = desktop_file.read()
|
2020-08-10 18:39:51 +00:00
|
|
|
|
|
|
|
assert(desktop_file_text.startswith("[Desktop Entry]"))
|
2020-11-18 23:42:21 +00:00
|
|
|
|
|
|
|
click_autostart()
|
|
|
|
if sys.platform == 'linux':
|
|
|
|
assert not os.path.exists(autostart_path)
|