mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-03-13 02:04:09 +00:00
fix(users): handle no admin case
This commit is contained in:
parent
adcdbfb368
commit
e835173fea
3 changed files with 27 additions and 11 deletions
|
@ -58,7 +58,7 @@ def get_users(
|
|||
)
|
||||
for user in user_data["users"]
|
||||
]
|
||||
if not exclude_primary:
|
||||
if not exclude_primary and "username" in user_data.keys():
|
||||
users.append(
|
||||
UserDataUser(
|
||||
username=user_data["username"],
|
||||
|
|
|
@ -6,6 +6,7 @@ from tests.common import (
|
|||
generate_users_query,
|
||||
read_json,
|
||||
)
|
||||
from selfprivacy_api.utils import WriteUserData
|
||||
from tests.test_graphql.common import assert_empty, assert_errorcode
|
||||
|
||||
invalid_usernames = [
|
||||
|
@ -89,6 +90,15 @@ def undefined_settings(mocker, 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:
|
||||
"""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(
|
||||
"/graphql",
|
||||
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 = """
|
||||
query TestUsers($username: String!) {
|
||||
users {
|
||||
|
|
|
@ -112,15 +112,6 @@ def mock_subprocess_popen(mocker):
|
|||
|
||||
## 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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue