Release SyncVito 1.0.13
This commit is contained in:
1 parent
b6e32a1b18
commit
cdcd03d7b0
8 files changed
+284
-20
No files matched your search
@@ -0,0 +1,101 @@
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
import syncvito.autostart as autostart
|
||||
from syncvito.autostart import generate_task_xml, set_autostart
|
||||
|
||||
|
||||
def test_generate_task_xml_structure() -> None:
|
||||
cmd = Path("C:/Program Files/SyncVito/SyncVito.exe")
|
||||
args = "--minimized"
|
||||
xml = generate_task_xml(cmd, args)
|
||||
|
||||
assert '<?xml version="1.0" encoding="UTF-16"?>' in xml
|
||||
assert "<RunLevel>HighestAvailable</RunLevel>" in xml
|
||||
assert "<LogonType>InteractiveToken</LogonType>" in xml
|
||||
assert "<Delay>PT5S</Delay>" in xml
|
||||
assert "<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>" in xml
|
||||
assert "<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>" in xml
|
||||
assert "<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>" in xml
|
||||
assert "<Command>C:\\Program Files\\SyncVito\\SyncVito.exe</Command>" in xml
|
||||
assert "<Arguments>--minimized</Arguments>" in xml
|
||||
|
||||
|
||||
def test_set_autostart_non_windows(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(autostart.os, "name", "posix")
|
||||
assert not set_autostart(True)
|
||||
assert not set_autostart(False)
|
||||
|
||||
|
||||
def test_set_autostart_enable_scheduled_task_success(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(autostart.os, "name", "nt")
|
||||
monkeypatch.setattr(sys, "frozen", True, raising=False)
|
||||
monkeypatch.setattr(sys, "executable", r"C:\Program Files\SyncVito\SyncVito.exe")
|
||||
|
||||
mock_run = MagicMock(return_value=subprocess.CompletedProcess(args=[], returncode=0))
|
||||
monkeypatch.setattr(autostart, "_run_schtasks", mock_run)
|
||||
|
||||
deleted_run_key = False
|
||||
|
||||
def mock_delete_run_key() -> None:
|
||||
nonlocal deleted_run_key
|
||||
deleted_run_key = True
|
||||
|
||||
monkeypatch.setattr(autostart, "_delete_run_key_entry", mock_delete_run_key)
|
||||
|
||||
result = set_autostart(True)
|
||||
assert result is True
|
||||
assert mock_run.called
|
||||
create_call_args = mock_run.call_args[0][0]
|
||||
assert create_call_args[0] == "/create"
|
||||
assert create_call_args[1] == "/tn"
|
||||
assert create_call_args[2] == "SyncVito"
|
||||
assert deleted_run_key is True
|
||||
|
||||
|
||||
def test_set_autostart_enable_fallback_registry(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(autostart.os, "name", "nt")
|
||||
monkeypatch.setattr(sys, "frozen", True, raising=False)
|
||||
monkeypatch.setattr(sys, "executable", r"C:\Program Files\SyncVito\SyncVito.exe")
|
||||
|
||||
# schtasks fails (e.g. non-elevated prompt)
|
||||
mock_run = MagicMock(return_value=subprocess.CompletedProcess(args=[], returncode=1))
|
||||
monkeypatch.setattr(autostart, "_run_schtasks", mock_run)
|
||||
|
||||
registry_command = None
|
||||
|
||||
def mock_set_run_key(cmd: str) -> None:
|
||||
nonlocal registry_command
|
||||
registry_command = cmd
|
||||
|
||||
monkeypatch.setattr(autostart, "_set_run_key_entry", mock_set_run_key)
|
||||
|
||||
result = set_autostart(True)
|
||||
assert result is False
|
||||
assert registry_command == r'"C:\Program Files\SyncVito\SyncVito.exe" --minimized'
|
||||
|
||||
|
||||
def test_set_autostart_disable(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(autostart.os, "name", "nt")
|
||||
|
||||
mock_run = MagicMock(return_value=subprocess.CompletedProcess(args=[], returncode=0))
|
||||
monkeypatch.setattr(autostart, "_run_schtasks", mock_run)
|
||||
|
||||
deleted_run_key = False
|
||||
|
||||
def mock_delete_run_key() -> None:
|
||||
nonlocal deleted_run_key
|
||||
deleted_run_key = True
|
||||
|
||||
monkeypatch.setattr(autostart, "_delete_run_key_entry", mock_delete_run_key)
|
||||
|
||||
result = set_autostart(False)
|
||||
assert result is True
|
||||
assert mock_run.called
|
||||
delete_call_args = mock_run.call_args[0][0]
|
||||
assert delete_call_args == ["/delete", "/tn", "SyncVito", "/f"]
|
||||
assert deleted_run_key is True
|
||||
@@ -3,9 +3,17 @@ from pathlib import Path
|
||||
|
||||
def test_installer_launches_admin_application_with_elevated_setup_token() -> None:
|
||||
script = Path("installer/SyncVito.iss").read_text(encoding="utf-8")
|
||||
run_entries = [line for line in script.splitlines() if line.startswith("Filename:")]
|
||||
run_section = script.split("[Run]")[1].split("[")[0] if "[Run]" in script else ""
|
||||
run_entries = [line for line in run_section.splitlines() if line.startswith("Filename:")]
|
||||
|
||||
assert len(run_entries) == 2
|
||||
assert all("runascurrentuser" in entry for entry in run_entries)
|
||||
assert "postinstall" in run_entries[0]
|
||||
assert 'Parameters: "--updated"' in run_entries[1]
|
||||
|
||||
|
||||
def test_installer_cleans_up_scheduled_task_on_uninstall() -> None:
|
||||
script = Path("installer/SyncVito.iss").read_text(encoding="utf-8")
|
||||
uninstall_section = script.split("[UninstallRun]")[1].split("[")[0] if "[UninstallRun]" in script else ""
|
||||
assert "schtasks.exe" in uninstall_section
|
||||
assert "{#MyAppName}" in uninstall_section
|
||||
Reference in new issue
Block a user