2023-12-08 01:38:24 +00:00
|
|
|
from conftest import STATUS_SUCCESS, STATUS_ERROR, LOGIN_ENDPOINT, LOGOUT_ENDPOINT
|
2022-09-24 02:10:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_login_with_valid_credentials(pytestconfig, http_client_unauthenticated):
|
2022-12-05 17:58:23 +00:00
|
|
|
# Note: This test depends on the piscsi group existing and 'username' a member the group
|
2022-09-24 02:10:01 +00:00
|
|
|
response = http_client_unauthenticated.post(
|
2023-12-08 01:38:24 +00:00
|
|
|
LOGIN_ENDPOINT,
|
2022-09-24 02:10:01 +00:00
|
|
|
data={
|
2022-12-05 17:58:23 +00:00
|
|
|
"username": pytestconfig.getoption("piscsi_username"),
|
|
|
|
"password": pytestconfig.getoption("piscsi_password"),
|
2022-09-24 02:10:01 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
assert "env" in response_data["data"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_login_with_invalid_credentials(http_client_unauthenticated):
|
|
|
|
response = http_client_unauthenticated.post(
|
2023-12-08 01:38:24 +00:00
|
|
|
LOGIN_ENDPOINT,
|
2022-09-24 02:10:01 +00:00
|
|
|
data={
|
|
|
|
"username": "__INVALID_USER__",
|
|
|
|
"password": "__INVALID_PASS__",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
assert response.status_code == 401
|
|
|
|
assert response_data["status"] == STATUS_ERROR
|
|
|
|
assert response_data["messages"][0]["message"] == (
|
2022-12-05 17:58:23 +00:00
|
|
|
"You must log in with valid credentials for a user in the 'piscsi' group"
|
2022-09-24 02:10:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_logout(http_client):
|
2023-12-08 01:38:24 +00:00
|
|
|
response = http_client.get(LOGOUT_ENDPOINT)
|
2022-09-25 17:15:35 +00:00
|
|
|
assert response.status_code == 200
|