diff --git a/code/backend/nest_backend/routes/users/user_create.py b/code/backend/nest_backend/routes/users/user_create.py index f1ea9c6..43fb5a1 100644 --- a/code/backend/nest_backend/routes/users/user_create.py +++ b/code/backend/nest_backend/routes/users/user_create.py @@ -20,7 +20,7 @@ def page_user_create(): if not user.isAdmin: abort(403) new_user = User(email=request.json.get("email"), password=gen_password(request.json.get("password")), - username=request.json.get("username")) + username=request.json.get("username")) Base.session.add(new_user) Base.session.commit() return json_success(new_user.to_json()) diff --git a/code/backend/nest_backend/test/user_create_test.py b/code/backend/nest_backend/test/user_create_test.py index d98fef0..baca138 100644 --- a/code/backend/nest_backend/test/user_create_test.py +++ b/code/backend/nest_backend/test/user_create_test.py @@ -1,11 +1,14 @@ +import unittest import requests import json + auth_code = "" -def test_user_create(): - global auth_code +class MyTestCase(unittest.TestCase): + def test_user_create(self): + global auth_code r = requests.post('http://localhost:5000/api/login', json={'email': 'admin@admin.com', 'password': 'password'}) j = json.loads(r.text) @@ -13,7 +16,7 @@ def test_user_create(): auth_code = j['data']['access_token'] r = requests.post(f'http://localhost:5000/api/user/create', headers={'authorization': "Bearer " + auth_code}, - json={'email': 'utente12@nest.com', 'password': '1234', 'username': 'utente12'}) + json={'email': 'utente16@nest.com', 'password': '', 'username': 'utente16'}) j = json.loads(r.text) assert j['result'] == "success" @@ -21,4 +24,8 @@ def test_user_create(): print("Testing del metodo user_create") -test_user_create() + + +if __name__ == '__main__': + unittest.main() + diff --git a/code/backend/nest_backend/test/user_delete_test.py b/code/backend/nest_backend/test/user_delete_test.py index 41e984e..5faa754 100644 --- a/code/backend/nest_backend/test/user_delete_test.py +++ b/code/backend/nest_backend/test/user_delete_test.py @@ -1,24 +1,26 @@ import requests import json +import unittest auth_code = "" -def test_user_delete(): - global auth_code +class MyTestCase(unittest.TestCase): + def test_user_delete(self): + global auth_code - 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('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/remove', headers={'authorization': "Bearer " + auth_code}, - json={'email': 'utente10@nest.com'}) - j = json.loads(r.text) - assert j['result'] == "success" + r = requests.post(f'http://localhost:5000/api/user/remove', headers={'authorization': "Bearer " + auth_code}, + json={'email': 'utente15@nest.com'}) + j = json.loads(r.text) + assert j['result'] == "success" - print("User_delete eseguito correttamente!") + print("User_delete eseguito correttamente!") + + print("Testing del metodo user_delete") -print("Testing del metodo user_delete") -test_user_delete()