1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-23 05:24:18 +00:00
pds-2021-g2-nest/code/backend/nest_backend/test/user_delete_test.py

58 lines
2.2 KiB
Python
Raw Normal View History

2021-04-27 22:44:21 +00:00
import requests
import json
import unittest
2021-04-27 22:44:21 +00:00
auth_code = ""
class MyTestCase(unittest.TestCase):
def test_user_delete(self):
global auth_code
2021-04-27 22:44:21 +00:00
#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']
2021-04-27 22:44:21 +00:00
#test cancellazione senza specificare user, fallisce
r = requests.post(f'http://localhost:5000/api/user/remove', headers={'authorization': "Bearer " + auth_code},
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"
2021-04-27 22:44:21 +00:00
print("User_delete eseguito correttamente!")
print("Testing del metodo user_delete")
2021-04-27 22:44:21 +00:00