From 4f3c4936b0817cf46da1bb50a765aa19fb99bc69 Mon Sep 17 00:00:00 2001 From: stefanogoldoni Date: Wed, 28 Apr 2021 23:23:46 +0200 Subject: [PATCH] testati tutti i casi del metodo user_delete --- .../nest_backend/test/user_delete_test.py | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/code/backend/nest_backend/test/user_delete_test.py b/code/backend/nest_backend/test/user_delete_test.py index 5faa754..9b8f9ba 100644 --- a/code/backend/nest_backend/test/user_delete_test.py +++ b/code/backend/nest_backend/test/user_delete_test.py @@ -9,13 +9,44 @@ class MyTestCase(unittest.TestCase): def test_user_delete(self): global auth_code + #testo come utente normale + r = requests.post('http://localhost:5000/api/login', json={'email': 'utente_test@nest.com', 'password': 'password'}) + j = json.loads(r.text) + assert j['result'] == "success" + auth_code = j['data']['access_token'] + + #cancellazione utente qualunque: fallisce, non sono admin + r = requests.post(f'http://localhost:5000/api/user/remove', headers={'authorization': "Bearer " + auth_code}, + json={'email': 'utente_qualunque@nest.com'}) + j = json.loads(r.text) + assert j['result'] == "failure" + + #testo come utente admin r = requests.post('http://localhost:5000/api/login', json={'email': 'admin@admin.com', 'password': 'password'}) j = json.loads(r.text) assert j['result'] == "success" auth_code = j['data']['access_token'] + #test cancellazione senza specificare user, fallisce r = requests.post(f'http://localhost:5000/api/user/remove', headers={'authorization': "Bearer " + auth_code}, - json={'email': 'utente15@nest.com'}) + json={'email': ''}) + j = json.loads(r.text) + assert j['result'] == "failure" + + #test cancellazione user non esistente, fallisce + r = requests.post(f'http://localhost:5000/api/user/remove', headers={'authorization': "Bearer " + auth_code}, + json={'email': 'none@nest.com'}) + j = json.loads(r.text) + assert j['result'] == "failure" + + #test cancellazione user corrente, fallisce + r = requests.post(f'http://localhost:5000/api/user/remove', headers={'authorization': "Bearer " + auth_code}, + json={'email': 'admin@nest.com'}) + j = json.loads(r.text) + assert j['result'] == "failure" + + r = requests.post(f'http://localhost:5000/api/user/remove', headers={'authorization': "Bearer " + auth_code}, + json={'email': 'utente_test@nest.com'}) j = json.loads(r.text) assert j['result'] == "success"