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:
parent
2f15e2ef62
commit
d31b02089e
@ -14,9 +14,12 @@ class Worker:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
self.domain = domain
|
self.domain = domain
|
||||||
|
self.requests = {}
|
||||||
|
self.responses = {}
|
||||||
|
|
||||||
|
self.jwt = None # never gets assigned until /login is hit
|
||||||
if create_admin:
|
if create_admin:
|
||||||
self.creds = self.__create_admin()
|
self.basic_creds = self.__create_admin()
|
||||||
# two most important details for basically everything
|
# two most important details for basically everything
|
||||||
self.id = self.body['id']
|
self.id = self.body['id']
|
||||||
self.secret = self.body['secret']
|
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
|
# 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
|
||||||
|
|
||||||
# This is to never be overwritten
|
# This is to never be overwritten
|
||||||
self.creds = {
|
self.basic_creds = {
|
||||||
'name': 'owner sama uwu',
|
'name': 'owner sama uwu',
|
||||||
'joindate': 69,
|
'joindate': 69,
|
||||||
'status': 0,
|
'status': 0,
|
||||||
@ -45,7 +49,8 @@ class Worker:
|
|||||||
print('TESTBOT UNABLE TO LOAD JSON DATA FROM -c flag', file=sys.stderr)
|
print('TESTBOT UNABLE TO LOAD JSON DATA FROM -c flag', file=sys.stderr)
|
||||||
exit(1)
|
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):
|
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)
|
print(f'TESTBOT {method} {url} {request.status_code}', file=self.out)
|
||||||
@ -53,28 +58,33 @@ class Worker:
|
|||||||
if body:
|
if body:
|
||||||
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 request(self, method: str, path: str, opts: dict, expectation: int):
|
||||||
pass
|
assert(path[0] == '/')
|
||||||
|
|
||||||
def post(self, url, jwt=False, **opts):
|
# Build the request and store it in our structure
|
||||||
pass
|
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):
|
resp = req.make(expectation)
|
||||||
pass
|
self.responses[r_id] = resp
|
||||||
|
|
||||||
def delete(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
return req.id
|
||||||
|
|
||||||
|
|
||||||
def spam_messages(channel, jwt, worker):
|
def spam_messages(channel, jwt, worker):
|
||||||
for _ in range(15):
|
for _ in range(15):
|
||||||
worker.post('/message/send', jwt=jwt, channel=channel, content='dummy post')
|
worker.post('/message/send', jwt=jwt, channel=channel, content='dummy post')
|
||||||
|
|
||||||
def run(worker):
|
def run(worker: Worker):
|
||||||
VOICE_CHAN = 1
|
VOICE_CHAN = 1
|
||||||
TEXT_CHAN = 2
|
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
|
# 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
|
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__':
|
if __name__ == '__main__':
|
||||||
worker = Worker('http://localhost:8888', create_admin=False, init_verbose=True)
|
worker = Worker('http://localhost:8888', create_admin=False)
|
||||||
run(worker)
|
run(worker)
|
||||||
|
Loading…
Reference in New Issue
Block a user