| 1 |
import json |
| 2 |
|
| 3 |
import pytest |
| 4 |
from responses import matchers |
| 5 |
|
| 6 |
from globus_sdk import MISSING, FlowsAPIError |
| 7 |
from globus_sdk.testing import get_last_request, load_response |
| 8 |
from globus_sdk.testing.models import RegisteredResponse |
| 9 |
|
| 10 |
|
| 11 |
@pytest.mark.parametrize("subscription_id", [MISSING, None, "dummy_subscription_id"]) |
| 12 |
def test_create_flow(flows_client, subscription_id): |
| 13 |
metadata = load_response(flows_client.create_flow).metadata |
| 14 |
|
| 15 |
resp = flows_client.create_flow( |
| 16 |
**metadata["params"], subscription_id=subscription_id |
| 17 |
) |
| 18 |
assert resp.data["title"] == "Multi Step Transfer" |
| 19 |
|
| 20 |
last_req = get_last_request() |
| 21 |
req_body = json.loads(last_req.body) |
| 22 |
if subscription_id is not MISSING: |
| 23 |
assert req_body["subscription_id"] == subscription_id |
| 24 |
else: |
| 25 |
assert "subscription_id" not in req_body |
| 26 |
|
| 27 |
|
| 28 |
@pytest.mark.parametrize("value", [MISSING, [], ["dummy_value"]]) |
| 29 |
@pytest.mark.parametrize("key", ["run_managers", "run_monitors"]) |
| 30 |
def test_create_flow_run_role_serialization(flows_client, key, value): |
| 31 |
|
| 32 |
request_body = { |
| 33 |
"title": "Multi Step Transfer", |
| 34 |
"definition": { |
| 35 |
"StartAt": "Transfer1", |
| 36 |
"States": { |
| 37 |
"Transfer1": {"Type": "Pass", "End": True}, |
| 38 |
}, |
| 39 |
}, |
| 40 |
"input_schema": {}, |
| 41 |
} |
| 42 |
|
| 43 |
if value is not MISSING: |
| 44 |
request_body[key] = value |
| 45 |
|
| 46 |
load_response( |
| 47 |
RegisteredResponse( |
| 48 |
service="flows", |
| 49 |
path="/flows", |
| 50 |
method="POST", |
| 51 |
json=request_body, |
| 52 |
match=[ |
| 53 |
matchers.json_params_matcher( |
| 54 |
params={ |
| 55 |
"title": request_body["title"], |
| 56 |
"definition": request_body["definition"], |
| 57 |
"input_schema": request_body["input_schema"], |
| 58 |
}, |
| 59 |
strict_match=False, |
| 60 |
) |
| 61 |
], |
| 62 |
) |
| 63 |
) |
| 64 |
|
| 65 |
flows_client.create_flow(**request_body) |
| 66 |
|
| 67 |
last_req = get_last_request() |
| 68 |
req_body = json.loads(last_req.body) |
| 69 |
|
| 70 |
if value is MISSING: |
| 71 |
assert key not in req_body |
| 72 |
else: |
| 73 |
assert req_body[key] == value |
| 74 |
|
| 75 |
|
| 76 |
def test_create_flow_error_parsing(flows_client): |
| 77 |
metadata = load_response( |
| 78 |
flows_client.create_flow, case="bad_admin_principal_error" |
| 79 |
).metadata |
| 80 |
with pytest.raises(FlowsAPIError) as excinfo: |
| 81 |
flows_client.create_flow(**metadata["params"]) |
| 82 |
err = excinfo.value |
| 83 |
assert err.code == "UNPROCESSABLE_ENTITY" |
| 84 |
assert err.messages == [ |
| 85 |
( |
| 86 |
'Unrecognized principal string: "ae341a98-d274-11e5-b888-dbae3a8ba545". ' |
| 87 |
'Allowed principal types in role "FlowAdministrator": ' |
| 88 |
"[<AuthGroupUrn>, <AuthIdentityUrn>]" |
| 89 |
), |
| 90 |
( |
| 91 |
'Unrecognized principal string: "4fab4345-6d20-43a0-9a25-16b2e3bbe765". ' |
| 92 |
'Allowed principal types in role "FlowAdministrator": ' |
| 93 |
"[<AuthGroupUrn>, <AuthIdentityUrn>]" |
| 94 |
), |
| 95 |
] |
| 96 |
|
| 97 |
|
| 98 |
def test_get_flow(flows_client): |
| 99 |
meta = load_response(flows_client.get_flow).metadata |
| 100 |
resp = flows_client.get_flow(meta["flow_id"]) |
| 101 |
assert resp.data["title"] == meta["title"] |
| 102 |
|
| 103 |
|
| 104 |
def test_update_flow(flows_client): |
| 105 |
meta = load_response(flows_client.update_flow).metadata |
| 106 |
resp = flows_client.update_flow(meta["flow_id"], **meta["params"]) |
| 107 |
for k, v in meta["params"].items(): |
| 108 |
assert k in resp |
| 109 |
assert resp[k] == v |
| 110 |
|
| 111 |
|
| 112 |
@pytest.mark.parametrize("value", [MISSING, [], ["dummy_value"]]) |
| 113 |
@pytest.mark.parametrize("key", ["run_managers", "run_monitors"]) |
| 114 |
def test_update_flow_run_role_serialization(flows_client, key, value): |
| 115 |
metadata = load_response(flows_client.update_flow).metadata |
| 116 |
params = {**metadata["params"], key: value} |
| 117 |
|
| 118 |
flows_client.update_flow(metadata["flow_id"], **params) |
| 119 |
|
| 120 |
last_req = get_last_request() |
| 121 |
req_body = json.loads(last_req.body) |
| 122 |
|
| 123 |
if value is MISSING: |
| 124 |
assert key not in req_body |
| 125 |
else: |
| 126 |
assert req_body[key] == value |
| 127 |
|
| 128 |
|
| 129 |
def test_delete_flow(flows_client): |
| 130 |
metadata = load_response(flows_client.delete_flow).metadata |
| 131 |
|
| 132 |
resp = flows_client.delete_flow(metadata["flow_id"]) |
| 133 |
assert resp.data["title"] == "Multi Step Transfer" |
| 134 |
assert resp.data["DELETED"] is True |