refactor: вынес сервисы и ui-компоненты
- вынес token/chat/update логику в services - вынес диалог и текст инструкции в ui - добавил и обновил тесты для нового слоя
This commit is contained in:
50
tests/test_auto_update_service.py
Normal file
50
tests/test_auto_update_service.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
_SPEC = importlib.util.spec_from_file_location(
|
||||
"auto_update_service",
|
||||
Path("services/auto_update_service.py"),
|
||||
)
|
||||
_MODULE = importlib.util.module_from_spec(_SPEC)
|
||||
_SPEC.loader.exec_module(_MODULE)
|
||||
AutoUpdateService = _MODULE.AutoUpdateService
|
||||
|
||||
|
||||
class AutoUpdateServiceTests(unittest.TestCase):
|
||||
def test_extract_sha256_from_text(self):
|
||||
digest = "a" * 64
|
||||
text = f"{digest} AnabasisManager-1.0.0-win.zip\n"
|
||||
extracted = AutoUpdateService.extract_sha256_from_text(
|
||||
text,
|
||||
"AnabasisManager-1.0.0-win.zip",
|
||||
)
|
||||
self.assertEqual(extracted, digest)
|
||||
|
||||
def test_sha256_file(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "payload.bin"
|
||||
payload = b"anabasis"
|
||||
path.write_bytes(payload)
|
||||
expected = hashlib.sha256(payload).hexdigest()
|
||||
self.assertEqual(AutoUpdateService.sha256_file(str(path)), expected)
|
||||
|
||||
def test_build_update_script_contains_core_vars(self):
|
||||
script = AutoUpdateService.build_update_script(
|
||||
app_dir=r"C:\Apps\AnabasisManager",
|
||||
source_dir=r"C:\Temp\Extracted",
|
||||
exe_name="AnabasisManager.exe",
|
||||
target_pid=1234,
|
||||
)
|
||||
script_text = Path(script).read_text(encoding="utf-8")
|
||||
self.assertIn("set APP_DIR=", script_text)
|
||||
self.assertIn("set SRC_DIR=", script_text)
|
||||
self.assertIn("set EXE_NAME=", script_text)
|
||||
self.assertIn("set TARGET_PID=", script_text)
|
||||
self.assertIn(":rollback", script_text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user