-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement AuthClient.update_project (#774)
Additionally, fix `create_project` in a minor way, to include a `*` marker in its signature for keyword-only arguments.
- Loading branch information
Showing
4 changed files
with
219 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Added | ||
~~~~~ | ||
|
||
- Add ``AuthClient.update_project`` as a method for updating a Project via the | ||
Globus Auth Developer API (:pr:`NUMBER`) |
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,71 @@ | ||
import uuid | ||
|
||
from globus_sdk._testing.models import RegisteredResponse, ResponseSet | ||
|
||
project_id = str(uuid.uuid1()) | ||
star_lord = { | ||
"identity_provider": str(uuid.uuid1()), | ||
"identity_type": "login", | ||
"organization": "Guardians of the Galaxy", | ||
"status": "used", | ||
"id": str(uuid.uuid1()), | ||
"name": "Star Lord", | ||
"username": "star.lord@guardians.galaxy", | ||
"email": "star.lord2@guardians.galaxy", | ||
} | ||
guardians_group = { | ||
"id": str(uuid.uuid1()), | ||
"name": "Guardians of the Galaxy", | ||
"description": "A group of heroes", | ||
"organization": "Guardians of the Galaxy", | ||
} | ||
|
||
|
||
RESPONSES = ResponseSet( | ||
default=RegisteredResponse( | ||
service="auth", | ||
path=f"/v2/api/projects/{project_id}", | ||
method="PUT", | ||
json={ | ||
"project": { | ||
"contact_email": "support@globus.org", | ||
"id": project_id, | ||
"admins": { | ||
"identities": [star_lord], | ||
"groups": [], | ||
}, | ||
"project_name": "Guardians of the Galaxy", | ||
"admin_ids": [star_lord["id"]], | ||
"admin_group_ids": None, | ||
"display_name": "Guardians of the Galaxy", | ||
} | ||
}, | ||
metadata={ | ||
"id": project_id, | ||
"admin_id": star_lord["id"], | ||
}, | ||
), | ||
admin_group=RegisteredResponse( | ||
service="auth", | ||
path=f"/v2/api/projects/{project_id}", | ||
method="PUT", | ||
json={ | ||
"project": { | ||
"contact_email": "support@globus.org", | ||
"id": project_id, | ||
"admins": { | ||
"identities": [], | ||
"groups": [guardians_group], | ||
}, | ||
"project_name": "Guardians of the Galaxy", | ||
"admin_ids": None, | ||
"admin_group_ids": [guardians_group["id"]], | ||
"display_name": "Guardians of the Galaxy", | ||
} | ||
}, | ||
metadata={ | ||
"id": project_id, | ||
"admin_group_id": guardians_group["id"], | ||
}, | ||
), | ||
) |
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
81 changes: 81 additions & 0 deletions
81
tests/functional/services/auth/base/test_update_project.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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import json | ||
import uuid | ||
|
||
import pytest | ||
|
||
from globus_sdk._testing import get_last_request, load_response | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"admin_id_style", ("none", "string", "list", "set", "uuid", "uuid_list") | ||
) | ||
def test_update_project_admin_id_styles(client, admin_id_style): | ||
meta = load_response(client.update_project).metadata | ||
|
||
if admin_id_style == "none": | ||
admin_ids = None | ||
elif admin_id_style == "string": | ||
admin_ids = meta["admin_id"] | ||
elif admin_id_style == "list": | ||
admin_ids = [meta["admin_id"]] | ||
elif admin_id_style == "set": | ||
admin_ids = {meta["admin_id"]} | ||
elif admin_id_style == "uuid": | ||
admin_ids = uuid.UUID(meta["admin_id"]) | ||
elif admin_id_style == "uuid_list": | ||
admin_ids = [uuid.UUID(meta["admin_id"])] | ||
else: | ||
raise NotImplementedError(f"unknown admin_id_style {admin_id_style}") | ||
|
||
project_id = meta["id"] | ||
res = client.update_project( | ||
project_id, display_name="My Project", admin_ids=admin_ids | ||
) | ||
|
||
assert res["project"]["id"] == meta["id"] | ||
|
||
last_req = get_last_request() | ||
data = json.loads(last_req.body) | ||
assert list(data) == ["project"], data # 'project' is the only key | ||
if admin_id_style == "none": | ||
assert data["project"] == {"display_name": "My Project"} | ||
else: | ||
assert data["project"] == { | ||
"display_name": "My Project", | ||
"admin_ids": [meta["admin_id"]], | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"group_id_style", ("string", "list", "set", "uuid", "uuid_list") | ||
) | ||
def test_update_project_group_id_styles(client, group_id_style): | ||
meta = load_response(client.update_project, case="admin_group").metadata | ||
|
||
if group_id_style == "string": | ||
group_ids = meta["admin_group_id"] | ||
elif group_id_style == "list": | ||
group_ids = [meta["admin_group_id"]] | ||
elif group_id_style == "set": | ||
group_ids = {meta["admin_group_id"]} | ||
elif group_id_style == "uuid": | ||
group_ids = uuid.UUID(meta["admin_group_id"]) | ||
elif group_id_style == "uuid_list": | ||
group_ids = [uuid.UUID(meta["admin_group_id"])] | ||
else: | ||
raise NotImplementedError(f"unknown group_id_style {group_id_style}") | ||
|
||
project_id = meta["id"] | ||
res = client.update_project( | ||
project_id, contact_email="support@globus.org", admin_group_ids=group_ids | ||
) | ||
|
||
assert res["project"]["id"] == meta["id"] | ||
|
||
last_req = get_last_request() | ||
data = json.loads(last_req.body) | ||
assert list(data) == ["project"], data # 'project' is the only key | ||
assert data["project"] == { | ||
"contact_email": "support@globus.org", | ||
"admin_group_ids": [meta["admin_group_id"]], | ||
} |