| 1 |
import json |
| 2 |
import uuid |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
from globus_sdk import exc |
| 7 |
from globus_sdk.services.transfer import CreateTunnelData |
| 8 |
from globus_sdk.testing import get_last_request, load_response |
| 9 |
|
| 10 |
|
| 11 |
def test_create_tunnel(client): |
| 12 |
meta = load_response(client.create_tunnel).metadata |
| 13 |
|
| 14 |
submission_id = uuid.uuid4() |
| 15 |
data = CreateTunnelData( |
| 16 |
meta["initiator_ap"], |
| 17 |
meta["listener_ap"], |
| 18 |
submission_id=submission_id, |
| 19 |
label=meta["display_name"], |
| 20 |
) |
| 21 |
|
| 22 |
res = client.create_tunnel(data) |
| 23 |
assert res.http_status == 200 |
| 24 |
assert res["data"]["type"] == "Tunnel" |
| 25 |
|
| 26 |
req = get_last_request() |
| 27 |
sent = json.loads(req.body) |
| 28 |
assert ( |
| 29 |
sent["data"]["relationships"]["initiator"]["data"]["id"] == meta["initiator_ap"] |
| 30 |
) |
| 31 |
assert ( |
| 32 |
sent["data"]["relationships"]["listener"]["data"]["id"] == meta["listener_ap"] |
| 33 |
) |
| 34 |
assert sent["data"]["attributes"]["submission_id"] == str(submission_id) |
| 35 |
assert sent["data"]["attributes"]["label"] == meta["display_name"] |
| 36 |
|
| 37 |
|
| 38 |
def test_create_tunnel_no_submission(client): |
| 39 |
meta = load_response(client.create_tunnel).metadata |
| 40 |
|
| 41 |
data = CreateTunnelData( |
| 42 |
meta["initiator_ap"], meta["listener_ap"], label=meta["display_name"] |
| 43 |
) |
| 44 |
|
| 45 |
res = client.create_tunnel(data) |
| 46 |
assert res.http_status == 200 |
| 47 |
|
| 48 |
req = get_last_request() |
| 49 |
sent = json.loads(req.body) |
| 50 |
assert sent["data"]["attributes"]["submission_id"] is not None |
| 51 |
|
| 52 |
|
| 53 |
def test_create_tunnel_bad_input(client): |
| 54 |
data = { |
| 55 |
"relationships": { |
| 56 |
"listener": { |
| 57 |
"data": { |
| 58 |
"type": "StreamAccessPoint", |
| 59 |
} |
| 60 |
}, |
| 61 |
"initiator": { |
| 62 |
"data": { |
| 63 |
"type": "StreamAccessPoint", |
| 64 |
} |
| 65 |
}, |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
with pytest.raises(exc.GlobusSDKUsageError): |
| 70 |
client.create_tunnel(data) |