forked from mtusi2026/mtusi2026lab3
Исправление ошибок ЛР3
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import base64
|
||||
import uuid
|
||||
|
||||
import httpx
|
||||
|
||||
BASE = "http://localhost:8080"
|
||||
|
||||
|
||||
def register_and_login(c):
|
||||
username = "m_" + uuid.uuid4().hex[:8]
|
||||
password = "Test-password-1234"
|
||||
c.post(f"{BASE}/api/v1/users", json={
|
||||
"username": username, "display_name": "T", "password": password,
|
||||
})
|
||||
credential = base64.b64encode((username + ":" + password).encode()).decode()
|
||||
s = c.post(f"{BASE}/api/v1/auth/sessions",
|
||||
headers={"Authorization": "Basic " + credential}).json()
|
||||
return s["user"]["id"], s["token"]
|
||||
|
||||
|
||||
def main():
|
||||
with httpx.Client(timeout=10) as c:
|
||||
alice_id, alice_token = register_and_login(c)
|
||||
chat = c.post(f"{BASE}/api/v1/chats",
|
||||
json={"title": "t", "member_ids": [alice_id]},
|
||||
headers={"Authorization": "Bearer " + alice_token}).json()
|
||||
|
||||
r = c.post(
|
||||
f"{BASE}/api/v1/chats/{chat['id']}/messages",
|
||||
json={"text": " "},
|
||||
headers={
|
||||
"Authorization": "Bearer " + alice_token,
|
||||
"Idempotency-Key": uuid.uuid4().hex,
|
||||
},
|
||||
)
|
||||
print("blank text:", r.status_code, r.text[:200])
|
||||
|
||||
r = c.post(
|
||||
f"{BASE}/api/v1/chats/{chat['id']}/messages",
|
||||
json={"text": "hi", "sender_id": "extra"},
|
||||
headers={
|
||||
"Authorization": "Bearer " + alice_token,
|
||||
"Idempotency-Key": uuid.uuid4().hex,
|
||||
},
|
||||
)
|
||||
print("extra sender_id:", r.status_code, r.text[:200])
|
||||
|
||||
r = c.post(
|
||||
f"{BASE}/api/v1/users",
|
||||
json={"username": " ", "display_name": "X", "password": "Test-password-1234"},
|
||||
)
|
||||
print("blank username:", r.status_code, r.text[:200])
|
||||
|
||||
r = c.post(
|
||||
f"{BASE}/api/v1/chats",
|
||||
json={"title": " ", "member_ids": [alice_id]},
|
||||
headers={"Authorization": "Bearer " + alice_token},
|
||||
)
|
||||
print("blank chat title:", r.status_code, r.text[:200])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user