From e8348918c4c0df51c324ae898dcf4080ba53a77f Mon Sep 17 00:00:00 2001 From: shockrah Date: Sat, 8 May 2021 02:07:32 -0700 Subject: [PATCH] + More qol like better __str__ methods everywhere + More error handling in case shit goes wrong Basically handling more cases where some initial test could result in the whole script exiting with code(1) Not really that big of a deal since most tests after _that_ point will fail anyway but the fix has revealed issues in the auth code magically so I'm keeping up with the new idea that initial tests should have every resultant case validated to avoid weird behavior > good code results in good results who would have guessed --- json-api/client-tests/config.py | 10 +++++++++- json-api/client-tests/main.py | 7 +++++-- json-api/client-tests/request.py | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/json-api/client-tests/config.py b/json-api/client-tests/config.py index 28cc25f..44c965d 100644 --- a/json-api/client-tests/config.py +++ b/json-api/client-tests/config.py @@ -30,7 +30,15 @@ class Admin: self.server = Server(server) def __str__(self) -> str: - return f'{self.name}#{self.id}' + acc = { + 'id': self.id, + 'name': self.name, + 'permissions': self.permissions, + 'secret': self.secret, + 'jwt': self.jwt, + } + container = {'user': acc, 'server': str(server)} + return str(container) def create_admin() -> Admin : CARGO_BIN = os.getenv('CARGO_BIN') diff --git a/json-api/client-tests/main.py b/json-api/client-tests/main.py index 8b35026..189a58b 100644 --- a/json-api/client-tests/main.py +++ b/json-api/client-tests/main.py @@ -8,7 +8,7 @@ VOICE_CHAN = 1 TEXT_CHAN = 2 def login(admin: Admin) -> (Request, str): - print(f'Provided admin account {admin.server}') + print(f'Provided admin account {admin}') req = Request( admin.server.url + '/login', 'post', @@ -68,9 +68,12 @@ def make_and_receive_invite(admin: Admin) -> (Request, Request): make_inv_req.fire() if make_inv_req.response is None: return (make_inv_req, user_inv_req) + elif make_inv_req.response.status_code >= 400: + print('Params used ', make_inv_req) + return (make_inv_req, None) # Setup to fire the second request, .fire() is safe to blindly use at this point - print('Response text from /join ', make_inv_req.response.text) + print('Response text from /join ', make_inv_req.response.status_code, ' ', make_inv_req.response.text) new_invite_body = make_inv_req.response.json()['invite'] code = new_invite_body['id'] user_inv_req = req(admin , 'get' , '/join', {'code': code}, 200, verbose=True) diff --git a/json-api/client-tests/request.py b/json-api/client-tests/request.py index 529aa0d..89d34a3 100644 --- a/json-api/client-tests/request.py +++ b/json-api/client-tests/request.py @@ -22,6 +22,9 @@ class Request: self.verbose = verbose + def __str__(self): + return str(self.qs) + @property def passing(self): if self.response is None: