Лабораторная 5

This commit is contained in:
2026-11-24 17:58:42 +03:00
parent 276dbdad8a
commit 3938900ec6
40 changed files with 3130 additions and 27 deletions
+6 -3
View File
@@ -13,8 +13,8 @@ import urllib.request
import uuid
ROOT = Path(__file__).resolve().parents[1]
LAB = json.loads((ROOT / 'lab.json').read_text())['number']
SPEC = json.loads((ROOT / 'contracts/openapi.json').read_text())
LAB = json.loads((ROOT / 'lab.json').read_text(encoding='utf-8'))['number']
SPEC = json.loads((ROOT / 'contracts/openapi.json').read_text(encoding='utf-8'))
class Failure(AssertionError):
pass
@@ -140,7 +140,10 @@ class Client:
payload = json.loads(data)
except (ValueError,UnicodeError):
raise Failure('invalid response JSON') from None
shape(payload, 'Error' if status>=400 else schema)
try:
shape(payload, 'Error' if status>=400 else schema)
except Failure as exc:
raise Failure(method + ' ' + path.split('?')[0] + ': ' + str(exc)) from None
if status>=400:
check(payload['error']['request_id']==rh.get('X-Request-Id'),'error request_id differs from header')
if status==401 and LAB>=2: