-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3f4226
commit dd04db0
Showing
1 changed file
with
168 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,14 @@ def delete_user(email): | |
session_commit() | ||
|
||
|
||
def create_user(client, data, access_token): | ||
delete_user(data["email"]) | ||
|
||
return client.put( | ||
"/editUser", data=json.dumps(data), headers=make_headers(access_token) | ||
) | ||
|
||
|
||
def test_get_reports(client): | ||
"""Teste get /reports/ - Valida status_code 200""" | ||
access_token = get_access(client) | ||
|
@@ -66,9 +74,7 @@ def test_put_user(client): | |
"active": "true", | ||
} | ||
|
||
response = client.put( | ||
"/editUser", data=json.dumps(data), headers=make_headers(access_token) | ||
) | ||
response = create_user(client, data, access_token) | ||
responseObject = json.loads(response.data) | ||
userId = responseObject["data"] | ||
user = session.query(User).filter(User.id == userId).first() | ||
|
@@ -81,7 +87,19 @@ def test_put_editUser(client): | |
"""Teste put /editUser/<int:idUser> - Compara o response.data e edita o usuário""" | ||
access_token = get_access(client, roles=["userAdmin", "staging"]) | ||
|
||
user = session.query(User).filter(User.email == "[email protected]").first() | ||
# first insert user | ||
create_data = { | ||
"id": "", | ||
"email": "[email protected]", | ||
"name": "test3", | ||
"external": "test", | ||
"active": "true", | ||
} | ||
|
||
response = create_user(client, create_data, access_token) | ||
assert response.status_code == 200 | ||
|
||
user = session.query(User).filter(User.email == create_data["email"]).first() | ||
assert user != None | ||
|
||
data = { | ||
|
@@ -107,4 +125,149 @@ def test_put_editUser(client): | |
assert data["external"] == userEdited.external | ||
assert data["active"] == userEdited.active | ||
|
||
delete_user("[email protected]") | ||
|
||
def test_create_user_invalid_role(client): | ||
"""Teste put /editUser - Verifica roles criadas""" | ||
access_token = get_access(client, roles=["userAdmin", "staging"]) | ||
email = "[email protected]" | ||
|
||
delete_user(email) | ||
|
||
data = { | ||
"id": "", | ||
"email": email, | ||
"name": "test3", | ||
"external": "test", | ||
"active": "true", | ||
"roles": ["admin"], | ||
} | ||
|
||
response = client.put( | ||
"/editUser", data=json.dumps(data), headers=make_headers(access_token) | ||
) | ||
responseObject = json.loads(response.data) | ||
userId = responseObject["data"] | ||
user = session.query(User).filter(User.id == userId).first() | ||
|
||
assert response.status_code == 200 | ||
assert "admin" not in user.config["roles"] | ||
assert "userAdmin" not in user.config["roles"] | ||
|
||
|
||
def test_update_user_invalid_role(client): | ||
"""Teste put /editUser/<int:idUser> - Compara o response.data e edita o usuário""" | ||
access_token = get_access(client, roles=["userAdmin", "staging"]) | ||
|
||
# first insert user | ||
create_data = { | ||
"id": "", | ||
"email": "[email protected]", | ||
"name": "test3", | ||
"external": "test", | ||
"active": "true", | ||
} | ||
|
||
response = create_user(client, create_data, access_token) | ||
assert response.status_code == 200 | ||
|
||
user = session.query(User).filter(User.email == create_data["email"]).first() | ||
assert user != None | ||
|
||
data = { | ||
"id": user.id, | ||
"email": user.email, | ||
"name": "updateTest", | ||
"external": "updateTest", | ||
"active": False, | ||
"roles": ["admin"], | ||
} | ||
|
||
response = client.put( | ||
"/editUser/" + str(user.id), | ||
data=json.dumps(data), | ||
headers=make_headers(access_token), | ||
) | ||
assert response.status_code == 200 | ||
|
||
session_commit() | ||
|
||
userEdited = session.query(User).filter(User.id == user.id).first() | ||
|
||
assert data["name"] == userEdited.name | ||
assert data["external"] == userEdited.external | ||
assert "admin" not in user.config["roles"] | ||
assert "userAdmin" not in user.config["roles"] | ||
|
||
|
||
def test_create_user_invalid_role_perimission(client): | ||
"""Teste put /editUser - Roles inválidas""" | ||
|
||
email = "[email protected]" | ||
|
||
delete_user(email) | ||
|
||
data = { | ||
"id": "", | ||
"email": email, | ||
"name": "test3", | ||
"external": "test", | ||
"active": "true", | ||
"roles": ["admin"], | ||
} | ||
|
||
access_token = get_access(client, roles=["userAdmin", "staging", "admin"]) | ||
response = client.put( | ||
"/editUser", data=json.dumps(data), headers=make_headers(access_token) | ||
) | ||
assert response.status_code == 401 | ||
|
||
access_token = get_access(client, roles=["userAdmin", "staging", "training"]) | ||
response = client.put( | ||
"/editUser", data=json.dumps(data), headers=make_headers(access_token) | ||
) | ||
assert response.status_code == 401 | ||
|
||
|
||
def test_update_user_invalid_role_permission(client): | ||
"""Teste put /editUser/<int:idUser> - Edição com roles inválidas""" | ||
access_token = get_access(client, roles=["userAdmin", "staging"]) | ||
|
||
# first insert user | ||
create_data = { | ||
"id": "", | ||
"email": "[email protected]", | ||
"name": "test3", | ||
"external": "test", | ||
"active": "true", | ||
} | ||
|
||
response = create_user(client, create_data, access_token) | ||
assert response.status_code == 200 | ||
|
||
user = session.query(User).filter(User.email == create_data["email"]).first() | ||
assert user != None | ||
|
||
data = { | ||
"id": user.id, | ||
"email": user.email, | ||
"name": "updateTest", | ||
"external": "updateTest", | ||
"active": False, | ||
"roles": ["admin"], | ||
} | ||
|
||
access_token = get_access(client, roles=["userAdmin", "staging", "admin"]) | ||
response = client.put( | ||
"/editUser/" + str(user.id), | ||
data=json.dumps(data), | ||
headers=make_headers(access_token), | ||
) | ||
assert response.status_code == 401 | ||
|
||
access_token = get_access(client, roles=["userAdmin", "staging", "training"]) | ||
response = client.put( | ||
"/editUser/" + str(user.id), | ||
data=json.dumps(data), | ||
headers=make_headers(access_token), | ||
) | ||
assert response.status_code == 401 |