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