-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validate_flow
operation to FlowsClient
#979
Merged
ada-globus
merged 2 commits into
main
from
an/add-validate-route-to-flows-client/sc-33101
Apr 25, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
~~~~~ | ||
|
||
- Added support to ``FlowsClient`` for the ``validate_flow`` operation of the | ||
Globus Flows service. (: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,115 @@ | ||
from responses import matchers | ||
|
||
from globus_sdk._testing.models import RegisteredResponse, ResponseSet | ||
|
||
VALIDATE_SIMPLE_FLOW_DEFINITION = { | ||
"Comment": "Simple flow", | ||
"StartAt": "Step1", | ||
"States": { | ||
"Step1": { | ||
"Type": "Action", | ||
"ActionUrl": "https://transfer.actions.globus.org/transfer", | ||
"Parameters": { | ||
"source_endpoint.$": "$.source_endpoint_id", | ||
"destination_endpoint.$": "$.destination_endpoint_id", | ||
"DATA": [ | ||
{ | ||
"source_path.$": "$.source_path", | ||
"destination_path.$": "$.destination_path", | ||
} | ||
], | ||
}, | ||
"ResultPath": "$.TransferResult", | ||
"End": True, | ||
} | ||
}, | ||
} | ||
|
||
VALIDATE_SIMPLE_SUCCESS_RESPONSE = { | ||
"scopes": {"User": ["urn:globus:auth:scope:transfer.api.globus.org:all"]} | ||
} | ||
|
||
VALIDATE_INVALID_FLOW_DEFINITION = { | ||
"Comment": "Simple flow", | ||
"StartAt": "Step1", | ||
"States": { | ||
"Step1": { | ||
"Type": "Action", | ||
"ActionUrl": "https://transfer.actions.globus.org/transfer", | ||
"Parameters": { | ||
"source_endpoint.$": "$.source_endpoint_id", | ||
"destination_endpoint.$": "$.destination_endpoint_id", | ||
"DATA": [ | ||
{ | ||
"source_path.$": "$.source_path", | ||
"destination_path.$": "$.destination_path", | ||
} | ||
], | ||
}, | ||
"ResultPath": "$.TransferResult", | ||
} | ||
}, | ||
} | ||
|
||
VALIDATE_INVALID_RESPONSE = { | ||
"error": { | ||
"code": "UNPROCESSABLE_ENTITY", | ||
"detail": [ | ||
{ | ||
"loc": ["definition", "States", "Step1"], | ||
"msg": ( | ||
"A state of type 'Action' must be defined as either terminal " | ||
'("End": true) or transitional ("Next": "NextStateId")' | ||
), | ||
"type": "value_error", | ||
} | ||
], | ||
"message": ( | ||
"1 validation error in body. $.definition.States.Step1: A state of " | ||
"type 'Action' must be defined as either terminal (\"End\": true) " | ||
'or transitional ("Next": "NextStateId")' | ||
), | ||
}, | ||
"debug_id": "41267e70-6788-4316-8b67-df7160166466", | ||
} | ||
|
||
_validate_simple_flow_request = { | ||
"definition": VALIDATE_SIMPLE_FLOW_DEFINITION, | ||
} | ||
|
||
_validate_invalid_flow_request = { | ||
"definition": VALIDATE_INVALID_FLOW_DEFINITION, | ||
} | ||
|
||
RESPONSES = ResponseSet( | ||
metadata={ | ||
"success": VALIDATE_SIMPLE_FLOW_DEFINITION, | ||
"invalid": VALIDATE_INVALID_FLOW_DEFINITION, | ||
}, | ||
default=RegisteredResponse( | ||
service="flows", | ||
path="/flows/validate", | ||
method="POST", | ||
status=200, | ||
json=VALIDATE_SIMPLE_SUCCESS_RESPONSE, | ||
match=[ | ||
matchers.json_params_matcher( | ||
params={"definition": VALIDATE_SIMPLE_FLOW_DEFINITION}, | ||
strict_match=False, | ||
) | ||
], | ||
), | ||
definition_error=RegisteredResponse( | ||
service="flows", | ||
path="/flows/validate", | ||
method="POST", | ||
status=422, | ||
json=VALIDATE_INVALID_RESPONSE, | ||
match=[ | ||
matchers.json_params_matcher( | ||
params={"definition": VALIDATE_INVALID_FLOW_DEFINITION}, | ||
strict_match=False, | ||
) | ||
], | ||
), | ||
) |
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,46 @@ | ||
import json | ||
|
||
import pytest | ||
|
||
from globus_sdk import FlowsAPIError | ||
from globus_sdk._testing import get_last_request, load_response | ||
|
||
|
||
@pytest.mark.parametrize("input_schema", [None, {}]) | ||
def test_validate_flow(flows_client, input_schema): | ||
metadata = load_response(flows_client.validate_flow).metadata | ||
|
||
# Prepare the payload | ||
payload = {"definition": metadata["success"]} | ||
if input_schema is not None: | ||
payload["input_schema"] = input_schema | ||
|
||
resp = flows_client.validate_flow(**payload) | ||
assert resp.data["scopes"] == { | ||
"User": ["urn:globus:auth:scope:transfer.api.globus.org:all"] | ||
} | ||
|
||
# Check what was actually sent | ||
last_req = get_last_request() | ||
req_body = json.loads(last_req.body) | ||
# Ensure the input schema is not sent if omitted | ||
assert req_body == payload | ||
|
||
|
||
def test_validate_flow_error_parsing(flows_client): | ||
metadata = load_response( | ||
flows_client.validate_flow, case="definition_error" | ||
).metadata | ||
|
||
# Make sure we get an error response | ||
with pytest.raises(FlowsAPIError) as excinfo: | ||
flows_client.validate_flow(definition=metadata["invalid"]) | ||
|
||
err = excinfo.value | ||
assert err.code == "UNPROCESSABLE_ENTITY" | ||
assert err.messages == [ | ||
( | ||
"A state of type 'Action' must be defined as either terminal " | ||
'("End": true) or transitional ("Next": "NextStateId")' | ||
), | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a style-guide for this. We started using emphasis (boldface, IIRC?) in some of the docs for
flow
,run
,timer
, and other proper nouns which are easily confused with service names.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think the way I'd phrase it is roughly:
Is there such a paradigm—or related prior-art—in the SDK docs? If so, happy to make consistent!