From e39179da78bcbcad3d9958eaf28ef030eba570ec Mon Sep 17 00:00:00 2001 From: shockrah Date: Wed, 20 Jan 2021 21:26:50 -0800 Subject: [PATCH] Response now has a .json method to pull the body out as a dictionary --- server-api/client-tests/web/http.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server-api/client-tests/web/http.py b/server-api/client-tests/web/http.py index aec896b..0e2a523 100644 --- a/server-api/client-tests/web/http.py +++ b/server-api/client-tests/web/http.py @@ -1,6 +1,7 @@ import sys import requests import time +import json class RequestError(Exception): pass @@ -46,6 +47,17 @@ class Response: print(msg, file=self.out) + def json(self): + ''' + Force an interpretation of json from the body + NOTE: this method is rather obtuse and a massive afterthough so its usage + should be limited as much as possible + ''' + try: + return json.loads(self.body) + except: + return {} + def __str__(self): ''' Returns: str(Response) -> `code => response.bdoy` @@ -79,7 +91,7 @@ class Request: raise RequestError('Invalid method passed') - def make(self, hope: int) -> Response: + def make(self, hope: int, auth: str) -> Response: ''' @param hope: int -> status code we hope to get back @return Response -> Wrapper around server http response