Client tester now uses channel_id where applicable for api parameters

as well as being less explicit about what it passes to the query string
This commit is contained in:
shockrah 2021-02-10 23:15:05 -08:00
parent 2d6739438a
commit 21b184b324

View File

@ -52,16 +52,14 @@ class Worker:
@auth: Denotes if we use basic auth or jwt if its not 'basic'
'''
if type(auth) == str:
opts['id'] = self.id
if auth == 'basic':
opts['secret'] = self.secret
else:
opts['jwt'] = auth
return opts
# id is basically always required by the api so we mindlessly add it here
opts['id'] = self.id
if auth == 'basic':
opts['secret'] = self.secret
else:
# if its not a string we don't add anything in
return opts
opts['jwt'] = auth
return opts
def logs(self):
ids = sorted(self.requests.keys()) # shared keys in requests/responses
@ -71,9 +69,9 @@ class Worker:
# Logg the provided data to ensure that _it_ wasn't the cause for error
resp = self.responses[key]
if resp.code != resp.expected:
opts = self.requests[key].params
print(f'\tParams: {opts}')
if self.body_logs[key] is True:
self.responses[key].log()
# if body is request to be shown then dump it tabbed out by 1 tab
if self.body_logs[key] is True:
print(f'\tBody: {self.responses[key].body}')
@ -111,7 +109,6 @@ def run(worker: Worker):
channel_tests = [
# sanity check
{'init': ['get', '/channels/list', {}], 'auth': None, 'hope': 401},
{'init': ['post', '/channels/list', {}], 'auth': jwt, 'hope': 404},
{'init': ['post', '/channels/create', {'name': str(new_channel_name), 'kind': TEXT_CHAN, 'description': 'asdf'}], 'auth': jwt, 'hope': 200},
@ -142,46 +139,46 @@ def run(worker: Worker):
message_tests = [
# bs message spam
{'init': ['post', '/message/send', {'channel': chan_d['id'], 'content': 'bs content'}], 'auth': jwt, 'hope': 200},
{'init': ['post', '/message/send', {'channel': chan_d['id'], 'content': 'bs content'}], 'auth': jwt, 'hope': 200},
{'init': ['post', '/message/send', {'channel': chan_d['id'], 'content': 'bs content'}], 'auth': jwt, 'hope': 200},
{'init': ['post', '/message/send', {'channel': chan_d['id'], 'content': 'bs content'}], 'auth': jwt, 'hope': 200},
{'init': ['post', '/message/send', {'channel_id': chan_d['id'], 'content': 'bs content'}], 'auth': jwt, 'hope': 200},
{'init': ['post', '/message/send', {'channel_id': chan_d['id'], 'content': 'bs content'}], 'auth': jwt, 'hope': 200},
{'init': ['post', '/message/send', {'channel_id': chan_d['id'], 'content': 'bs content'}], 'auth': jwt, 'hope': 200},
{'init': ['post', '/message/send', {'channel_id': chan_d['id'], 'content': 'bs content'}], 'auth': jwt, 'hope': 200},
# can we get them back tho?
{
'init': [
'get', '/message/get_range', {'channel': chan_d['id'], 'start-time': int(msg_chan_name-10), 'end-time': int(msg_chan_name + 10)}
'get', '/message/get_range', {'channel_id': chan_d['id'], 'start-time': int(msg_chan_name-10), 'end-time': int(msg_chan_name + 10)}
],
'auth': jwt, 'hope': 200
},
{
'init': [
'get', '/message/get_range', {'channel': chan_d['id'], 'end-time': int(msg_chan_name)}
'get', '/message/get_range', {'channel_id': chan_d['id'], 'end-time': int(msg_chan_name)}
],
'auth': jwt, 'hope': 400
},
{
'init': [
'get', '/message/get_range', {'channel': chan_d['id'], 'start-time': int(msg_chan_name), 'end-time': int(msg_chan_name)}
'get', '/message/get_range', {'channel_id': chan_d['id'], 'start-time': int(msg_chan_name), 'end-time': int(msg_chan_name)}
],
'auth': jwt, 'hope': 400
},
{
'init': [
'get', '/message/get_range', {'channel': chan_d['id'], 'end-time': int(msg_chan_name), 'start-time': int(msg_chan_name)}
'get', '/message/get_range', {'channel_id': chan_d['id'], 'end-time': int(msg_chan_name), 'start-time': int(msg_chan_name)}
],
'auth': jwt, 'hope': 400
},
# two tests that follow the rules
{
'init': [
'get', '/message/from_id', {'start': 1, 'channel': 3}
'get', '/message/from_id', {'start': 1, 'channel_id': 3}
],
'auth': jwt, 'hope': 200, 'body': True
},
{
'init': [
'get', '/message/from_id', {'start':1, 'channel':3, 'limit':2}
'get', '/message/from_id', {'start':1, 'channel_id':3, 'limit':2}
],
'auth': jwt, 'hope': 200, 'body': True
},
@ -189,14 +186,14 @@ def run(worker: Worker):
{
# channel doesn't exist so a 404 seems to be inorder
'init': [
'get', '/message/from_id', {'start': 1, 'channel':9}
'get', '/message/from_id', {'start': 1, 'channel_id':9}
],
'auth': jwt, 'hope': 404
},
{
'init': [
# good channel but id is tooo high
'get', '/message/from_id', {'start': 5, 'channel':3}
'get', '/message/from_id', {'start': 5, 'channel_id':3}
],
'auth': jwt, 'hope': 404
},
@ -216,5 +213,5 @@ def run(worker: Worker):
worker.logs()
if __name__ == '__main__':
worker = Worker('http://localhost:8888', create_admin=True)
worker = Worker('http://localhost:4536', create_admin=True)
run(worker)