1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-26 23:14:19 +00:00
pds-2021-g2-nest/code/backend/nest_backend/test/user_test.py

65 lines
2.3 KiB
Python
Raw Normal View History

import requests
import json
import unittest
auth_code = ""
class MyTestCase(unittest.TestCase):
def test_user_delete(self):
global auth_code
# sono un utente normale
r = requests.post('http://localhost:5000/api/v1/login', json={'email': 'utente_test@nest.com', 'password': 'password'})
j = json.loads(r.text)
assert j['result'] == "success"
auth_code = j['data']['access_token']
# elimino ma non sono admin
r = requests.delete(f'http://localhost:5000/api/v1/users/admin@admin.com',
2021-05-01 10:28:26 +00:00
headers={'authorization': "Bearer " + auth_code})
j = json.loads(r.text)
assert j['result'] == "failure"
print("delete User NON eseguito correttamente!")
# adesso divento admin
r = requests.post('http://localhost:5000/api/v1/login', json={'email': 'admin@admin.com', 'password': 'password'})
j = json.loads(r.text)
assert j['result'] == "success"
auth_code = j['data']['access_token']
# elimino un utente che non c'è
r = requests.delete(f'http://localhost:5000/api/v1/users/none@nest.com',
2021-05-01 10:28:26 +00:00
headers={'authorization': "Bearer " + auth_code})
j = json.loads(r.text)
assert j['result'] == "failure"
print("delete User NON eseguito correttamente!")
r = requests.delete(f'http://localhost:5000/api/v1/users/admin@admin.com',
2021-05-01 10:28:26 +00:00
headers={'authorization': "Bearer " + auth_code})
j = json.loads(r.text)
assert j['result'] == "failure"
print("delete User NON eseguito correttamente!")
2021-04-29 22:12:25 +00:00
r = requests.delete(f'http://localhost:5000/api/v1/users/utente3@nest.com',
2021-05-01 10:28:26 +00:00
headers={'authorization': "Bearer " + auth_code})
j = json.loads(r.text)
assert j['result'] == "success"
# TODO AGGIUNGERE TESTING DI GET E PATCH
2021-05-01 10:28:26 +00:00
# chiedo le info di un utente che esiste
r = requests.get(f'http://localhost:5000/api/v1/users/utente_test@nest.com',
headers={'authorization': "Bearer " + auth_code})
j = json.loads(r.text)
assert j['result'] == "success"
print("User_delete eseguito correttamente!")
2021-04-29 22:12:25 +00:00
print("Testing del metodo user delete")