| 1 |
import json |
| 2 |
|
| 3 |
import globus_sdk |
| 4 |
from globus_sdk._missing import filter_missing |
| 5 |
from globus_sdk.testing import get_last_request, load_response |
| 6 |
|
| 7 |
|
| 8 |
def test_dummy_timer_creation(client): |
| 9 |
# create a timer with a dummy payload and validate how it gets wrapped by the |
| 10 |
# sending method |
| 11 |
meta = load_response(client.create_timer).metadata |
| 12 |
|
| 13 |
timer = client.create_timer(timer={"foo": "bar"}) |
| 14 |
assert timer["timer"]["job_id"] == meta["timer_id"] |
| 15 |
|
| 16 |
req = get_last_request() |
| 17 |
sent = json.loads(req.body) |
| 18 |
assert sent == {"timer": {"foo": "bar"}} |
| 19 |
|
| 20 |
|
| 21 |
def test_transfer_timer_creation(client): |
| 22 |
# create a timer using the payload helpers and confirm that it is serialized as |
| 23 |
# desired |
| 24 |
meta = load_response(client.create_timer).metadata |
| 25 |
body = globus_sdk.TransferData( |
| 26 |
source_endpoint=meta["source_endpoint"], |
| 27 |
destination_endpoint=meta["destination_endpoint"], |
| 28 |
) |
| 29 |
body.add_item("/share/godata/file1.txt", "/~/file1.txt") |
| 30 |
|
| 31 |
schedule = globus_sdk.RecurringTimerSchedule( |
| 32 |
interval_seconds=60, end={"condition": "iterations", "iterations": 3} |
| 33 |
) |
| 34 |
|
| 35 |
timer = client.create_timer( |
| 36 |
timer=globus_sdk.TransferTimer(body=body, schedule=schedule) |
| 37 |
) |
| 38 |
assert timer["timer"]["job_id"] == meta["timer_id"] |
| 39 |
|
| 40 |
req = get_last_request() |
| 41 |
sent = json.loads(req.body) |
| 42 |
assert sent["timer"]["schedule"] == { |
| 43 |
"type": "recurring", |
| 44 |
"interval_seconds": 60, |
| 45 |
"end": {"condition": "iterations", "iterations": 3}, |
| 46 |
} |
| 47 |
assert sent["timer"]["body"] == { |
| 48 |
k: [filter_missing(data_val) for data_val in v] if k == "DATA" else v |
| 49 |
for k, v in filter_missing(body).items() |
| 50 |
if k != "skip_activation_check" |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
def test_flow_timer_creation(client): |
| 55 |
# Setup |
| 56 |
meta = load_response(client.create_timer, case="flow_timer_success").metadata |
| 57 |
|
| 58 |
# Act |
| 59 |
client.create_timer( |
| 60 |
timer=globus_sdk.FlowTimer( |
| 61 |
flow_id=meta["flow_id"], |
| 62 |
body=meta["callback_body"], |
| 63 |
schedule=meta["schedule"], |
| 64 |
) |
| 65 |
) |
| 66 |
|
| 67 |
# Verify |
| 68 |
req = get_last_request() |
| 69 |
sent = json.loads(req.body) |
| 70 |
assert sent["timer"]["flow_id"] == meta["flow_id"] |
| 71 |
assert sent["timer"]["body"] == meta["callback_body"] |
| 72 |
assert sent["timer"]["schedule"] == meta["schedule"] |