From 34736bef3fe76692b651e85ddddbdc45ca3fd460 Mon Sep 17 00:00:00 2001 From: shockrah Date: Sat, 20 Feb 2021 20:14:10 -0800 Subject: [PATCH] updating tests for members routes --- json-api/build.sh | 17 ++++++++++++++--- json-api/client-tests/client.py | 26 +++++++++++++++++++++----- json-api/client-tests/web/http.py | 2 +- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/json-api/build.sh b/json-api/build.sh index 6e00d2e..e98630d 100755 --- a/json-api/build.sh +++ b/json-api/build.sh @@ -21,11 +21,22 @@ full= testing() { release_opt=$1 cargo build $release_opt + # next we run the server in the background + + cargo run $release_opt -- -s& + sid=$! + + # wait a sec + echo Waiting on server to start + sleep 3 + # now fire off client tests source ./client-tests/bin/activate python3 client-tests/client.py -# if [ ! -z $full ];then -# cargo test $release_opt -# fi + # clean up the server now + kill -9 $sid + if [ ! -z $full ];then + cargo test $release_opt + fi } while getopts ":fhtTbr" arg; do diff --git a/json-api/client-tests/client.py b/json-api/client-tests/client.py index e526ede..f57f08e 100644 --- a/json-api/client-tests/client.py +++ b/json-api/client-tests/client.py @@ -102,6 +102,7 @@ def run(worker: Worker): # Basically every test requires a jwt to be passed in so we grab that here # Should this fail so should nearly every other test from this point req_login = worker.request('post', '/login', 'basic',{}, 200) + print(worker.responses[req_login].json()) jwt = worker.responses[req_login].json()['jwt'] new_channel_name = time.time() @@ -147,25 +148,25 @@ def run(worker: Worker): # can we get them back tho? { 'init': [ - 'get', '/message/get_range', {'channel_id': 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_id': 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_id': 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_id': 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 }, @@ -210,8 +211,23 @@ def run(worker: Worker): + member_tests = [ + { 'init': ['get', '/members/me', {}], 'auth': jwt, 'hope': 200 }, + { 'init': ['get', '/members/me', {'asdf': 123}], 'auth': jwt, 'hope': 200 }, + { 'init': ['get', '/members/get_online', {}], 'auth': jwt, 'hope': 200, 'body': True}, + ] + + for test in member_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() if __name__ == '__main__': - worker = Worker('https://localhost', create_admin=True) + worker = Worker('http://localhost:4536', create_admin=True) run(worker) diff --git a/json-api/client-tests/web/http.py b/json-api/client-tests/web/http.py index 0018826..097445e 100644 --- a/json-api/client-tests/web/http.py +++ b/json-api/client-tests/web/http.py @@ -90,7 +90,7 @@ class Response: # no color on the query like ever(because its typically massive if show_query: - msg += f'\n\t{self.query_string[:80]}' + msg += f'\n\t{self.query_string[:77]}...' self.__write_msg(msg)