forked from mtusi2026/mtusi2026lab4
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
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) |