1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-28 23:44:19 +00:00

lettura e creazione repository testata in tutti i metodi

This commit is contained in:
stefanogoldoni 2021-04-30 22:21:12 +02:00
parent e0f54e53d9
commit 11ab4143bb

View file

@ -9,19 +9,12 @@ auth_code = ""
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def test_repository_create(self): def test_repository_create(self):
global auth_code global auth_code
# TEST IN POST # entro come utente_Test
r = requests.post('http://localhost:5000/api/v1/login', json={'email': 'utente_test@nest.com', 'password': 'password'}) r = requests.post('http://localhost:5000/api/v1/login', json={'email': 'utente_test@nest.com', 'password': 'password'})
j = json.loads(r.text) j = json.loads(r.text)
assert j['result'] == "success" assert j['result'] == "success"
auth_code = j['data']['access_token'] 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 # TEST IN GET
r = requests.post('http://localhost:5000/api/v1/login', json={'email': 'utente_test@nest.com', 'password': 'password'}) r = requests.post('http://localhost:5000/api/v1/login', json={'email': 'utente_test@nest.com', 'password': 'password'})
j = json.loads(r.text) j = json.loads(r.text)
@ -35,7 +28,31 @@ class MyTestCase(unittest.TestCase):
for i in j: for i in j:
print(j[i]) print(j[i])
print("Repositories letti correttamente!")
# TODO: testare anche i parametri onlyDead e onlyActive
# creo un repo senza nome: fallisce
r = requests.post(f'http://localhost:5000/api/v1/repositories/', headers={'authorization': "Bearer " + auth_code},
json={})
j = json.loads(r.text)
assert j['result'] == "failure"
# creo un repo con nome vuoto: fallisce
r = requests.post(f'http://localhost:5000/api/v1/repositories/', headers={'authorization': "Bearer " + auth_code},
json={'nome': ''})
j = json.loads(r.text)
assert j['result'] == "failure"
# creo un repo: successo
r = requests.post(f'http://localhost:5000/api/v1/repositories/', headers={'authorization': "Bearer " + auth_code},
json={'name': 'repo_test_2'})
j = json.loads(r.text)
assert j['result'] == "success"
print("Repository creata correttamente!")
print("Testing del metodo repository_create")
print("Testing dei metodi di lettura e creazione repository")