refactor: вынес сервисы и ui-компоненты
- вынес token/chat/update логику в services - вынес диалог и текст инструкции в ui - добавил и обновил тесты для нового слоя
This commit is contained in:
53
tests/test_token_store.py
Normal file
53
tests/test_token_store.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
_SPEC = importlib.util.spec_from_file_location(
|
||||
"token_store",
|
||||
Path("services/token_store.py"),
|
||||
)
|
||||
_MODULE = importlib.util.module_from_spec(_SPEC)
|
||||
_SPEC.loader.exec_module(_MODULE)
|
||||
load_token = _MODULE.load_token
|
||||
save_token = _MODULE.save_token
|
||||
|
||||
|
||||
class TokenStoreTests(unittest.TestCase):
|
||||
def test_save_and_load_non_expiring_token(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
token_file = Path(td) / "token.json"
|
||||
with patch.object(_MODULE.os, "name", "posix"):
|
||||
expiration = save_token(
|
||||
token="abc123",
|
||||
token_file=str(token_file),
|
||||
app_data_dir=td,
|
||||
expires_in=0,
|
||||
)
|
||||
token, loaded_expiration = load_token(str(token_file))
|
||||
|
||||
self.assertEqual(expiration, 0)
|
||||
self.assertEqual(token, "abc123")
|
||||
self.assertEqual(loaded_expiration, 0)
|
||||
|
||||
def test_expired_token_is_removed(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
token_file = Path(td) / "token.json"
|
||||
with patch.object(_MODULE.os, "name", "posix"):
|
||||
with patch.object(_MODULE.time, "time", return_value=1000):
|
||||
save_token(
|
||||
token="abc123",
|
||||
token_file=str(token_file),
|
||||
app_data_dir=td,
|
||||
expires_in=1,
|
||||
)
|
||||
with patch.object(_MODULE.time, "time", return_value=2000):
|
||||
token, expiration = load_token(str(token_file))
|
||||
|
||||
self.assertIsNone(token)
|
||||
self.assertIsNone(expiration)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user