diff --git a/server-api/client-tests/client.py b/server-api/client-tests/client.py index f4ab45f..604e2f1 100644 --- a/server-api/client-tests/client.py +++ b/server-api/client-tests/client.py @@ -16,6 +16,7 @@ class Worker: self.domain = domain self.requests = {} self.responses = {} + self.body_logs = {} self.jwt = None # never gets assigned until /login is hit self.basic_creds = self.__create_admin() @@ -72,9 +73,11 @@ class Worker: if resp.code != resp.expected: opts = self.requests[key].params print(f'\tParams: {opts}') + if self.body_logs[key] is True: + print(f'\tBody: {self.responses[key].body}') - def request(self, method: str, path: str, auth: str, opts: dict, expectation: int): + def request(self, method: str, path: str, auth: str, opts: dict, expectation: int, show_body=False): assert(path[0] == '/') # First make sure we add in the correct auth params that are requested @@ -84,10 +87,13 @@ class Worker: url = self.domain + path req = http.Request(method, url, opts) r_id = time.time() - self.requests[r_id] = req resp = req.make(expectation) + + # update log trackers + self.requests[r_id] = req self.responses[r_id] = resp + self.body_logs[r_id] = show_body return r_id @@ -138,13 +144,30 @@ def run(worker: Worker): }, 200) chan_d = worker.responses[_id].json() - # spam some messages - for i in range(5): - msg = f'Message id: {i}' - worker.request('post', '/message/send', jwt, { - 'channel': chan_d['id'], - 'content': msg - }, 200) + 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}, + + # 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)}], 'auth': jwt, 'hope': 200, 'body': True}, + {'init': ['get', '/message/get_range', {'channel': 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)}], '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)}], 'auth': jwt, 'hope': 400}, + ] + + for test in message_tests: + method, path, opts = test['init'] + auth = test['auth'] + hope = test['hope'] + if 'body' in test: + worker.request(method, path, auth, opts, hope, show_body=test['body']) + else: + worker.request(method, path, auth, opts, hope) + + worker.logs()