| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import copy |
| 4 |
import datetime |
| 5 |
import typing as t |
| 6 |
import uuid |
| 7 |
|
| 8 |
from responses import matchers |
| 9 |
|
| 10 |
from globus_sdk.testing import RegisteredResponse, ResponseList, ResponseSet |
| 11 |
|
| 12 |
from ._common import RUN, RUN_ID, USER1 |
| 13 |
|
| 14 |
FLOW_ID_ALPHA = str(uuid.uuid1()) |
| 15 |
FLOW_ID_BETA = str(uuid.uuid1()) |
| 16 |
|
| 17 |
|
| 18 |
def generate_example_run(n: int, flow_id: str | None = None) -> dict[str, t.Any]: |
| 19 |
run_id = str(uuid.UUID(int=n)) |
| 20 |
|
| 21 |
base_time = datetime.datetime.fromisoformat("2021-10-18T19:19:35.967289+00:00") |
| 22 |
start_time = base_time + datetime.timedelta(days=n) |
| 23 |
completion_time = base_time + datetime.timedelta(days=n + 1) |
| 24 |
|
| 25 |
run_doc = copy.deepcopy(RUN) |
| 26 |
run_doc["completion_time"] = completion_time.isoformat() |
| 27 |
run_doc["label"] = f"Run {n}" |
| 28 |
run_doc["start_time"] = start_time.isoformat() |
| 29 |
run_doc["run_id"] = run_id |
| 30 |
run_doc["action_id"] = run_id |
| 31 |
if flow_id is not None: |
| 32 |
run_doc["flow_id"] = flow_id |
| 33 |
|
| 34 |
return run_doc |
| 35 |
|
| 36 |
|
| 37 |
_combined_filter_output = { |
| 38 |
"runs": [generate_example_run(i, flow_id=FLOW_ID_ALPHA) for i in range(5)] |
| 39 |
+ [generate_example_run(i, flow_id=FLOW_ID_BETA) for i in range(5)], |
| 40 |
"limit": 10, |
| 41 |
"has_next_page": False, |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
RESPONSES = ResponseSet( |
| 46 |
default=RegisteredResponse( |
| 47 |
service="flows", |
| 48 |
path="/runs", |
| 49 |
json={ |
| 50 |
"runs": [RUN], |
| 51 |
"limit": 20, |
| 52 |
"has_next_page": False, |
| 53 |
"marker": None, |
| 54 |
}, |
| 55 |
metadata={"first_run_id": RUN_ID}, |
| 56 |
), |
| 57 |
filter_flow_id=ResponseList( |
| 58 |
RegisteredResponse( |
| 59 |
service="flows", |
| 60 |
path="/runs", |
| 61 |
json={ |
| 62 |
"runs": [ |
| 63 |
generate_example_run(i, flow_id=FLOW_ID_ALPHA) for i in range(5) |
| 64 |
], |
| 65 |
"limit": 5, |
| 66 |
"has_next_page": False, |
| 67 |
}, |
| 68 |
match=[matchers.query_param_matcher({"filter_flow_id": FLOW_ID_ALPHA})], |
| 69 |
), |
| 70 |
RegisteredResponse( |
| 71 |
service="flows", |
| 72 |
path="/runs", |
| 73 |
json={ |
| 74 |
"runs": [ |
| 75 |
generate_example_run(i, flow_id=FLOW_ID_BETA) for i in range(5) |
| 76 |
], |
| 77 |
"limit": 5, |
| 78 |
"has_next_page": False, |
| 79 |
}, |
| 80 |
match=[matchers.query_param_matcher({"filter_flow_id": FLOW_ID_BETA})], |
| 81 |
), |
| 82 |
# register this twice to make the matching order insensitive |
| 83 |
RegisteredResponse( |
| 84 |
service="flows", |
| 85 |
path="/runs", |
| 86 |
json=_combined_filter_output, |
| 87 |
match=[ |
| 88 |
matchers.query_param_matcher( |
| 89 |
{"filter_flow_id": f"{FLOW_ID_ALPHA},{FLOW_ID_BETA}"} |
| 90 |
) |
| 91 |
], |
| 92 |
), |
| 93 |
RegisteredResponse( |
| 94 |
service="flows", |
| 95 |
path="/runs", |
| 96 |
json=_combined_filter_output, |
| 97 |
match=[ |
| 98 |
matchers.query_param_matcher( |
| 99 |
{"filter_flow_id": f"{FLOW_ID_BETA},{FLOW_ID_ALPHA}"} |
| 100 |
) |
| 101 |
], |
| 102 |
), |
| 103 |
metadata={ |
| 104 |
"by_flow_id": { |
| 105 |
FLOW_ID_ALPHA: { |
| 106 |
"num": 5, |
| 107 |
}, |
| 108 |
FLOW_ID_BETA: { |
| 109 |
"num": 5, |
| 110 |
}, |
| 111 |
} |
| 112 |
}, |
| 113 |
), |
| 114 |
paginated=ResponseList( |
| 115 |
RegisteredResponse( |
| 116 |
service="flows", |
| 117 |
path="/runs", |
| 118 |
json={ |
| 119 |
"runs": [generate_example_run(i) for i in range(20)], |
| 120 |
"limit": 20, |
| 121 |
"has_next_page": True, |
| 122 |
"marker": "fake_marker_0", |
| 123 |
}, |
| 124 |
), |
| 125 |
RegisteredResponse( |
| 126 |
service="flows", |
| 127 |
path="/runs", |
| 128 |
json={ |
| 129 |
"runs": [generate_example_run(i) for i in range(20, 40)], |
| 130 |
"limit": 20, |
| 131 |
"has_next_page": True, |
| 132 |
"marker": "fake_marker_1", |
| 133 |
}, |
| 134 |
match=[matchers.query_param_matcher({"marker": "fake_marker_0"})], |
| 135 |
), |
| 136 |
RegisteredResponse( |
| 137 |
service="flows", |
| 138 |
path="/runs", |
| 139 |
json={ |
| 140 |
"runs": [generate_example_run(i) for i in range(40, 60)], |
| 141 |
"limit": 20, |
| 142 |
"has_next_page": False, |
| 143 |
"marker": None, |
| 144 |
}, |
| 145 |
match=[matchers.query_param_matcher({"marker": "fake_marker_1"})], |
| 146 |
), |
| 147 |
metadata={ |
| 148 |
"owner_id": USER1, |
| 149 |
"num_pages": 3, |
| 150 |
"expect_markers": ["fake_marker_0", "fake_marker_1", None], |
| 151 |
"total_items": 60, |
| 152 |
}, |
| 153 |
), |
| 154 |
) |