115 lines
3.8 KiB
Python
115 lines
3.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Hotfix 1.3.14: Erststart ohne Lizenzschluessel darf Aktivierungsdialog oeffnen."""
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
|
class _AppStub:
|
|
license_mode = "demo"
|
|
_user_profile = {"name": "Test"}
|
|
|
|
def get_backend_url(self):
|
|
return "https://api.aza-medwork.ch"
|
|
|
|
def get_backend_token(self):
|
|
return "test-token"
|
|
|
|
def get_practice_id(self):
|
|
return ""
|
|
|
|
def after(self, *_args, **_kwargs):
|
|
return None
|
|
|
|
|
|
class TestLicenseKeyRequiredStartupRouting(unittest.TestCase):
|
|
@patch("basis14._save_license_cache")
|
|
@patch("basis14.save_user_profile")
|
|
@patch("basis14._load_license_cache", return_value=None)
|
|
@patch("basis14._get_hardware_fingerprint", return_value="fp-test")
|
|
@patch("basis14._get_or_create_device_id", return_value="dev-test")
|
|
@patch("basis14.load_user_profile", return_value={"name": "Test", "license_key": ""})
|
|
@patch("basis14.requests.get")
|
|
def test_license_key_required_no_pending_device_limit_msg(
|
|
self, mock_get, *_patches
|
|
):
|
|
from basis14 import KGDesktopApp
|
|
|
|
resp = MagicMock()
|
|
resp.status_code = 200
|
|
resp.json.return_value = {
|
|
"valid": False,
|
|
"reason": "license_key_required",
|
|
"device_allowed": False,
|
|
}
|
|
mock_get.return_value = resp
|
|
|
|
app = _AppStub()
|
|
KGDesktopApp.check_license_status(app)
|
|
|
|
self.assertEqual(app.license_mode, "demo")
|
|
self.assertIsNone(getattr(app, "_pending_device_limit_msg", None))
|
|
|
|
@patch("basis14._save_license_cache")
|
|
@patch("basis14.save_user_profile")
|
|
@patch("basis14._load_license_cache", return_value=None)
|
|
@patch("basis14._get_hardware_fingerprint", return_value="fp-test")
|
|
@patch("basis14._get_or_create_device_id", return_value="dev-test")
|
|
@patch("basis14.load_user_profile", return_value={"name": "Test", "license_key": ""})
|
|
@patch("basis14.requests.get")
|
|
def test_device_limit_reached_sets_pending_message(self, mock_get, *_patches):
|
|
from basis14 import KGDesktopApp
|
|
|
|
resp = MagicMock()
|
|
resp.status_code = 200
|
|
resp.json.return_value = {
|
|
"valid": False,
|
|
"reason": "device_limit_reached",
|
|
"device_allowed": False,
|
|
"allowed_devices": 2,
|
|
"used_devices": 2,
|
|
}
|
|
mock_get.return_value = resp
|
|
|
|
app = _AppStub()
|
|
KGDesktopApp.check_license_status(app)
|
|
|
|
self.assertEqual(app.license_mode, "demo")
|
|
self.assertTrue(getattr(app, "_pending_device_limit_msg", None))
|
|
self.assertIn("Geraete-Limit", app._pending_device_limit_msg)
|
|
|
|
def test_demo_remote_startup_routes_to_activation_without_pending_limit(self):
|
|
pending = None
|
|
action = (
|
|
"device_limit_notice"
|
|
if pending
|
|
else "license_required_notice"
|
|
)
|
|
self.assertEqual(action, "license_required_notice")
|
|
|
|
def test_demo_remote_startup_routes_to_device_limit_when_pending(self):
|
|
pending = "Geraete-Limit erreicht."
|
|
action = (
|
|
"device_limit_notice"
|
|
if pending
|
|
else "license_required_notice"
|
|
)
|
|
self.assertEqual(action, "device_limit_notice")
|
|
|
|
|
|
class TestStartupNoticeHandlers(unittest.TestCase):
|
|
def test_license_required_opens_activation_not_messagebox(self):
|
|
import inspect
|
|
import basis14
|
|
|
|
src_required = inspect.getsource(basis14.KGDesktopApp._show_license_required_notice)
|
|
src_limit = inspect.getsource(basis14.KGDesktopApp._show_device_limit_notice)
|
|
self.assertIn("_show_activation_dialog", src_required)
|
|
self.assertIn("messagebox.showwarning", src_limit)
|
|
self.assertNotIn("_show_activation_dialog", src_limit)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|