forked from mtusi2026/mtusi2026lab2
review fixes
This commit is contained in:
+10
-2
@@ -26,13 +26,13 @@ def psql(sql):
|
||||
return compose("exec", "-T", "postgres", "psql", "-U", "messenger", "-d", "messenger", "-t", "-A", "-c", sql)
|
||||
|
||||
|
||||
def call(method, path, data=None, auth=None):
|
||||
def call(method, path, data=None, auth=None, ensure_ascii=True):
|
||||
headers = {"Accept": "application/json"}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
if auth:
|
||||
headers["Authorization"] = auth
|
||||
request = urllib.request.Request(BASE + path, method=method, headers=headers, data=json.dumps(data).encode() if data is not None else None)
|
||||
request = urllib.request.Request(BASE + path, method=method, headers=headers, data=json.dumps(data, ensure_ascii=ensure_ascii).encode() if data is not None else None)
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=5) as response:
|
||||
return response.status, json.loads(response.read() or b"null")
|
||||
@@ -59,6 +59,8 @@ def main():
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=16) as workers:
|
||||
statuses = list(workers.map(competing_register, range(16)))
|
||||
assert statuses.count(201) == 1 and statuses.count(409) == 15, statuses
|
||||
spaces_name = "spaces_" + uuid.uuid4().hex[:12]
|
||||
assert register(spaces_name, " " * 12)[0] == 400
|
||||
status, session = login(name, password)
|
||||
assert status == 201
|
||||
basic = base64.b64encode((name + ":" + password).encode()).decode()
|
||||
@@ -79,6 +81,12 @@ def main():
|
||||
finally:
|
||||
psql("DROP TRIGGER lab2_rollback_guard ON chat_members; DROP FUNCTION lab2_rollback_guard();")
|
||||
path = "/api/v1/chats/" + chat["id"] + "/messages"
|
||||
emoji_text = "😀" * 4000
|
||||
assert len(json.dumps({"text": emoji_text}).encode()) == 48012
|
||||
assert len(json.dumps({"text": emoji_text}, ensure_ascii=False).encode()) == 16012
|
||||
for ensure_ascii in (True, False):
|
||||
status, sent = call("POST", path, {"text": emoji_text}, token, ensure_ascii=ensure_ascii)
|
||||
assert status == 201 and sent["text"] == emoji_text
|
||||
assert call("POST", path, {"text": "before outage"}, token)[0] == 201
|
||||
malformed = base64.urlsafe_b64encode(json.dumps([chat["id"], 17, user_id]).encode()).decode().rstrip("=")
|
||||
assert call("GET", path + "?cursor=" + malformed, auth=token)[0] == 400
|
||||
|
||||
Reference in New Issue
Block a user