1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 06:24:19 +00:00
This commit is contained in:
Annielated 2021-04-30 00:29:32 +02:00
parent 077524ff23
commit b8ad2020f8
6 changed files with 119 additions and 73 deletions

6
.idea/misc.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View file

@ -6,7 +6,7 @@
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="SDK_HOME" value="C:\Users\giova\AppData\Local\pypoetry\Cache\virtualenvs\nest-backend-gZK59SuL-py3.9\Scripts\python.exe" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />

View file

@ -0,0 +1,41 @@
import requests
import json
import unittest
auth_code = ""
class MyTestCase(unittest.TestCase):
def test_repository_create(self):
global auth_code
# TEST IN POST
r = requests.post('http://localhost:5000/api/v1/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/v1/repositories/', headers={'authorization': "Bearer " + auth_code},
json={})
j = json.loads(r.text)
assert j['result'] == "success"
print("Repository creata correttamente!")
# TEST IN GET
r = requests.post('http://localhost:5000/api/v1/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.get(f'http://localhost:5000/api/v1/repositories/', headers={'authorization': "Bearer " + auth_code},
json={'owner_id': 'utente_test@nest.com', 'isActive': False})
j = json.loads(r.text)
assert j['result'] == "success"
for i in j:
print(j[i])
print("Testing del metodo repository_create")

View file

@ -1,27 +0,0 @@
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")

View file

@ -1,45 +0,0 @@
import unittest
import requests
import json
auth_code = ""
class MyTestCase(unittest.TestCase):
def test_user_create(self):
global auth_code
# testo come admin: successo
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'})
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"
print("User_create eseguito correttamente!")
print("Testing del metodo user_create")
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,71 @@
import unittest
import requests
import json
auth_code = ""
class MyTestCase(unittest.TestCase):
def test_user_create(self):
global auth_code
# TEST IN POST
# User autenticato come Admin: successo
r = requests.post('http://localhost:5000/api/v1/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/v1/users', headers={'authorization': "Bearer " + auth_code},
json={'email': 'utente_test@nest.com', 'password': 'password', 'username': 'utente_test'})
j = json.loads(r.text)
assert j['result'] == "success"
print("User creato correttamente!")
# User autenticato come non-Admin: fallisce
auth_code = ""
r = requests.post('http://localhost:5000/api/v1/login', json={'email': 'utente20@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/v1/users', 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"
print("User non creato correttamente!")
# TEST IN GET
# User autenticato come Admin
r = requests.post('http://localhost:5000/api/v1/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.get(f'http://localhost:5000/api/v1/users', headers={'authorization': "Bearer " + auth_code})
j = json.loads(r.text)
assert j['result'] == "success"
for i in j:
print(j[i])
# User autenticato come non-Admin
r = requests.post('http://localhost:5000/api/v1/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.get(f'http://localhost:5000/api/v1/users', headers={'authorization': "Bearer " + auth_code})
j = json.loads(r.text)
assert j['result'] == "failure"
print("Testing del metodo user_create")
if __name__ == '__main__':
unittest.main()