"""API /api/updates/* для баннера обновлений.""" from __future__ import annotations import os import tempfile import unittest from app import create_app, db from config import TestingConfig class UpdateApiConfig(TestingConfig): _TMP_DIR = tempfile.mkdtemp(prefix="wesp-update-api-") SQLALCHEMY_DATABASE_URI = f"sqlite:///{os.path.join(_TMP_DIR, 'recipes_test.db')}" SQLALCHEMY_BINDS = {"reports": f"sqlite:///{os.path.join(_TMP_DIR, 'reports_test.db')}"} SYNC_CLIENT_VERSION = "2.0.0" UPDATE_RESTART_CMD = "echo restart" class UpdateNotifierApiTests(unittest.TestCase): def setUp(self) -> None: self.app = create_app(UpdateApiConfig) self.client = self.app.test_client() self.ctx = self.app.app_context() self.ctx.push() db.create_all() def tearDown(self) -> None: db.session.remove() db.drop_all() self.ctx.pop() def test_updates_status_on_localhost_without_session(self) -> None: r = self.client.get("/api/updates/status") self.assertEqual(r.status_code, 200) body = r.get_json() self.assertIn("current_version", body) self.assertEqual(body["current_version"], "2.0.0") self.assertFalse(body.get("update_available")) def test_install_without_pending_returns_error(self) -> None: r = self.client.post("/api/updates/install", json={}) self.assertIn(r.status_code, (404, 500)) body = r.get_json() self.assertIn("error", body) def test_updates_status_includes_last_update_state(self) -> None: r = self.client.get("/api/updates/status") self.assertEqual(r.status_code, 200) body = r.get_json() self.assertIn("last_update_state", body) def test_health_endpoint(self) -> None: r = self.client.get("/api/health") self.assertEqual(r.status_code, 200) self.assertIn("ok", r.get_json()) if __name__ == "__main__": unittest.main()