-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add
status_in
filter to projectUsers query (#1397)
- Loading branch information
Showing
11 changed files
with
226 additions
and
53 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import uuid | ||
|
||
import pytest | ||
|
||
from kili.client import Kili | ||
|
||
|
||
@pytest.fixture() | ||
def kili() -> Kili: | ||
return Kili() | ||
|
||
|
||
@pytest.fixture() | ||
def project_id_suspended_user_email(kili: Kili): | ||
project = kili.create_project( | ||
input_type="TEXT", title="test_query_project_users.py sdk", json_interface={"jobs": {}} | ||
) | ||
|
||
# add a user that we desactivate | ||
suspended_user_email = f"john.doe{uuid.uuid4()}[email protected]" | ||
kili.append_to_roles( | ||
project_id=project["id"], | ||
user_email=suspended_user_email, | ||
role="LABELER", | ||
) | ||
kili.update_properties_in_user(email=suspended_user_email, activated=False) | ||
|
||
yield project["id"], suspended_user_email | ||
|
||
kili.delete_project(project_id=project["id"]) | ||
|
||
|
||
def test_given_project_when_querying_project_users_it_works( | ||
kili: Kili, project_id_suspended_user_email | ||
): | ||
# Given | ||
project_id, suspended_user_email = project_id_suspended_user_email | ||
api_user = kili.get_user() | ||
fields = ["activated", "deletedAt", "id", "role", "user.email", "user.id", "status"] | ||
|
||
# When | ||
all_users = kili.project_users(project_id=project_id, fields=fields, status_in=None) | ||
|
||
# Then | ||
assert len(all_users) > 0 | ||
|
||
# When | ||
activated_users = kili.project_users( | ||
project_id=project_id, fields=fields, status_in=["ACTIVATED"] | ||
) | ||
|
||
# Then, only one activated user: the api user | ||
assert len(activated_users) == 1, activated_users | ||
assert activated_users[0]["user"]["email"] == api_user["email"], activated_users | ||
|
||
# When | ||
admin_users = kili.project_users(project_id=project_id, fields=fields, status_in=["ORG_ADMIN"]) | ||
|
||
# Then, admin users are not api user or disabled user | ||
for proj_user in admin_users: | ||
assert proj_user["user"]["email"] not in { | ||
api_user["email"], | ||
suspended_user_email, | ||
}, admin_users | ||
|
||
# When | ||
disabled_users = kili.project_users( | ||
project_id=project_id, fields=fields, status_in=["ORG_SUSPENDED"] | ||
) | ||
|
||
# Then, only one disabled user | ||
assert len(disabled_users) == 1, disabled_users | ||
assert disabled_users[0]["user"]["email"] == suspended_user_email, disabled_users |
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
24 changes: 0 additions & 24 deletions
24
...lient/queries/test_user_facing_queries.py → ...nts/client/queries/test_assets_queries.py
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 |
---|---|---|
@@ -1,35 +1,11 @@ | ||
"""Module for testing the user-facing-queries method.""" | ||
|
||
|
||
from typing import Dict, Generator, List | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from typeguard import check_type | ||
|
||
from kili.core.graphql.operations.asset.queries import AssetQuery | ||
from kili.core.graphql.operations.user.queries import UserQuery | ||
from kili.entrypoints.queries.asset import QueriesAsset | ||
from kili.entrypoints.queries.user import QueriesUser | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args, kwargs, expected_return_type", | ||
[ | ||
((), {}, List[Dict]), | ||
((), {"as_generator": True}, Generator[Dict, None, None]), | ||
((), {"as_generator": False}, List[Dict]), | ||
((), {"email": "[email protected]", "as_generator": False}, List[Dict]), | ||
], | ||
) | ||
@patch.object(UserQuery, "__call__") | ||
def test_users_query_return_type(mocker, args, kwargs, expected_return_type): | ||
kili = QueriesUser() | ||
kili.graphql_client = mocker.MagicMock() | ||
kili.http_client = mocker.MagicMock() | ||
|
||
result = kili.users(*args, **kwargs) | ||
assert check_type("result", result, expected_return_type) is None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
File renamed without changes.
Oops, something went wrong.