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

46 lines
1.4 KiB
Python
Raw Normal View History

import unittest
2021-04-26 21:19:17 +00:00
import requests
import json
2021-04-26 21:19:17 +00:00
auth_code = ""
class MyTestCase(unittest.TestCase):
def test_user_create(self):
global auth_code
2021-04-26 21:19:17 +00:00
# testo come admin: successo
2021-04-26 21:19:17 +00:00
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']
r = requests.post(f'http://localhost:5000/api/user/create', headers={'authorization': "Bearer " + auth_code},
json={'email': 'utente_test@nest.com', 'password': 'password', 'username': 'utente_test'})
2021-04-26 21:19:17 +00:00
j = json.loads(r.text)
assert j['result'] == "success"
# testo come utente normale: fallisce
auth_code = ""
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']
r = requests.post(f'http://localhost:5000/api/user/create', headers={'authorization': "Bearer " + auth_code},
json={'email': 'utente_test_2@nest.com', 'password': 'password', 'username': 'utente_test_2'})
j = json.loads(r.text)
assert j['result'] == "failure"
2021-04-26 21:19:17 +00:00
print("User_create eseguito correttamente!")
print("Testing del metodo user_create")
if __name__ == '__main__':
unittest.main()