1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 04:54:18 +00:00

importato unittest, rimossa chiamata della funzione che ora avviene grazie al parametro self

This commit is contained in:
Annielated 2021-04-28 19:55:59 +02:00
parent 9ea852b50b
commit aaab6094a9
3 changed files with 27 additions and 18 deletions

View file

@ -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())

View file

@ -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()

View file

@ -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()