Debian Codegraph @

src/globus_sdk/testing/data/flows/list_flows.py

raw
1 from __future__ import annotations
2
3 import datetime
4 import typing as t
5 import uuid
6
7 from responses import matchers
8
9 from globus_sdk.testing.models import RegisteredResponse, ResponseList, ResponseSet
10
11 from ._common import TWO_HOP_TRANSFER_FLOW_DOC, TWO_HOP_TRANSFER_FLOW_ID
12
13 OWNER_ID = "e061df5a-b7b9-4578-a73b-6d4a4edfd66e"
14
15
16 def generate_hello_world_example_flow(n: int) -> dict[str, t.Any]:
17 flow_id = str(uuid.UUID(int=n))
18 base_time = datetime.datetime.fromisoformat("2021-10-18T19:19:35.967289+00:00")
19 updated_at = created_at = base_time + datetime.timedelta(days=n)
20 flow_user_scope = (
21 f"https://auth.globus.org/scopes/{flow_id}/"
22 f"flow_{flow_id.replace('-', '_')}_user"
23 )
24
25 return {
26 "action_url": f"https://flows.automate.globus.org/flows/{flow_id}",
27 "administered_by": [],
28 "api_version": "1.0",
29 "created_at": created_at.isoformat() + "+00:00",
30 "created_by": f"urn:globus:auth:identity:{OWNER_ID}",
31 "definition": {
32 "StartAt": "HelloWorld",
33 "States": {
34 "HelloWorld": {
35 "ActionScope": (
36 "https://auth.globus.org/scopes/actions.globus.org/hello_world"
37 ),
38 "ActionUrl": "https://actions.globus.org/hello_world",
39 "End": True,
40 "Parameters": {"echo_string": "Hello, World."},
41 "ResultPath": "$.Result",
42 "Type": "Action",
43 }
44 },
45 },
46 "description": "A simple Flow...",
47 "flow_administrators": [],
48 "flow_owner": f"urn:globus:auth:identity:{OWNER_ID}",
49 "flow_starters": [],
50 "flow_url": f"https://flows.automate.globus.org/flows/{flow_id}",
51 "flow_viewers": [],
52 "globus_auth_scope": flow_user_scope,
53 "globus_auth_username": f"{flow_id}@clients.auth.globus.org",
54 "id": str(flow_id),
55 "input_schema": {
56 "additionalProperties": False,
57 "properties": {
58 "echo_string": {"description": "The string to echo", "type": "string"},
59 "sleep_time": {"type": "integer"},
60 },
61 "required": ["echo_string", "sleep_time"],
62 "type": "object",
63 },
64 "keywords": [],
65 "log_supported": True,
66 "principal_urn": f"urn:globus:auth:identity:{flow_id}",
67 "runnable_by": [],
68 "subtitle": "",
69 "synchronous": False,
70 "title": f"Hello, World (Example {n})",
71 "types": ["Action"],
72 "updated_at": updated_at.isoformat() + "+00:00",
73 "user_role": "flow_viewer",
74 "visible_to": [],
75 }
76
77
78 RESPONSES = ResponseSet(
79 metadata={"first_flow_id": TWO_HOP_TRANSFER_FLOW_ID},
80 default=RegisteredResponse(
81 service="flows",
82 path="/flows",
83 json={
84 "flows": [TWO_HOP_TRANSFER_FLOW_DOC],
85 "limit": 20,
86 "has_next_page": False,
87 "marker": None,
88 },
89 ),
90 paginated=ResponseList(
91 RegisteredResponse(
92 service="flows",
93 path="/flows",
94 json={
95 "flows": [generate_hello_world_example_flow(i) for i in range(20)],
96 "limit": 20,
97 "has_next_page": True,
98 "marker": "fake_marker_0",
99 },
100 ),
101 RegisteredResponse(
102 service="flows",
103 path="/flows",
104 json={
105 "flows": [generate_hello_world_example_flow(i) for i in range(20, 40)],
106 "limit": 20,
107 "has_next_page": True,
108 "marker": "fake_marker_1",
109 },
110 match=[matchers.query_param_matcher({"marker": "fake_marker_0"})],
111 ),
112 RegisteredResponse(
113 service="flows",
114 path="/flows",
115 json={
116 "flows": [generate_hello_world_example_flow(i) for i in range(40, 60)],
117 "limit": 20,
118 "has_next_page": False,
119 "marker": None,
120 },
121 match=[matchers.query_param_matcher({"marker": "fake_marker_1"})],
122 ),
123 metadata={
124 "owner_id": OWNER_ID,
125 "num_pages": 3,
126 "expect_markers": ["fake_marker_0", "fake_marker_1", None],
127 "total_items": 60,
128 },
129 ),
130 )