Files
microfish/backend/tests/test_locale_runtime.py
Kunthawat Greethong 8b84378fe1 feat: SaaS foundation for CrowdSight
Elevate MiroFish/CrowdSight from single-container dev to a SaaS foundation:

- Local memory backend (Zep-compatible): memory services/models, local graph
  builder + updater, AgentActivity seam, import-boundary isolation; Zep stays
  default, local is opt-in behind MEMORY_BACKEND. Semantic parity not yet proven.
- Durable product persistence: projects/simulations/reports schema (migration
  0007) + tenant/owner-scoped ProductRepository + dual-write + scoped_project
  read-first + ArtifactStore abstraction; durable JobQueue + worker.py.
- SaaS hardening: durable RateLimiter (wired to login), UsageService (LLM
  accounting), redacted AuditService, idempotency, CORS allowlist, safe API
  errors, single-use PasswordResetService + endpoints (covers invite-pending).
- Exactly 3 roles (super_admin/admin/user) with tenant authz policy.
- Admin UI: GET/POST/PATCH /api/admin/users + GET/PUT /api/admin/settings
  (super-admin only, encrypted/masked); AdminView.vue + SettingsView.vue with
  admin/super-admin route guards, th/en i18n.
- Production deploy topology: multi-stage Dockerfile (frontend build + gunicorn
  wsgi + nginx SPA-proxy + supervisord worker), backend/wsgi.py, gunicorn dep.

Backend 197 passed; frontend 10 tests + build green. ruff unavailable (gap).
No commit of credentials; secrets handled via env/.env.example.
Deferred: Zep semantic A/B parity, object storage cutover, mobile QA, EasyPanel
container build of deploy topology.
2026-08-31 13:05:21 +07:00

41 lines
1.3 KiB
Python

import unittest
from flask import Flask
from app.utils import locale as _LOCALE
_FLASK_APP = Flask(__name__)
class LocaleRuntimeTests(unittest.TestCase):
def tearDown(self):
_LOCALE.set_locale("th")
def test_background_locale_normalizes_legacy_and_unknown_values(self):
_LOCALE.set_locale("zh-CN")
self.assertEqual(_LOCALE.get_locale(), "th")
_LOCALE.set_locale("en-US")
self.assertEqual(_LOCALE.get_locale(), "en")
_LOCALE.set_locale("fr")
self.assertEqual(_LOCALE.get_locale(), "th")
def test_request_locale_negotiates_supported_language_only(self):
with _FLASK_APP.test_request_context(
headers={"Accept-Language": "zh-CN;q=1, en-US;q=0.8, th;q=0"}
):
self.assertEqual(_LOCALE.get_locale(), "en")
def test_translation_fallback_is_not_chinese(self):
_LOCALE.set_locale("zh")
translated = _LOCALE.t("api.projectNotFound", id="demo")
self.assertFalse(any("\u3400" <= char <= "\u9fff" for char in translated))
self.assertNotEqual(translated, "api.projectNotFound")
self.assertFalse(
any("\u3400" <= char <= "\u9fff" for char in _LOCALE.get_language_instruction())
)
if __name__ == "__main__":
unittest.main()