fix(users): handle no admin case
parent
adcdbfb368
commit
e835173fea
|
@ -58,7 +58,7 @@ def get_users(
|
||||||
)
|
)
|
||||||
for user in user_data["users"]
|
for user in user_data["users"]
|
||||||
]
|
]
|
||||||
if not exclude_primary:
|
if not exclude_primary and "username" in user_data.keys():
|
||||||
users.append(
|
users.append(
|
||||||
UserDataUser(
|
UserDataUser(
|
||||||
username=user_data["username"],
|
username=user_data["username"],
|
||||||
|
|
|
@ -6,6 +6,7 @@ from tests.common import (
|
||||||
generate_users_query,
|
generate_users_query,
|
||||||
read_json,
|
read_json,
|
||||||
)
|
)
|
||||||
|
from selfprivacy_api.utils import WriteUserData
|
||||||
from tests.test_graphql.common import assert_empty, assert_errorcode
|
from tests.test_graphql.common import assert_empty, assert_errorcode
|
||||||
|
|
||||||
invalid_usernames = [
|
invalid_usernames = [
|
||||||
|
@ -89,6 +90,15 @@ def undefined_settings(mocker, datadir):
|
||||||
return datadir
|
return datadir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def no_users_no_admin_nobody(undefined_settings):
|
||||||
|
datadir = undefined_settings
|
||||||
|
with WriteUserData() as data:
|
||||||
|
del data["username"]
|
||||||
|
del data["sshKeys"]
|
||||||
|
return datadir
|
||||||
|
|
||||||
|
|
||||||
class ProcessMock:
|
class ProcessMock:
|
||||||
"""Mock subprocess.Popen"""
|
"""Mock subprocess.Popen"""
|
||||||
|
|
||||||
|
@ -170,7 +180,7 @@ def test_graphql_get_no_users(authorized_client, no_users, mock_subprocess_popen
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_get_users_undefined(authorized_client, undefined_settings):
|
def test_graphql_get_users_undefined_but_admin(authorized_client, undefined_settings):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
|
@ -187,6 +197,21 @@ def test_graphql_get_users_undefined(authorized_client, undefined_settings):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_get_users_undefined_no_admin(
|
||||||
|
authorized_client, no_users_no_admin_nobody
|
||||||
|
):
|
||||||
|
response = authorized_client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": generate_users_query([API_USERS_INFO]),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json().get("data") is not None
|
||||||
|
|
||||||
|
assert len(response.json()["data"]["users"]["allUsers"]) == 0
|
||||||
|
|
||||||
|
|
||||||
API_GET_USERS = """
|
API_GET_USERS = """
|
||||||
query TestUsers($username: String!) {
|
query TestUsers($username: String!) {
|
||||||
users {
|
users {
|
||||||
|
|
|
@ -112,15 +112,6 @@ def mock_subprocess_popen(mocker):
|
||||||
|
|
||||||
## TESTS ######################################################
|
## TESTS ######################################################
|
||||||
|
|
||||||
|
|
||||||
def test_get_undefined_users(
|
|
||||||
authorized_client, undefined_settings, mock_subprocess_popen
|
|
||||||
):
|
|
||||||
response = authorized_client.get("/users")
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json() == []
|
|
||||||
|
|
||||||
|
|
||||||
# graphql tests still provide these fields even if with empty values
|
# graphql tests still provide these fields even if with empty values
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue