111 lines
3.8 KiB
Python
111 lines
3.8 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""Tests: Update-Dialog Groesse/Zentrierung + direkter Update-Button."""
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import inspect
|
||
|
|
import unittest
|
||
|
|
from unittest.mock import MagicMock, patch
|
||
|
|
|
||
|
|
|
||
|
|
class TestUpdateDialogLayout(unittest.TestCase):
|
||
|
|
def test_dialog_uses_min_width_and_parent_centering(self):
|
||
|
|
import aza_updater as au
|
||
|
|
|
||
|
|
src = inspect.getsource(au._show_update_dialog_professional)
|
||
|
|
self.assertIn("MIN_W = 600", src)
|
||
|
|
self.assertIn("winfo_rootx()", src)
|
||
|
|
self.assertIn("winfo_rooty()", src)
|
||
|
|
self.assertIn("win.grab_set()", src)
|
||
|
|
self.assertNotIn('win.geometry(f"{W}x', src)
|
||
|
|
|
||
|
|
def test_spaeter_button_on_separate_row(self):
|
||
|
|
import aza_updater as au
|
||
|
|
|
||
|
|
src = inspect.getsource(au._show_update_dialog_professional)
|
||
|
|
self.assertIn('btn_row_later', src)
|
||
|
|
self.assertIn('"Später"', src)
|
||
|
|
|
||
|
|
def test_three_actions_present(self):
|
||
|
|
import aza_updater as au
|
||
|
|
|
||
|
|
src = inspect.getsource(au._show_update_dialog_professional)
|
||
|
|
for label in ("Jetzt aktualisieren", "Beim Beenden aktualisieren", "Später"):
|
||
|
|
self.assertIn(label, src)
|
||
|
|
|
||
|
|
|
||
|
|
class TestDirectUpdateButton(unittest.TestCase):
|
||
|
|
def test_manual_start_update_now_exists(self):
|
||
|
|
from desktop_update_check import manual_start_update_now
|
||
|
|
|
||
|
|
self.assertTrue(callable(manual_start_update_now))
|
||
|
|
|
||
|
|
def test_header_button_uses_direct_start(self):
|
||
|
|
import basis14
|
||
|
|
|
||
|
|
src = inspect.getsource(basis14.KGDesktopApp._manual_update_check)
|
||
|
|
self.assertIn("manual_start_update_now", src)
|
||
|
|
self.assertNotIn("manual_check_for_updates", src)
|
||
|
|
|
||
|
|
def test_sidebar_button_uses_direct_start(self):
|
||
|
|
import aza_office_shell_v1 as shell
|
||
|
|
|
||
|
|
src = inspect.getsource(shell._OfficeShellV12._on_sidebar_update_click)
|
||
|
|
self.assertIn("manual_start_update_now", src)
|
||
|
|
self.assertNotIn("show_update_dialog_from_info", src)
|
||
|
|
|
||
|
|
@patch("desktop_update_check._launch_update_now")
|
||
|
|
@patch("desktop_update_check._build_update_info")
|
||
|
|
@patch("desktop_update_check.fetch_remote_manifest")
|
||
|
|
def test_direct_button_launches_without_dialog(
|
||
|
|
self, mock_fetch, mock_build, mock_launch
|
||
|
|
):
|
||
|
|
from desktop_update_check import manual_start_update_now
|
||
|
|
|
||
|
|
mock_fetch.return_value = (
|
||
|
|
{"version": "9.9.9", "channel": "stable", "update_level": "recommended"},
|
||
|
|
None,
|
||
|
|
)
|
||
|
|
info = {
|
||
|
|
"update_available": True,
|
||
|
|
"latest_version": "9.9.9",
|
||
|
|
"current_version": "1.0.0",
|
||
|
|
"update_level": "recommended",
|
||
|
|
}
|
||
|
|
mock_build.return_value = info
|
||
|
|
parent = MagicMock()
|
||
|
|
|
||
|
|
manual_start_update_now(parent=parent)
|
||
|
|
|
||
|
|
mock_launch.assert_called_once_with(info, parent)
|
||
|
|
|
||
|
|
@patch("desktop_update_check._launch_update_now")
|
||
|
|
@patch("desktop_update_check._build_update_info")
|
||
|
|
@patch("desktop_update_check.fetch_remote_manifest")
|
||
|
|
def test_no_update_skips_launch(self, mock_fetch, mock_build, mock_launch):
|
||
|
|
from desktop_update_check import manual_start_update_now
|
||
|
|
|
||
|
|
mock_fetch.return_value = (
|
||
|
|
{"version": "1.3.14", "channel": "stable"},
|
||
|
|
None,
|
||
|
|
)
|
||
|
|
mock_build.return_value = None
|
||
|
|
manual_start_update_now(parent=None)
|
||
|
|
mock_launch.assert_not_called()
|
||
|
|
|
||
|
|
def test_launch_update_now_uses_launch_external_installer(self):
|
||
|
|
import desktop_update_check as duc
|
||
|
|
|
||
|
|
src = inspect.getsource(duc._launch_update_now)
|
||
|
|
self.assertIn("launch_external_installer", src)
|
||
|
|
self.assertIn("clear_update_pending", src)
|
||
|
|
|
||
|
|
def test_show_update_notification_still_uses_dialog(self):
|
||
|
|
import desktop_update_check as duc
|
||
|
|
|
||
|
|
src = inspect.getsource(duc._show_update_notification)
|
||
|
|
self.assertIn("_show_update_dialog_professional", src)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|