45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
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() |