Files
javadandCursor b93ecf1691 Initial commit of the Kamidso API.
Keep source, config, and deploy files. Leave runtime data, uploads, and logs out of git.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-10 13:43:09 +03:30

60 lines
2.1 KiB
Python

import pytest
from kamidso.api.tokens import decode_jwt, encode_jwt
from kamidso.contracts.errors import KamidsoError, KamidsoErrorCode
from kamidso.settings.flags import FeatureFlags, load_kamidso_settings
from kamidso.utils.mobile import normalize_mobile
def test_jwt_roundtrip():
token = encode_jwt({"sub": "usr_1", "exp": 4102444800}, "secret")
payload = decode_jwt(token, "secret")
assert payload is not None
assert payload["sub"] == "usr_1"
assert decode_jwt(token, "other") is None
def test_feature_flags_phase1_defaults():
flags = FeatureFlags()
assert flags.chat is True
assert flags.scheduled_tasks is False
assert flags.reports is False
assert flags.radar is False
assert flags.dashboards is False
def test_error_is_public_and_persian():
err = KamidsoError(KamidsoErrorCode.FILE_ANALYSIS_FAILED, retryable=True, run_id="run_9")
payload = err.to_public_dict()
assert payload["code"] == "FILE_ANALYSIS_FAILED"
assert payload["retryable"] is True
assert "run_9" in payload["run_id"]
assert "details" not in payload
def test_otp_settings_defaults():
settings = load_kamidso_settings()
assert settings.kavenegar_otp_template == "sendotpkamidso"
assert settings.otp_mock_enabled is True
assert settings.otp_expire_minutes == 5
assert settings.otp_max_attempts == 5
def test_otp_error_messages_are_persian():
assert "موبایل" in KamidsoError(KamidsoErrorCode.INVALID_MOBILE).message
assert "کد تأیید" in KamidsoError(KamidsoErrorCode.OTP_INVALID).message
def test_normalize_mobile_iranian_formats():
assert normalize_mobile("09123456789") == "09123456789"
assert normalize_mobile("+989123456789") == "09123456789"
assert normalize_mobile("989123456789") == "09123456789"
assert normalize_mobile("9123456789") == "09123456789"
assert normalize_mobile("۰۹۱۲۳۴۵۶۷۸۹") == "09123456789"
def test_normalize_mobile_rejects_invalid():
with pytest.raises(KamidsoError) as exc:
normalize_mobile("12345")
assert exc.value.code == KamidsoErrorCode.INVALID_MOBILE