forked from mtusi2026/mtusi2026lab2
внес правки
This commit is contained in:
@@ -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)
|
||||
@@ -9,7 +9,8 @@ def register_and_login(username, password):
|
||||
requests.post(f"{BASE_URL}/api/v1/users", json={
|
||||
"username": username, "display_name": "Test", "password": password
|
||||
})
|
||||
resp = requests.post(f"{BASE_URL}/auth/sessions", auth=(username, password))
|
||||
|
||||
resp = requests.post(f"{BASE_URL}/api/v1/auth/sessions", auth=(username, password))
|
||||
return resp.json()["token"]
|
||||
|
||||
|
||||
@@ -20,18 +21,15 @@ def test_wrong_password():
|
||||
"username": username, "display_name": "Test", "password": password
|
||||
})
|
||||
|
||||
resp = requests.post(f"{BASE_URL}/auth/sessions", auth=(username, "wrong_password"))
|
||||
resp = requests.post(f"{BASE_URL}/api/v1/auth/sessions", auth=(username, "wrong_password"))
|
||||
assert resp.status_code == 401
|
||||
|
||||
|
||||
def test_logout():
|
||||
token = register_and_login("test_logout", "valid_password_123")
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
assert requests.get(f"{BASE_URL}/api/v1/users/me", headers=headers).status_code == 200
|
||||
|
||||
assert requests.delete(f"{BASE_URL}/auth/sessions/current", headers=headers).status_code == 204
|
||||
|
||||
assert requests.delete(f"{BASE_URL}/api/v1/auth/sessions/current", headers=headers).status_code == 204
|
||||
assert requests.get(f"{BASE_URL}/api/v1/users/me", headers=headers).status_code == 401
|
||||
|
||||
|
||||
@@ -41,6 +39,6 @@ def test_expiry():
|
||||
|
||||
assert requests.get(f"{BASE_URL}/api/v1/users/me", headers=headers).status_code == 200
|
||||
|
||||
time.sleep(2)
|
||||
time.sleep(3)
|
||||
|
||||
assert requests.get(f"{BASE_URL}/api/v1/users/me", headers=headers).status_code == 401
|
||||
Reference in New Issue
Block a user