| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import json |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
import globus_sdk |
| 8 |
from globus_sdk import FlowsAPIError, SpecificFlowClient |
| 9 |
from globus_sdk.testing import get_last_request, load_response |
| 10 |
|
| 11 |
|
| 12 |
def test_run_flow(specific_flow_client_class: type[SpecificFlowClient]): |
| 13 |
metadata = load_response(SpecificFlowClient.run_flow).metadata |
| 14 |
|
| 15 |
flow_client = specific_flow_client_class(flow_id=metadata["flow_id"]) |
| 16 |
|
| 17 |
resp = flow_client.run_flow(**metadata["request_params"]) |
| 18 |
assert resp.http_status == 200 |
| 19 |
|
| 20 |
|
| 21 |
def test_run_flow_missing_scope(specific_flow_client_class: type[SpecificFlowClient]): |
| 22 |
metadata = load_response( |
| 23 |
SpecificFlowClient.run_flow, case="missing_scope_error" |
| 24 |
).metadata |
| 25 |
|
| 26 |
flow_client = specific_flow_client_class(flow_id=metadata["flow_id"]) |
| 27 |
|
| 28 |
with pytest.raises(FlowsAPIError) as excinfo: |
| 29 |
flow_client.run_flow(**metadata["request_params"]) |
| 30 |
|
| 31 |
err = excinfo.value |
| 32 |
assert err.http_status == 403 |
| 33 |
assert err.code == "MISSING_SCOPE" |
| 34 |
assert ( |
| 35 |
err.message == "This action requires the following scope: frobulate[demuddle]" |
| 36 |
) |
| 37 |
|
| 38 |
|
| 39 |
def test_run_flow_without_activity_notification_policy( |
| 40 |
specific_flow_client_class, |
| 41 |
): |
| 42 |
metadata = load_response(SpecificFlowClient.run_flow).metadata |
| 43 |
flow_client = specific_flow_client_class(flow_id=metadata["flow_id"]) |
| 44 |
resp = flow_client.run_flow({}) |
| 45 |
assert resp.http_status == 200 |
| 46 |
|
| 47 |
last_req = get_last_request() |
| 48 |
sent_payload = json.loads(last_req.body) |
| 49 |
assert "activity_notification_policy" not in sent_payload |
| 50 |
|
| 51 |
|
| 52 |
def test_run_flow_with_empty_activity_notification_policy( |
| 53 |
specific_flow_client_class, |
| 54 |
): |
| 55 |
metadata = load_response(SpecificFlowClient.run_flow).metadata |
| 56 |
flow_client = specific_flow_client_class(flow_id=metadata["flow_id"]) |
| 57 |
|
| 58 |
policy = globus_sdk.RunActivityNotificationPolicy() |
| 59 |
flow_client.run_flow({}, activity_notification_policy=policy) |
| 60 |
|
| 61 |
last_req = get_last_request() |
| 62 |
sent_payload = json.loads(last_req.body) |
| 63 |
assert "activity_notification_policy" in sent_payload |
| 64 |
assert sent_payload["activity_notification_policy"] == {} |
| 65 |
|
| 66 |
|
| 67 |
def test_run_flow_with_activity_notification_policy( |
| 68 |
specific_flow_client_class, |
| 69 |
): |
| 70 |
metadata = load_response(SpecificFlowClient.run_flow).metadata |
| 71 |
flow_client = specific_flow_client_class(flow_id=metadata["flow_id"]) |
| 72 |
|
| 73 |
policy = globus_sdk.RunActivityNotificationPolicy(status=["FAILED", "INACTIVE"]) |
| 74 |
flow_client.run_flow({}, activity_notification_policy=policy) |
| 75 |
|
| 76 |
last_req = get_last_request() |
| 77 |
sent_payload = json.loads(last_req.body) |
| 78 |
assert "activity_notification_policy" in sent_payload |
| 79 |
assert sent_payload["activity_notification_policy"] == { |
| 80 |
"status": ["FAILED", "INACTIVE"] |
| 81 |
} |