2021-05-11 21:06:38 +00:00
|
|
|
from flask.testing import Client
|
|
|
|
|
|
|
|
'''A file that contains tests of classes and methods for all the requests concerning an user.'''
|
|
|
|
|
|
|
|
|
2021-05-12 18:20:51 +00:00
|
|
|
class TestRepositoryAdd:
|
|
|
|
def test_for_success(self, flask_client: Client, user_headers):
|
|
|
|
r = flask_client.post(f'/api/v1/repositories/', headers=user_headers, json={
|
|
|
|
'conditions': [
|
|
|
|
{
|
2021-05-12 21:39:29 +00:00
|
|
|
'content': 'PdS2021',
|
|
|
|
'id': 0,
|
|
|
|
'type': 0
|
2021-05-12 18:20:51 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
'evaluation_mode': 0,
|
|
|
|
'name': 'repo_test',
|
|
|
|
'is_active': True
|
2021-05-11 21:55:35 +00:00
|
|
|
})
|
2021-05-12 22:05:00 +00:00
|
|
|
assert r.status_code == 200
|
2021-05-12 18:20:51 +00:00
|
|
|
assert r.json["result"] == "success"
|
|
|
|
assert r.json["data"]["is_active"] is True
|
2021-05-11 21:55:35 +00:00
|
|
|
|
2021-05-12 18:20:51 +00:00
|
|
|
# non vengono passate le condizioni necessarie, in questo caso il nome della repository
|
2021-05-12 22:05:00 +00:00
|
|
|
def test_no_name(self, flask_client: Client, user_headers):
|
2021-05-12 18:20:51 +00:00
|
|
|
r = flask_client.post(f'/api/v1/repositories/', headers=user_headers, json={
|
|
|
|
'conditions': [
|
|
|
|
{
|
2021-05-12 21:39:29 +00:00
|
|
|
'content': 'PdS2021',
|
|
|
|
'id': 0,
|
|
|
|
'type': 0
|
2021-05-12 18:20:51 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
'evaluation_mode': 0,
|
|
|
|
'is_active': True
|
2021-05-11 21:55:35 +00:00
|
|
|
})
|
2021-05-12 22:05:00 +00:00
|
|
|
assert r.status_code == 400
|
2021-05-12 18:20:51 +00:00
|
|
|
assert r.json["msg"] == "Missing arguments."
|
|
|
|
assert r.json["result"] == "failure"
|
2021-05-12 21:39:29 +00:00
|
|
|
|
|
|
|
# viene passato un campo evaluation_mode con valore non previsto dall'enum
|
|
|
|
def test_wrong_evaluation_mode(self, flask_client: Client, user_headers):
|
|
|
|
r = flask_client.post(f'/api/v1/repositories/', headers=user_headers, json={
|
|
|
|
'conditions': [
|
|
|
|
{
|
|
|
|
'content': 'PdS2021',
|
|
|
|
'id': 0,
|
|
|
|
'type': 0
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'evaluation_mode': 99,
|
|
|
|
'name': 'repo_test',
|
|
|
|
'is_active': True
|
|
|
|
})
|
2021-05-12 22:05:00 +00:00
|
|
|
assert r.status_code == 400
|
2021-05-12 21:39:29 +00:00
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
|
|
|
# viene passato un campo type con valore non previsto dall'enum
|
|
|
|
def test_wrong_condition(self, flask_client: Client, user_headers):
|
|
|
|
r = flask_client.post(f'/api/v1/repositories/', headers=user_headers, json={
|
|
|
|
'conditions': [
|
|
|
|
{
|
|
|
|
'content': 'PdS2021',
|
|
|
|
'id': 0,
|
|
|
|
'type': 99
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'evaluation_mode': 2,
|
|
|
|
'name': 'repo_test',
|
|
|
|
'is_active': True
|
|
|
|
})
|
2021-05-12 22:05:00 +00:00
|
|
|
assert r.status_code == 400
|
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
|
|
|
|
|
|
|
class TestRepositoryGetAll:
|
|
|
|
def test_get_all_user_repositories(self, flask_client: Client, user_headers):
|
|
|
|
r = flask_client.get(f'/api/v1/repositories/', headers=user_headers,
|
|
|
|
json={'owner_id': 'utente_test@nest.com', 'isActive': False})
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert r.json["result"] == "success"
|
|
|
|
|
|
|
|
def test_get_all_admin_repositories(self, flask_client: Client, admin_headers):
|
|
|
|
r = flask_client.get(f'/api/v1/repositories/', headers=admin_headers,
|
|
|
|
json={'owner_id': 'admin@admin.com', 'isActive': False})
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert r.json["result"] == "success"
|
|
|
|
|
|
|
|
|
|
|
|
class TestRepositoryGet:
|
|
|
|
def test_get_existing_repository(self, flask_client: Client, user_headers):
|
|
|
|
r = flask_client.get(f'/api/v1/repositories/1', headers=user_headers)
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert r.json["result"] == "success"
|
|
|
|
|
|
|
|
def test_get_non_existing_repository(self, flask_client: Client, admin_headers):
|
|
|
|
r = flask_client.get(f'/api/v1/repositories/99', headers=admin_headers)
|
|
|
|
assert r.status_code == 404
|
2021-05-12 21:39:29 +00:00
|
|
|
assert r.json["result"] == "failure"
|
2021-05-11 21:55:35 +00:00
|
|
|
|
2021-05-12 22:05:00 +00:00
|
|
|
|
2021-05-13 20:52:18 +00:00
|
|
|
class TestRepositoryPatch:
|
|
|
|
def test_wrong_owner(self, flask_client: Client, admin_headers):
|
2021-05-13 20:57:40 +00:00
|
|
|
r = flask_client.patch(f'/api/v1/repositories/1', headers=admin_headers)
|
2021-05-13 20:52:18 +00:00
|
|
|
assert r.status_code == 403
|
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
|
|
|
def test_unknown_type(self, flask_client: Client, admin_headers):
|
2021-05-13 20:57:40 +00:00
|
|
|
r = flask_client.patch(f'/api/v1/repositories/1', headers=admin_headers,
|
2021-05-13 20:52:18 +00:00
|
|
|
json={
|
|
|
|
"name": "string",
|
|
|
|
"close": "string",
|
|
|
|
"open": "string",
|
|
|
|
"evaluation_mode": 99
|
|
|
|
})
|
|
|
|
assert r.status_code == 400
|
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
|
|
|
def test_for_success(self, flask_client: Client, user_headers):
|
2021-05-13 20:57:40 +00:00
|
|
|
r = flask_client.patch(f'/api/v1/repositories/1', headers=user_headers,
|
2021-05-13 20:52:18 +00:00
|
|
|
json={
|
|
|
|
"name": "nuovo_nome",
|
|
|
|
"close": "false",
|
|
|
|
"open": "false",
|
|
|
|
"evaluation_mode": 1
|
|
|
|
})
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert r.json["result"] == "success"
|
|
|
|
|
|
|
|
class TestRepositoryDelete:
|
2021-05-13 20:57:40 +00:00
|
|
|
def test_wrong_owner(self, flask_client: Client, user_headers):
|
|
|
|
r = flask_client.delete(f'/api/v1/repositories/2', headers=user_headers)
|
|
|
|
assert r.status_code == 403
|
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
2021-05-13 20:52:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestRepositoryPut:
|
2021-05-13 20:57:40 +00:00
|
|
|
def test_unknown_type(self, flask_client: Client, admin_headers):
|
|
|
|
r = flask_client.put(f'/api/v1/repositories/1', headers=admin_headers,
|
|
|
|
json={
|
|
|
|
"name": "string",
|
|
|
|
"close": "string",
|
|
|
|
"open": "string",
|
|
|
|
"evaluation_mode": 99
|
|
|
|
})
|
|
|
|
assert r.status_code == 400
|
|
|
|
assert r.json["result"] == "failure"
|
2021-05-13 20:52:18 +00:00
|
|
|
|
2021-05-12 18:20:51 +00:00
|
|
|
'''
|
2021-05-11 21:55:35 +00:00
|
|
|
class TestUserDelete:
|
|
|
|
def test_for_success(self, flask_client: Client, admin_headers):
|
|
|
|
r = flask_client.delete(f'/api/v1/users/utente_test@nest.com', headers=admin_headers)
|
|
|
|
assert b'success' in r.data
|
|
|
|
|
|
|
|
# the admin tries to commit suicide
|
|
|
|
def test_for_failure(self, flask_client: Client, admin_headers):
|
|
|
|
r = flask_client.delete(f'/api/v1/users/admin@admin.com', headers=admin_headers)
|
|
|
|
assert b'failure' in r.data
|
|
|
|
|
|
|
|
|
|
|
|
class TestUserPatch:
|
|
|
|
def test_for_success(self, flask_client: Client, admin_headers):
|
|
|
|
r = flask_client.patch(f'/api/v1/users/admin@admin.com', headers=admin_headers, json={
|
|
|
|
'username': 'admin_patched'
|
|
|
|
})
|
|
|
|
assert b'success' in r.data
|
|
|
|
|
|
|
|
# FIXME AssertionError in flask_client at line 63. Il test non riesce ad andare a buon fine
|
|
|
|
def test_for_failure(self, flask_client: Client, user_headers):
|
|
|
|
r = flask_client.patch(f'/api/v1/users/admin@admin.com', headers=user_headers, json={
|
|
|
|
'username': 'admin_patched'
|
|
|
|
})
|
|
|
|
assert b'failure' in r.data
|
|
|
|
|
|
|
|
'''
|