From 8128b4622e1572de878021d32ba7ca47f8096113 Mon Sep 17 00:00:00 2001 From: Giovanni Anniballi <253150@studenti.unimore.it> Date: Wed, 28 Apr 2021 21:17:05 +0000 Subject: [PATCH 1/5] importato unittest --- code/backend/nest_backend/test/login_test.py | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/code/backend/nest_backend/test/login_test.py b/code/backend/nest_backend/test/login_test.py index 998d91b..27a8758 100644 --- a/code/backend/nest_backend/test/login_test.py +++ b/code/backend/nest_backend/test/login_test.py @@ -1,23 +1,25 @@ +import unittest import requests import json auth_code = "" -def test_login(): - global auth_code - r = requests.post('http://localhost:5000/api/login', json={'email': 'admin@admin.com', 'password': 'amogus'}) - j = json.loads(r.text) - assert j['result'] == "failure" - r = requests.post('http://localhost:5000/api/login', json={'email': '', 'password': ''}) - j = json.loads(r.text) - assert j['result'] == "failure" - 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'] - print("Login eseguito correttamente!") +class MyTestCase(unittest.TestCase): + def test_login(self): + global auth_code + r = requests.post('http://localhost:5000/api/login', json={'email': 'admin@admin.com', 'password': 'amogus'}) + j = json.loads(r.text) + assert j['result'] == "failure" + r = requests.post('http://localhost:5000/api/login', json={'email': '', 'password': ''}) + j = json.loads(r.text) + assert j['result'] == "failure" + 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'] + print("Login eseguito correttamente!") print("Testing del login") -test_login() + From 5b71de4a515e70a4381dee2d644fbf7fccb99f35 Mon Sep 17 00:00:00 2001 From: stefanogoldoni Date: Wed, 28 Apr 2021 23:22:18 +0200 Subject: [PATCH 2/5] creazione utente_test --- code/backend/nest_backend/test/user_create_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/backend/nest_backend/test/user_create_test.py b/code/backend/nest_backend/test/user_create_test.py index baca138..3d33b6b 100644 --- a/code/backend/nest_backend/test/user_create_test.py +++ b/code/backend/nest_backend/test/user_create_test.py @@ -16,7 +16,7 @@ class MyTestCase(unittest.TestCase): auth_code = j['data']['access_token'] r = requests.post(f'http://localhost:5000/api/user/create', headers={'authorization': "Bearer " + auth_code}, - json={'email': 'utente16@nest.com', 'password': '', 'username': 'utente16'}) + json={'email': 'utente_test@nest.com', 'password': 'password', 'username': 'utente'}) j = json.loads(r.text) assert j['result'] == "success" From 4f3c4936b0817cf46da1bb50a765aa19fb99bc69 Mon Sep 17 00:00:00 2001 From: stefanogoldoni Date: Wed, 28 Apr 2021 23:23:46 +0200 Subject: [PATCH 3/5] testati tutti i casi del metodo user_delete --- .../nest_backend/test/user_delete_test.py | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/code/backend/nest_backend/test/user_delete_test.py b/code/backend/nest_backend/test/user_delete_test.py index 5faa754..9b8f9ba 100644 --- a/code/backend/nest_backend/test/user_delete_test.py +++ b/code/backend/nest_backend/test/user_delete_test.py @@ -9,13 +9,44 @@ class MyTestCase(unittest.TestCase): def test_user_delete(self): global auth_code + #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'] + #test cancellazione senza specificare user, fallisce r = requests.post(f'http://localhost:5000/api/user/remove', headers={'authorization': "Bearer " + auth_code}, - json={'email': 'utente15@nest.com'}) + 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" From ff64b2edacc85f4ed1c10cb1bf1d239483643cac Mon Sep 17 00:00:00 2001 From: Giovanni Anniballi <253150@studenti.unimore.it> Date: Wed, 28 Apr 2021 21:32:45 +0000 Subject: [PATCH 4/5] =?UTF-8?q?le=20repositori=20vengono=20create,=20si=20?= =?UTF-8?q?necessitano=20per=C3=B2=20altri=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/repository_create_test.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 code/backend/nest_backend/test/repository_create_test.py diff --git a/code/backend/nest_backend/test/repository_create_test.py b/code/backend/nest_backend/test/repository_create_test.py new file mode 100644 index 0000000..fa69d2c --- /dev/null +++ b/code/backend/nest_backend/test/repository_create_test.py @@ -0,0 +1,27 @@ +import requests +import json +import unittest + + +auth_code = "" + + +class MyTestCase(unittest.TestCase): + def test_repository_create(self): + global auth_code + + r = requests.post('http://localhost:5000/api/login', json={'email': 'utente13@nest.com', 'password': ''}) + j = json.loads(r.text) + assert j['result'] == "success" + auth_code = j['data']['access_token'] + + r = requests.post(f'http://localhost:5000/api/repository/create', headers={'authorization': "Bearer " + auth_code}, + json={'name': 'prova3', 'owner_id': 'email'}) + j = json.loads(r.text) + assert j['result'] == "success" + + print("Repository_create eseguito correttamente!") + + +print("Testing del metodo repository_create") + From 78fd6952109e41b4534451b58355c22db6d02459 Mon Sep 17 00:00:00 2001 From: Giovanni Anniballi <253150@studenti.unimore.it> Date: Wed, 28 Apr 2021 21:35:32 +0000 Subject: [PATCH 5/5] incompleto --- .../nest_backend/test/repository_edit_test.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 code/backend/nest_backend/test/repository_edit_test.py diff --git a/code/backend/nest_backend/test/repository_edit_test.py b/code/backend/nest_backend/test/repository_edit_test.py new file mode 100644 index 0000000..cd7c24b --- /dev/null +++ b/code/backend/nest_backend/test/repository_edit_test.py @@ -0,0 +1,27 @@ +import json +import unittest +import requests + + +class MyTestCase(unittest.TestCase): + def test_repository_edit(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.put(f'http://localhost:5000/api/repository/edit', headers={'authorization': "Bearer " + auth_code}, + json={'id': '1', 'name': 'newname'}) + j = json.loads(r.text) + assert j['result'] == "success" + + print('Repository_edit eseguito correttamente!') + + +print('Testing del metodo repository_edit') + + + +