From fb36f70d957237064f03e94aa2ab895db3526f2b Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 11 Feb 2021 15:04:41 -0800 Subject: [PATCH] Response logs now optionally show the query string when logging, defaulting to always show the logs for now however --- json-api/client-tests/web/http.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/json-api/client-tests/web/http.py b/json-api/client-tests/web/http.py index 8c6439a..aa91fba 100644 --- a/json-api/client-tests/web/http.py +++ b/json-api/client-tests/web/http.py @@ -18,6 +18,12 @@ class Response: self.method = method self.url = url + self.base_url = self.url[:self.url.find('?')] + try: + self.query_string = self.url.strip(self.base_url)[1:] + except: # do this for empty query strings + self.query_string = self.url.strip(self.base_url) + self.body = body #typically a string before parsing anything self.code = code #u16 self.expected = expected #u16 @@ -45,6 +51,8 @@ class Response: if (len(s) == 1 or len(s) == 0) is False: print(s, file=self.out) def _log_body(self): + # TODO: refactor this func to be more flexible as its hella useful + # for truncating ugly long as hell strings if self.truncate_long_body: if len(self.body) > 80: msg = self.body @@ -58,10 +66,9 @@ class Response: else: self.__write_msg(f'\t{self.body}') - def log(self): + def log(self, show_query: bool = True): if self.code != self.expected: - base_url = self.url[:self.url.find('?')] - fail = f'Failed {self.method.upper()} {base_url}\t{self.code} expected {self.expected}\n' + fail = f'Failed {self.method.upper()} {self.base_url}\t{self.code} expected {self.expected}\n' content = f'\tRaw params: {self.raw_params[0]}\n\tParsed Params: {self.raw_params[1]}' if self.color: fail = self._color_failing(fail) @@ -70,10 +77,14 @@ class Response: self.__write_msg(content) self._log_body() else: - msg = f'Passing: {self.method} {self.url}' + msg = f'Passing: {self.method} {self.base_url}' if self.color: msg = self._color_passing(msg) + # no color on the query like ever(because its typically massive + if show_query: + msg += f'\n\t{self.query_string[:80]}' + self.__write_msg(msg) def json(self):