Skip to content

Commit

Permalink
update schema, test
Browse files Browse the repository at this point in the history
  • Loading branch information
sir-sigurd committed Aug 7, 2024
1 parent ded2854 commit 64db7ed
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 72 deletions.
12 changes: 9 additions & 3 deletions api/python/quilt3-admin/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,19 @@ mutation usersRemoveRoles($name: String!, $roles: [String!]!, $fallback: String)
}
}

query getSsoConfig {
query ssoConfigGet {
admin {
ssoConfig
ssoConfig {
text
timestamp
uploader {
...UserSelection
}
}
}
}

mutation setSsoConfig($config: String) {
mutation ssoConfigSet($config: String) {
admin {
setSsoConfig(config: $config) {
... on Ok {
Expand Down
2 changes: 1 addition & 1 deletion api/python/quilt3/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

from . import roles, sso_config, users
from .exceptions import Quilt3AdminError, UserNotFoundError
from .types import ManagedRole, UnmanagedRole, User
from .types import ManagedRole, UnmanagedRole, SSOConfig, User
35 changes: 21 additions & 14 deletions api/python/quilt3/admin/_graphql_client/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 59 additions & 18 deletions api/python/quilt3/admin/_graphql_client/client.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions api/python/quilt3/admin/_graphql_client/get_sso_config.py

This file was deleted.

33 changes: 33 additions & 0 deletions api/python/quilt3/admin/_graphql_client/sso_config_get.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions api/python/quilt3/admin/sso_config.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import typing as T

from . import util
from . import types, util


def get() -> T.Optional[str]:
def get() -> T.Optional[types.SSOConfig]:
"""
Get the current SSO configuration.
"""
return util.get_client().get_sso_config()
result = util.get_client().sso_config_get()
return None if result is None else types.SSOConfig(**result.model_dump())


def set(config: T.Optional[str]) -> None:
"""
Set the SSO configuration.
"""
util.handle_errors(util.get_client().set_sso_config(config))
util.handle_errors(util.get_client().sso_config_set(config))
7 changes: 7 additions & 0 deletions api/python/quilt3/admin/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ class User:
is_service: bool
role: Optional[AnnotatedRole]
extra_roles: List[AnnotatedRole]


@pydantic.dataclasses.dataclass
class SSOConfig:
text: str
timestamp: datetime
uploader: User
38 changes: 38 additions & 0 deletions api/python/tests/test_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from quilt3 import admin
from quilt3.admin import _graphql_client

OK = {
"__typename": "Ok",
"_": None,
}
UNMANAGED_ROLE = {
"__typename": "UnmanagedRole",
"id": "d7d15bef-c482-4086-ae6b-d0372b6145d2",
Expand All @@ -32,6 +36,12 @@
"role": UNMANAGED_ROLE,
"extraRoles": [MANAGED_ROLE],
}
SSO_CONFIG = {
"__typename": "SsoConfig",
"text": "",
"timestamp": datetime.datetime(2024, 6, 14, 11, 42, 27, 857128, tzinfo=datetime.timezone.utc),
"uploader": USER,
}
MUTATION_ERRORS = (
(
{
Expand Down Expand Up @@ -324,3 +334,31 @@ def test_remove_roles(data, result):
admin.users.remove_roles("test", ["ManagedRole"], fallback="UnamanagedRole")
else:
assert admin.users.remove_roles("test", ["ManagedRole"], fallback="UnamanagedRole") == result


@pytest.mark.parametrize(
"data,result",
[
(SSO_CONFIG, admin.SSOConfig(**_as_dataclass_kwargs(SSO_CONFIG))),
(None, None),
],
)
def test_sso_config_get(data, result):
with mock_client(_make_nested_dict("admin.sso_config", data), "ssoConfigGet"):
assert admin.sso_config.get() == result


@pytest.mark.parametrize(
"data,result",
[
(OK, None),
*MUTATION_ERRORS,
],
)
def test_sso_config_set(data, result):
with mock_client(_make_nested_dict("admin.set_sso_config", data), "ssoConfigSet", variables={"config": ""}):
if isinstance(result, type) and issubclass(result, Exception):
with pytest.raises(result):
admin.sso_config.set("")
else:
assert admin.sso_config.set("") == result
Loading

0 comments on commit 64db7ed

Please sign in to comment.