Files
xiaoxia-saas/tests/unit/test_smoke_external_services.py
T
Xiaoxia AI 1f89f8edfe
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 14s
Deploy / Deploy Staging (push) Successful in 2m7s
Deploy / Deploy Production (push) Has been skipped
chore(release): allow smtp skip in strict smoke
2026-06-21 14:09:29 +08:00

108 lines
3.3 KiB
Python

import types
import scripts.smoke_external_services as smoke
def test_external_smoke_skips_disabled_services(monkeypatch, capsys):
for key in [
"ENABLE_REDIS_SESSIONS",
"ENABLE_EMAIL_DELIVERY",
"OSS_ENDPOINT",
"OSS_ACCESS_KEY_ID",
"OSS_ACCESS_KEY_SECRET",
"OSS_BUCKET_NAME",
]:
monkeypatch.delenv(key, raising=False)
smoke.smoke_redis(strict=False)
smoke.smoke_smtp(strict=False, send_email_to=None)
smoke.smoke_oss(strict=False)
output = capsys.readouterr().out
assert "SKIP redis sessions" in output
assert "SKIP smtp" in output
assert "SKIP oss" in output
def test_external_smoke_requires_oss_in_strict_mode(monkeypatch):
monkeypatch.delenv("OSS_ENDPOINT", raising=False)
try:
smoke.smoke_oss(strict=True)
except RuntimeError as error:
assert "missing required env: OSS_ENDPOINT" in str(error)
else:
raise AssertionError("strict OSS smoke should fail without credentials")
def test_external_smoke_redis_round_trip(monkeypatch, capsys):
class FakeRedis:
def __init__(self):
self.values = {}
def ping(self):
return True
def setex(self, key, seconds, value):
self.values[key] = value
def get(self, key):
return self.values[key]
def delete(self, key):
self.values.pop(key, None)
fake_client = FakeRedis()
monkeypatch.setenv("ENABLE_REDIS_SESSIONS", "true")
monkeypatch.setenv("REDIS_URL", "redis://redis:6379/0")
monkeypatch.setattr(smoke.redis.Redis, "from_url", lambda *args, **kwargs: fake_client)
smoke.smoke_redis(strict=False)
assert "OK redis sessions" in capsys.readouterr().out
def test_external_smoke_can_skip_smtp_in_strict_mode(monkeypatch, capsys):
monkeypatch.setattr(smoke, "smoke_redis", lambda strict: print("OK redis sessions"))
monkeypatch.setattr(smoke, "smoke_oss", lambda strict: print("OK oss upload/download/delete"))
assert smoke.main(["--strict", "--skip-smtp"]) == 0
output = capsys.readouterr().out
assert "SKIP smtp: explicitly skipped" in output
assert "OK oss upload/download/delete" in output
def test_external_smoke_smtp_connect_login(monkeypatch, capsys):
actions = []
class FakeSMTP:
def __init__(self, host, port, timeout):
actions.append((host, port, timeout))
def __enter__(self):
return self
def __exit__(self, exc_type, exc, tb):
return False
def starttls(self):
actions.append("tls")
def login(self, user, password):
actions.append(("login", user, password))
monkeypatch.setenv("ENABLE_EMAIL_DELIVERY", "true")
monkeypatch.setenv("SMTP_HOST", "smtp.local")
monkeypatch.setenv("SMTP_PORT", "587")
monkeypatch.setenv("SMTP_USER", "mailer")
monkeypatch.setenv("SMTP_PASSWORD", "secret")
monkeypatch.setenv("SMTP_FROM_EMAIL", "noreply@example.test")
monkeypatch.setenv("SMTP_USE_TLS", "true")
monkeypatch.setattr(smoke.smtplib, "SMTP", FakeSMTP)
smoke.smoke_smtp(strict=False, send_email_to=None)
assert actions == [("smtp.local", 587, 10), "tls", ("login", "mailer", "secret")]
assert "OK smtp connect/login" in capsys.readouterr().out