Conceptualizing how future tests will be written. IDeally we can specify them even later in json so that we can generate huge amounts of tests in any language and toss them through this pipeline fast as hell

This commit is contained in:
shockrah 2021-01-20 20:09:29 -08:00
parent 2f15e2ef62
commit d31b02089e

View File

@ -14,9 +14,12 @@ class Worker:
'''
self.domain = domain
self.requests = {}
self.responses = {}
self.jwt = None # never gets assigned until /login is hit
if create_admin:
self.creds = self.__create_admin()
self.basic_creds = self.__create_admin()
# two most important details for basically everything
self.id = self.body['id']
self.secret = self.body['secret']
@ -24,8 +27,9 @@ class Worker:
# for now we use this because my dev server has this fake ass acc on it
self.secret = 'mH7DfAfSLHhVbo9OW4dmqTbzzLnFaZQLxoZFIlKvKHm4NfpLyZsZrYdf12aACZXyEQxELOlBTe2rc36vTPVd8A==',
self.id = 2
# This is to never be overwritten
self.creds = {
self.basic_creds = {
'name': 'owner sama uwu',
'joindate': 69,
'status': 0,
@ -45,7 +49,8 @@ class Worker:
print('TESTBOT UNABLE TO LOAD JSON DATA FROM -c flag', file=sys.stderr)
exit(1)
def update_jwt(self, jwt: str):
self.jwt = jwt
def log(self, params: dict, url: str, method: str, request: requests.Response, body=True):
print(f'TESTBOT {method} {url} {request.status_code}', file=self.out)
@ -53,28 +58,33 @@ class Worker:
if body:
print(f'TESTBOT\t\t[Body]: {request.text}\n', file=self.out)
def _build_req_body(self, **options):
pass
def request(self, method: str, path: str, opts: dict, expectation: int):
assert(path[0] == '/')
def post(self, url, jwt=False, **opts):
pass
# Build the request and store it in our structure
url = self.domain + path
req = Request(method, url, opts)
r_id = time.time()
self.requests[r_id] = req
def get(self, url, jwt=False, **opts):
pass
def delete(self):
pass
resp = req.make(expectation)
self.responses[r_id] = resp
return req.id
def spam_messages(channel, jwt, worker):
for _ in range(15):
worker.post('/message/send', jwt=jwt, channel=channel, content='dummy post')
def run(worker):
def run(worker: Worker):
VOICE_CHAN = 1
TEXT_CHAN = 2
worker.stdout_to_stderr()
tests = [
{'init': ['get', '/channels/list', {}], 'hope': 400}, # sanity check
{'init': ['post', '/login', {}], 'hope': 200},
{'init': ['post', '/channels/list', **creds], 'hope': 200},
]
# the first two are sanity checks and should not faill
worker.get('/channels/list') # Should 400 or something since we're not sending the right keys
@ -130,5 +140,5 @@ def run(worker):
if __name__ == '__main__':
worker = Worker('http://localhost:8888', create_admin=False, init_verbose=True)
worker = Worker('http://localhost:8888', create_admin=False)
run(worker)