Beginning refactor of test client to more cleanly create new tests
Body parameters were being polluted so new logic is required to make the worker more stable and ignore its state properly
This commit is contained in:
parent
22d2f3eea0
commit
79d77e0007
@ -2,6 +2,9 @@ import time
|
|||||||
import subprocess, os, sys
|
import subprocess, os, sys
|
||||||
import json, requests
|
import json, requests
|
||||||
|
|
||||||
|
class RequestError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class Response:
|
class Response:
|
||||||
def __init__(self, body, code):
|
def __init__(self, body, code):
|
||||||
self.body = body
|
self.body = body
|
||||||
@ -10,6 +13,45 @@ class Response:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.code} => {self.body}'
|
return f'{self.code} => {self.body}'
|
||||||
|
|
||||||
|
class Request:
|
||||||
|
def __init__(self, domain: str, params: dict):
|
||||||
|
assert(path[len(path) - 1] != '/')
|
||||||
|
|
||||||
|
self.domain = domain
|
||||||
|
self.params = params
|
||||||
|
|
||||||
|
def _make_request(self, method: str, path: str, hope: int):
|
||||||
|
# Lower driver for actuall making the request we are looking for
|
||||||
|
assert(path.startswith('/'))
|
||||||
|
method = method.lower()
|
||||||
|
|
||||||
|
url = self.domain + path
|
||||||
|
if method == 'get':
|
||||||
|
resp = requests.get(url, data=self.params)
|
||||||
|
return Response(resp.body, resp.status_code, hope)
|
||||||
|
elif method == 'post':
|
||||||
|
resp = requests.post(url, data=self.params)
|
||||||
|
return Response(resp.body, resp.status_code, hope)
|
||||||
|
elif: method == 'delete':
|
||||||
|
resp = requests.delete(url, data=self.params)
|
||||||
|
return Response(resp.body, resp.status_code, hope)
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise RequestError('Invalid method passed')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get(self, path: str, hope: int):
|
||||||
|
return self._make_request('get', path, hope)
|
||||||
|
|
||||||
|
def post(self, path: str, hope: int):
|
||||||
|
return self._make_request('post', path, hope)
|
||||||
|
|
||||||
|
def delete(self, path: str, hope: int):
|
||||||
|
return self._make_request('delete', path, hope)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Test:
|
class Test:
|
||||||
def __init__(self, base='http://localhost:8888', create_admin=False, admin=None, init_verbose=False):
|
def __init__(self, base='http://localhost:8888', create_admin=False, admin=None, init_verbose=False):
|
||||||
'''
|
'''
|
||||||
@ -36,12 +78,16 @@ class Test:
|
|||||||
# for now we use this because my dev server has this fake ass acc on it
|
# for now we use this because my dev server has this fake ass acc on it
|
||||||
self.secret = 'mH7DfAfSLHhVbo9OW4dmqTbzzLnFaZQLxoZFIlKvKHm4NfpLyZsZrYdf12aACZXyEQxELOlBTe2rc36vTPVd8A==',
|
self.secret = 'mH7DfAfSLHhVbo9OW4dmqTbzzLnFaZQLxoZFIlKvKHm4NfpLyZsZrYdf12aACZXyEQxELOlBTe2rc36vTPVd8A==',
|
||||||
self.id = 2
|
self.id = 2
|
||||||
|
# Required params
|
||||||
self.body = {
|
self.body = {
|
||||||
'name': 'owner sama uwu',
|
'name': 'owner sama uwu',
|
||||||
'joindate': 69,
|
'joindate': 69,
|
||||||
'status': 0,
|
'status': 0,
|
||||||
'permissions': 18446744073709551615
|
'permissions': 18446744073709551615
|
||||||
}
|
}
|
||||||
|
self.default_body = {}
|
||||||
|
# deep copy of body to prevent side-channel writes
|
||||||
|
for k in self.body: self.default_body[k] = self.body[k]
|
||||||
|
|
||||||
self.base = base
|
self.base = base
|
||||||
|
|
||||||
@ -72,7 +118,7 @@ class Test:
|
|||||||
print(f'TESTBOT\t\t[Body]: {request.text}\n', file=self.out)
|
print(f'TESTBOT\t\t[Body]: {request.text}\n', file=self.out)
|
||||||
|
|
||||||
def _build_req_body(self, **options):
|
def _build_req_body(self, **options):
|
||||||
_map = self.body
|
_map = self.default_body
|
||||||
for key in options:
|
for key in options:
|
||||||
_map[key] = options[key]
|
_map[key] = options[key]
|
||||||
|
|
||||||
@ -188,11 +234,19 @@ def run(worker):
|
|||||||
# pass 200(all)
|
# pass 200(all)
|
||||||
spam_messages(send_chan['id'], jwt, worker)
|
spam_messages(send_chan['id'], jwt, worker)
|
||||||
now = time.time()
|
now = time.time()
|
||||||
worker.get('/message/get_range', jwt=jwt, **{
|
messages = json.loads(worker.get('/message/get_range', jwt=jwt, **{
|
||||||
'start-time': int(now - 15),
|
'start-time': int(now - 15),
|
||||||
'end-time': int(now + 1),
|
'end-time': int(now + 1),
|
||||||
'channel': send_chan['id']
|
'channel': send_chan['id']
|
||||||
|
}))
|
||||||
|
|
||||||
|
# 200 pass
|
||||||
|
from_id = worker.get('/message/from_id', jwt=jwt, **{
|
||||||
|
'channel': send_chan['id'],
|
||||||
|
'start': messages['messages'][0]['id']
|
||||||
})
|
})
|
||||||
|
print('done')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user