2021-04-28 22:14:38 +00:00
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
auth_code = ""
|
|
|
|
|
|
|
|
|
|
|
|
class MyTestCase(unittest.TestCase):
|
|
|
|
def test_user_delete(self):
|
|
|
|
global auth_code
|
|
|
|
|
2021-04-29 22:06:23 +00:00
|
|
|
# sono un utente normale
|
2021-05-01 16:18:13 +00:00
|
|
|
r = requests.post('http://localhost:5000/api/v1/login',
|
|
|
|
json={'email': 'utente_test@nest.com', 'password': 'password'})
|
2021-04-28 22:14:38 +00:00
|
|
|
j = json.loads(r.text)
|
|
|
|
assert j['result'] == "success"
|
|
|
|
auth_code = j['data']['access_token']
|
|
|
|
|
2021-04-29 22:06:23 +00:00
|
|
|
# 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})
|
2021-04-29 22:06:23 +00:00
|
|
|
j = json.loads(r.text)
|
|
|
|
assert j['result'] == "failure"
|
|
|
|
|
|
|
|
print("delete User NON eseguito correttamente!")
|
|
|
|
|
|
|
|
# adesso divento admin
|
2021-05-01 16:18:13 +00:00
|
|
|
r = requests.post('http://localhost:5000/api/v1/login',
|
|
|
|
json={'email': 'admin@admin.com', 'password': 'password'})
|
2021-04-29 22:06:23 +00:00
|
|
|
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})
|
2021-04-29 22:06:23 +00:00
|
|
|
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})
|
2021-04-29 22:06:23 +00:00
|
|
|
j = json.loads(r.text)
|
|
|
|
assert j['result'] == "failure"
|
|
|
|
|
|
|
|
print("delete User NON eseguito correttamente!")
|
|
|
|
|
2021-05-01 16:18:13 +00:00
|
|
|
r = requests.delete(f'http://localhost:5000/api/v1/users/utente13@nest.com',
|
2021-05-01 10:28:26 +00:00
|
|
|
headers={'authorization': "Bearer " + auth_code})
|
2021-04-28 22:14:38 +00:00
|
|
|
j = json.loads(r.text)
|
2021-05-06 12:12:11 +00:00
|
|
|
assert j['result'] == "failure"
|
2021-04-28 22:14:38 +00:00
|
|
|
|
2021-05-01 16:18:13 +00:00
|
|
|
print("delete User eseguito correttamente!")
|
|
|
|
|
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',
|
2021-05-01 16:18:13 +00:00
|
|
|
headers={'authorization': "Bearer " + auth_code})
|
2021-05-01 10:28:26 +00:00
|
|
|
j = json.loads(r.text)
|
|
|
|
assert j['result'] == "success"
|
|
|
|
|
2021-05-01 16:18:13 +00:00
|
|
|
print("get User info eseguito correttamente!")
|
|
|
|
|
|
|
|
# chiedo le info di un utente che NON esiste
|
|
|
|
r = requests.get(f'http://localhost:5000/api/v1/users/utente_chenonesiste@nest.com',
|
|
|
|
headers={'authorization': "Bearer " + auth_code})
|
|
|
|
j = json.loads(r.text)
|
|
|
|
assert j['result'] == "failure"
|
|
|
|
|
|
|
|
print("get User info NON eseguito correttamente!")
|
|
|
|
|
|
|
|
# modifico le info di un utente
|
|
|
|
r = requests.patch(f'http://localhost:5000/api/v1/users/utente1@nest.com',
|
|
|
|
headers={'authorization': "Bearer " + auth_code},
|
|
|
|
json={'username': 'utente1_modificato', 'password': 'password'})
|
|
|
|
j = json.loads(r.text)
|
|
|
|
assert j['result'] == "success"
|
2021-04-28 22:14:38 +00:00
|
|
|
|
2021-05-01 16:18:13 +00:00
|
|
|
print("patch User info eseguito correttamente!")
|
2021-04-28 22:14:38 +00:00
|
|
|
|
2021-05-01 16:18:13 +00:00
|
|
|
print("Tutti i test eseguiti correttamente!")
|
2021-04-28 22:14:38 +00:00
|
|
|
|
2021-05-01 16:18:13 +00:00
|
|
|
print("Testing dei metodo user delete, get e patch")
|