! Massive test suite overhaul see details below !
Problem: the old test suite was extremely inflexible This meant that making new tests took way too much time. + This new rework makes the new client's backend much thinner and less "magical" With less magic going on we can pass way more data more easily to the actual http-request engine making the convenience wrapper over top it much more flexible Translating old tests to the new engine might take a while but for now the old client codebase is completely deprecated and will no longer be used+updated
This commit is contained in:
@@ -20,9 +20,11 @@ class Response:
|
||||
Response is wrapper for reading + extracting information we care about
|
||||
Primarily created by Requests that get `make`'d.
|
||||
'''
|
||||
def __init__(self, method: str, url: str, body: str, code: int, expected: int, out=sys.stdout, color=True,
|
||||
truncate_long_body=True, p=None):
|
||||
def __init__(self, method: str, url: str, body: str, code: int, expected: int, headers=None,
|
||||
out=sys.stdout, color=True, truncate_long_body=True, p=None):
|
||||
|
||||
|
||||
self.headers = headers
|
||||
self.method = method
|
||||
self.url = url
|
||||
self.base_url = self.url[:self.url.find('?')]
|
||||
@@ -77,11 +79,13 @@ class Response:
|
||||
if self.code != self.expected:
|
||||
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]}'
|
||||
headers = f'\tHeaders: {self.headers}'
|
||||
if self.color:
|
||||
fail = self._color_failing(fail)
|
||||
|
||||
self.__write_msg(fail)
|
||||
self.__write_msg(content)
|
||||
print(headers)
|
||||
self._log_body()
|
||||
else:
|
||||
msg = f'Passing: {self.method} {self.base_url}'
|
||||
@@ -112,11 +116,12 @@ class Response:
|
||||
return f'{self.code} => {self.body}'
|
||||
|
||||
class Request:
|
||||
def __init__(self, method: str, url: str, params: dict):
|
||||
def __init__(self, method: str, url: str, params: dict, headers: dict):
|
||||
assert(method in ['get', 'post', 'delete'])
|
||||
|
||||
self.method = method
|
||||
self.url = url
|
||||
self.headers = headers
|
||||
if 'content' in params:
|
||||
self.body = params['content']
|
||||
else:
|
||||
@@ -146,14 +151,15 @@ class Request:
|
||||
url = self.url + self.query_string
|
||||
raw_params = (self.query_string, self.qs_dict)
|
||||
if method == 'get':
|
||||
resp = requests.get(url, verify=False)
|
||||
return Response('get', url, resp.text, resp.status_code, hope, p=raw_params)
|
||||
resp = requests.get(url, verify=False, headers=self.headers)
|
||||
return Response('get', url, resp.text, resp.status_code, hope, p=raw_params, headers=self.headers)
|
||||
elif method == 'post':
|
||||
resp = requests.post(url, data=self.body, verify=False)
|
||||
return Response('post', url, resp.text, resp.status_code, hope, p=raw_params)
|
||||
print(self.headers)
|
||||
resp = requests.post(url, data=self.body, verify=False, headers=self.headers)
|
||||
return Response('post', url, resp.text, resp.status_code, hope, p=raw_params, headers=self.headers)
|
||||
elif method == 'delete':
|
||||
resp = requests.delete(url, verify=False)
|
||||
return Response('delete', url, resp.text, resp.status_code, hope, p=raw_params)
|
||||
resp = requests.delete(url, verify=False, headers=self.headers)
|
||||
return Response('delete', url, resp.text, resp.status_code, hope, p=raw_params, headers=self.headers)
|
||||
|
||||
else:
|
||||
raise RequestError('Invalid method passed')
|
||||
|
||||
Reference in New Issue
Block a user