lab3: nginx, replicas, idempotency, tests

This commit is contained in:
2026-11-06 17:23:38 +03:00
commit 46c829b730
96 changed files with 206384 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
import subprocess
import time
import requests
BASE_URL = "http://localhost:8080"
def test_postgres_down_returns_503():
subprocess.run(["docker", "compose", "stop", "db"], check=True)
time.sleep(1)
try:
resp = requests.get(f"{BASE_URL}/health/ready")
assert resp.status_code == 503, f"Ожидался 503, получен {resp.status_code}"
finally:
subprocess.run(["docker", "compose", "start", "db"], check=True)
time.sleep(2)
def test_redis_down_returns_500_json():
subprocess.run(["docker", "pause", "mtusi_messenger_redis"], check=True)
try:
headers = {"Authorization": "Bearer test_token"}
resp = requests.get(f"{BASE_URL}/api/v1/users/me", headers=headers)
assert resp.status_code == 500, f"Ожидался 500, получен {resp.status_code}"
body = resp.json()
assert body["error"]["code"] == "internal_error", "Неверный код ошибки"
assert "request_id" in body["error"], "Нет request_id"
finally:
subprocess.run(["docker", "unpause", "mtusi_messenger_redis"], check=True)