dex-connector-google-forms 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dex_connector_google_forms-0.1.0/.gitignore +16 -0
- dex_connector_google_forms-0.1.0/LICENSE +21 -0
- dex_connector_google_forms-0.1.0/PKG-INFO +54 -0
- dex_connector_google_forms-0.1.0/README.md +42 -0
- dex_connector_google_forms-0.1.0/examples/response_recorder/__init__.py +3 -0
- dex_connector_google_forms-0.1.0/examples/response_recorder/flow.py +166 -0
- dex_connector_google_forms-0.1.0/examples/response_recorder/test_integration.py +99 -0
- dex_connector_google_forms-0.1.0/examples/response_recorder/worker.py +51 -0
- dex_connector_google_forms-0.1.0/pyproject.toml +38 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/__init__.py +63 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/_generated/__init__.py +2 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/_generated/config.py +31 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/_generated/connection.py +241 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/_generated/definitions.py +75 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/_generated/mock.py +200 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/_generated/models.py +303 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/_generated/refresh.py +9 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/_generated/steps.py +187 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/_generated/timestamps.py +60 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/client.py +128 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/connection.py +23 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/conversion.py +326 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/definitions.py +16 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/dex-connector.json +125 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/formsmock/__init__.py +6 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/json_values.py +23 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/models.py +37 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/operations.py +357 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/py.typed +2 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/query_values.py +16 -0
- dex_connector_google_forms-0.1.0/src/dex_connectors/google_forms/steps.py +7 -0
- dex_connector_google_forms-0.1.0/tests/refresh_agreement_cases.json +1309 -0
- dex_connector_google_forms-0.1.0/tests/test_conformance.py +37 -0
- dex_connector_google_forms-0.1.0/tests/test_json_values.py +15 -0
- dex_connector_google_forms-0.1.0/tests/test_query_values.py +36 -0
- dex_connector_google_forms-0.1.0/tests/test_refresh_agreement.py +278 -0
- dex_connector_google_forms-0.1.0/tests/test_timestamp_precision.py +53 -0
- dex_connector_google_forms-0.1.0/uv.lock +934 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
node_modules/
|
|
5
|
+
dist/
|
|
6
|
+
sdkpython/dist/dex_connectors_sdk-0.1.0-py3-none-any.whl
|
|
7
|
+
/.bin/dexcli
|
|
8
|
+
/.bin/dex-server-zd
|
|
9
|
+
/sdkpython/.dexcli-data/
|
|
10
|
+
site/.catalog.yaml
|
|
11
|
+
coverage/
|
|
12
|
+
*.out
|
|
13
|
+
*.test
|
|
14
|
+
go.work
|
|
15
|
+
go.work.sum
|
|
16
|
+
.idea/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-google-forms
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Dex-native Python connector for Google Forms
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: dex-connectors-sdk==0.7.0
|
|
9
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Google Forms Python connector
|
|
14
|
+
|
|
15
|
+
The `dex-connector-google-forms` package implements `getForm`,
|
|
16
|
+
`listResponses`, and `getResponse` as Dex Query Steps. It uses the Google Forms
|
|
17
|
+
connection and authorization guidance in the [connector README](../README.md).
|
|
18
|
+
The package requires `dex-connectors-sdk==0.7.0`.
|
|
19
|
+
|
|
20
|
+
The runnable [response recorder](examples/response_recorder/flow.py) reads a
|
|
21
|
+
form, one page of responses, and one response by ID. Its
|
|
22
|
+
[Worker entrypoint](examples/response_recorder/worker.py) loads the static
|
|
23
|
+
`google-forms-intake` connection from Dex project configuration. Configure that
|
|
24
|
+
connection in Dex Web, then start the Worker with:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
cd connectors/google/forms/python
|
|
28
|
+
uv run python -m examples.response_recorder.worker
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
From this repository, verify Go-recorded provider behavior and Python package
|
|
32
|
+
checks with:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
make test-connector-conformance CONNECTOR_DIRECTORY=connectors/google/forms
|
|
36
|
+
uv run --project connectors/google/forms/python ruff check connectors/google/forms/python
|
|
37
|
+
uv run --project connectors/google/forms/python mypy --strict connectors/google/forms/python/src
|
|
38
|
+
uv run --project connectors/google/forms/python pytest connectors/google/forms/python/tests
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The [Dex integration test](examples/response_recorder/test_integration.py)
|
|
42
|
+
starts a real Worker and Flow against a local Dex service and an in-process
|
|
43
|
+
Forms stand-in. With `dexcli dev` listening on port 39650, run:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:39650 \
|
|
47
|
+
uv run --project connectors/google/forms/python pytest \
|
|
48
|
+
connectors/google/forms/python/examples/response_recorder/test_integration.py
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The connector preserves RFC 3339 timestamps through nine fractional digits in
|
|
52
|
+
provider results, response filters, and Dex codec round trips. The local
|
|
53
|
+
integration test does not exercise live Google OAuth consent, form access, or
|
|
54
|
+
Forms API responses; those require a user-controlled Google connection.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Google Forms Python connector
|
|
2
|
+
|
|
3
|
+
The `dex-connector-google-forms` package implements `getForm`,
|
|
4
|
+
`listResponses`, and `getResponse` as Dex Query Steps. It uses the Google Forms
|
|
5
|
+
connection and authorization guidance in the [connector README](../README.md).
|
|
6
|
+
The package requires `dex-connectors-sdk==0.7.0`.
|
|
7
|
+
|
|
8
|
+
The runnable [response recorder](examples/response_recorder/flow.py) reads a
|
|
9
|
+
form, one page of responses, and one response by ID. Its
|
|
10
|
+
[Worker entrypoint](examples/response_recorder/worker.py) loads the static
|
|
11
|
+
`google-forms-intake` connection from Dex project configuration. Configure that
|
|
12
|
+
connection in Dex Web, then start the Worker with:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
cd connectors/google/forms/python
|
|
16
|
+
uv run python -m examples.response_recorder.worker
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
From this repository, verify Go-recorded provider behavior and Python package
|
|
20
|
+
checks with:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
make test-connector-conformance CONNECTOR_DIRECTORY=connectors/google/forms
|
|
24
|
+
uv run --project connectors/google/forms/python ruff check connectors/google/forms/python
|
|
25
|
+
uv run --project connectors/google/forms/python mypy --strict connectors/google/forms/python/src
|
|
26
|
+
uv run --project connectors/google/forms/python pytest connectors/google/forms/python/tests
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The [Dex integration test](examples/response_recorder/test_integration.py)
|
|
30
|
+
starts a real Worker and Flow against a local Dex service and an in-process
|
|
31
|
+
Forms stand-in. With `dexcli dev` listening on port 39650, run:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:39650 \
|
|
35
|
+
uv run --project connectors/google/forms/python pytest \
|
|
36
|
+
connectors/google/forms/python/examples/response_recorder/test_integration.py
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The connector preserves RFC 3339 timestamps through nine fractional digits in
|
|
40
|
+
provider results, response filters, and Dex codec round trips. The local
|
|
41
|
+
integration test does not exercise live Google OAuth consent, form access, or
|
|
42
|
+
Forms API responses; those require a user-controlled Google connection.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Read a form, list one response page, and read one response by ID."""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
import dex
|
|
8
|
+
from dex_connectors.sdk import QueryResult
|
|
9
|
+
|
|
10
|
+
from dex_connectors.google_forms import (
|
|
11
|
+
Connection,
|
|
12
|
+
Form,
|
|
13
|
+
FormResponse,
|
|
14
|
+
GetFormInput,
|
|
15
|
+
GetResponseInput,
|
|
16
|
+
ListResponsesInput,
|
|
17
|
+
ResponsePage,
|
|
18
|
+
new_get_form_step,
|
|
19
|
+
new_get_response_step,
|
|
20
|
+
new_list_responses_step,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
CONNECTION_NAME = "google-forms-intake"
|
|
24
|
+
_FORM_ID = dex.Attribute("google-forms-python-form-id", str)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True, slots=True)
|
|
28
|
+
class RecorderInput:
|
|
29
|
+
"""Form whose first response page should be read."""
|
|
30
|
+
|
|
31
|
+
form_id: str
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass(frozen=True, slots=True)
|
|
35
|
+
class RecorderOutcome:
|
|
36
|
+
"""One form and its first response, if present."""
|
|
37
|
+
|
|
38
|
+
form: Form
|
|
39
|
+
page: ResponsePage
|
|
40
|
+
response: FormResponse | None = None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# dex:group group-id:google-forms group-label:"Google Forms"
|
|
44
|
+
# dex:explanation text:"Store the form ID and read its questions before recording responses."
|
|
45
|
+
class PrepareRequest(dex.Step[RecorderInput]):
|
|
46
|
+
"""Retain the form identity across provider Steps."""
|
|
47
|
+
|
|
48
|
+
def get_step_type(self) -> str:
|
|
49
|
+
return "PrepareFormsRequest"
|
|
50
|
+
|
|
51
|
+
def execute(self, context: dex.Context, input: RecorderInput) -> dex.StepDecision:
|
|
52
|
+
if not input.form_id:
|
|
53
|
+
return dex.force_fail("form ID is required")
|
|
54
|
+
_FORM_ID.set(context, input.form_id)
|
|
55
|
+
return dex.go_to(dex.StepRef("ReadGoogleForm"), input)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# dex:group group-id:google-forms group-label:"Google Forms"
|
|
59
|
+
# dex:explanation text:"Carry the form result into the response listing Step."
|
|
60
|
+
class FormRead(dex.Step[QueryResult[Form]]):
|
|
61
|
+
"""Start the response list after the form is found."""
|
|
62
|
+
|
|
63
|
+
def get_step_type(self) -> str:
|
|
64
|
+
return "GoogleFormRead"
|
|
65
|
+
|
|
66
|
+
def execute(self, context: dex.Context, input: QueryResult[Form]) -> dex.StepDecision:
|
|
67
|
+
return dex.go_to(dex.StepRef("ListGoogleResponses"), GetFormInput(input.value.form_id))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# dex:group group-id:google-forms group-label:"Google Forms"
|
|
71
|
+
# dex:explanation text:"Complete an empty page or read its first response by ID."
|
|
72
|
+
class PageRead(dex.Step[QueryResult[ResponsePage]]):
|
|
73
|
+
"""Read the first response when Google returned one."""
|
|
74
|
+
|
|
75
|
+
def get_step_type(self) -> str:
|
|
76
|
+
return "GoogleResponsePageRead"
|
|
77
|
+
|
|
78
|
+
def execute(self, context: dex.Context, input: QueryResult[ResponsePage]) -> dex.StepDecision:
|
|
79
|
+
if not input.value.responses:
|
|
80
|
+
return dex.graceful_complete(input.value)
|
|
81
|
+
return dex.go_to(
|
|
82
|
+
dex.StepRef("ReadGoogleResponse"),
|
|
83
|
+
GetResponseInput(input.value.form_id, input.value.responses[0].response_id),
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# dex:group group-id:google-forms group-label:"Google Forms"
|
|
88
|
+
# dex:explanation text:"Complete after the individual Google response is found."
|
|
89
|
+
class ResponseRead(dex.Step[QueryResult[FormResponse]]):
|
|
90
|
+
"""Complete with the provider response record."""
|
|
91
|
+
|
|
92
|
+
def get_step_type(self) -> str:
|
|
93
|
+
return "GoogleResponseRead"
|
|
94
|
+
|
|
95
|
+
def execute(self, context: dex.Context, input: QueryResult[FormResponse]) -> dex.StepDecision:
|
|
96
|
+
return dex.graceful_complete(input.value)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class ResponseRecorderFlow(dex.Flow[RecorderInput]):
|
|
100
|
+
"""Exercise all three Google Forms operations in a real Dex Flow."""
|
|
101
|
+
|
|
102
|
+
def __init__(self, connection: Connection) -> None:
|
|
103
|
+
if connection.reference.name != CONNECTION_NAME:
|
|
104
|
+
raise ValueError("the Google Forms connection name must be static")
|
|
105
|
+
self._prepare = PrepareRequest()
|
|
106
|
+
self._form_read = FormRead()
|
|
107
|
+
self._page_read = PageRead()
|
|
108
|
+
self._response_read = ResponseRead()
|
|
109
|
+
self._get_form = new_get_form_step(
|
|
110
|
+
step_type="ReadGoogleForm",
|
|
111
|
+
step_input_type=RecorderInput,
|
|
112
|
+
annotations={
|
|
113
|
+
"groupId": "google-forms",
|
|
114
|
+
"groupLabel": "Google Forms",
|
|
115
|
+
"explanation": "Read the form's questions.",
|
|
116
|
+
},
|
|
117
|
+
connection=connection,
|
|
118
|
+
connection_name=CONNECTION_NAME,
|
|
119
|
+
map_to_operation_input=lambda value: GetFormInput(value.form_id),
|
|
120
|
+
found=self._form_read,
|
|
121
|
+
)
|
|
122
|
+
self._list_responses = new_list_responses_step(
|
|
123
|
+
step_type="ListGoogleResponses",
|
|
124
|
+
step_input_type=GetFormInput,
|
|
125
|
+
annotations={
|
|
126
|
+
"groupId": "google-forms",
|
|
127
|
+
"groupLabel": "Google Forms",
|
|
128
|
+
"explanation": "List one bounded page of responses.",
|
|
129
|
+
},
|
|
130
|
+
connection=connection,
|
|
131
|
+
connection_name=CONNECTION_NAME,
|
|
132
|
+
map_to_operation_input=lambda value: ListResponsesInput(value.form_id, page_size=25),
|
|
133
|
+
listed=self._page_read,
|
|
134
|
+
)
|
|
135
|
+
self._get_response = new_get_response_step(
|
|
136
|
+
step_type="ReadGoogleResponse",
|
|
137
|
+
step_input_type=GetResponseInput,
|
|
138
|
+
annotations={
|
|
139
|
+
"groupId": "google-forms",
|
|
140
|
+
"groupLabel": "Google Forms",
|
|
141
|
+
"explanation": "Read one response by its provider ID.",
|
|
142
|
+
},
|
|
143
|
+
connection=connection,
|
|
144
|
+
connection_name=CONNECTION_NAME,
|
|
145
|
+
map_to_operation_input=lambda value: value,
|
|
146
|
+
found=self._response_read,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
def get_flow_type(self) -> str:
|
|
150
|
+
"""Return the stable example Flow identity."""
|
|
151
|
+
return "GoogleFormsPythonResponseRecorder"
|
|
152
|
+
|
|
153
|
+
def get_steps(self) -> dex.StepList[RecorderInput]:
|
|
154
|
+
"""Register admission, three provider reads, and their success routes."""
|
|
155
|
+
return dex.StepList.start_step(self._prepare).other_steps(
|
|
156
|
+
self._get_form,
|
|
157
|
+
self._form_read,
|
|
158
|
+
self._list_responses,
|
|
159
|
+
self._page_read,
|
|
160
|
+
self._get_response,
|
|
161
|
+
self._response_read,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
165
|
+
"""Persist the form ID used by downstream Steps."""
|
|
166
|
+
return dex.PersistenceSchema.of(_FORM_ID)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Run the Forms example through a real Dex Worker and local Forms stand-in."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
from datetime import timedelta
|
|
9
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from threading import Thread
|
|
12
|
+
from uuid import uuid4
|
|
13
|
+
|
|
14
|
+
import dex
|
|
15
|
+
import pytest
|
|
16
|
+
from dex_connectors.sdk import ConnectionRef, SecretString, StaticCredentialProvider
|
|
17
|
+
|
|
18
|
+
from dex_connectors.google_forms import Client, Config, Credentials, FormResponse, new_connection
|
|
19
|
+
|
|
20
|
+
from .flow import CONNECTION_NAME, RecorderInput, ResponseRecorderFlow
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@pytest.mark.asyncio
|
|
24
|
+
async def test_response_recorder_reads_all_operations_in_real_dex(tmp_path: Path) -> None:
|
|
25
|
+
"""Verify Step transitions and provider calls against a real Dex service."""
|
|
26
|
+
service_address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
|
|
27
|
+
requests: list[str] = []
|
|
28
|
+
|
|
29
|
+
class FormsHandler(BaseHTTPRequestHandler):
|
|
30
|
+
def do_GET(self) -> None:
|
|
31
|
+
requests.append(self.path)
|
|
32
|
+
if self.path == "/v1/forms/form_1":
|
|
33
|
+
body = {"formId": "form_1", "info": {"title": "Vendor intake"}, "items": []}
|
|
34
|
+
elif self.path == "/v1/forms/form_1/responses?pageSize=25":
|
|
35
|
+
body = {
|
|
36
|
+
"responses": [
|
|
37
|
+
{
|
|
38
|
+
"responseId": "response_1",
|
|
39
|
+
"lastSubmittedTime": "2026-09-30T09:00:00.123456789Z",
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
elif self.path == "/v1/forms/form_1/responses/response_1":
|
|
44
|
+
body = {
|
|
45
|
+
"formId": "form_1",
|
|
46
|
+
"responseId": "response_1",
|
|
47
|
+
"lastSubmittedTime": "2026-09-30T09:00:00.123456789Z",
|
|
48
|
+
}
|
|
49
|
+
else:
|
|
50
|
+
self.send_error(404)
|
|
51
|
+
return
|
|
52
|
+
content = json.dumps(body).encode()
|
|
53
|
+
self.send_response(200)
|
|
54
|
+
self.send_header("Content-Type", "application/json")
|
|
55
|
+
self.send_header("Content-Length", str(len(content)))
|
|
56
|
+
self.end_headers()
|
|
57
|
+
self.wfile.write(content)
|
|
58
|
+
|
|
59
|
+
def log_message(self, format: str, *args: object) -> None:
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
server = ThreadingHTTPServer(("127.0.0.1", 0), FormsHandler)
|
|
63
|
+
thread = Thread(target=server.serve_forever, daemon=True)
|
|
64
|
+
thread.start()
|
|
65
|
+
connection_ref = ConnectionRef("google", CONNECTION_NAME)
|
|
66
|
+
credential_source = StaticCredentialProvider(
|
|
67
|
+
{connection_ref: Credentials(access_token=SecretString("inert-token"))}
|
|
68
|
+
)
|
|
69
|
+
client = Client(Config(endpoint=f"http://127.0.0.1:{server.server_port}"), credential_source)
|
|
70
|
+
connection = new_connection(client, connection_ref)
|
|
71
|
+
flow = ResponseRecorderFlow(connection)
|
|
72
|
+
registry = dex.Registry([flow], allow_async_handlers=True)
|
|
73
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(str(tmp_path / "blobs"), 1 << 24))
|
|
74
|
+
worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=service_address))
|
|
75
|
+
worker_task = asyncio.create_task(worker.start())
|
|
76
|
+
try:
|
|
77
|
+
await worker.wait_pull_registered(timeout=30)
|
|
78
|
+
async with dex.AsyncClient(
|
|
79
|
+
registry, cache, dex.ClientOptions(server_address=service_address)
|
|
80
|
+
) as dex_client:
|
|
81
|
+
flow_id = f"google-forms-python-{uuid4()}"
|
|
82
|
+
await dex_client.start_flow(flow, flow_id, RecorderInput("form_1"))
|
|
83
|
+
result = await dex_client.wait_for_flow(flow_id, timedelta(seconds=30))
|
|
84
|
+
assert result.status == dex.FlowStatus.COMPLETED, result.error_message
|
|
85
|
+
assert result.single_output(FormResponse).response_id == "response_1"
|
|
86
|
+
assert result.single_output(FormResponse).last_submitted_at == "2026-09-30T09:00:00.123456789Z"
|
|
87
|
+
assert requests == [
|
|
88
|
+
"/v1/forms/form_1",
|
|
89
|
+
"/v1/forms/form_1/responses?pageSize=25",
|
|
90
|
+
"/v1/forms/form_1/responses/response_1",
|
|
91
|
+
]
|
|
92
|
+
finally:
|
|
93
|
+
await worker.stop()
|
|
94
|
+
await worker_task
|
|
95
|
+
cache.close()
|
|
96
|
+
await connection.aclose()
|
|
97
|
+
server.shutdown()
|
|
98
|
+
server.server_close()
|
|
99
|
+
thread.join(timeout=5)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Worker entrypoint for the Google Forms response recorder."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import dex
|
|
11
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
12
|
+
|
|
13
|
+
from dex_connectors.google_forms import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, ResponseRecorderFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def run_worker() -> None:
|
|
19
|
+
"""Open the named Dex Web connection and serve the response recorder."""
|
|
20
|
+
project = await load_from_environment()
|
|
21
|
+
connection = None
|
|
22
|
+
cache = None
|
|
23
|
+
try:
|
|
24
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
25
|
+
registry = dex.Registry([ResponseRecorderFlow(connection)], allow_async_handlers=True)
|
|
26
|
+
cache_path = os.environ.get(
|
|
27
|
+
"DEX_BLOB_CACHE_DIR", str(Path(tempfile.gettempdir()) / "dex-google-forms-python-blobs")
|
|
28
|
+
)
|
|
29
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_path, 1 << 30))
|
|
30
|
+
worker = dex.AsyncWorker(
|
|
31
|
+
registry,
|
|
32
|
+
cache,
|
|
33
|
+
dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
|
|
34
|
+
)
|
|
35
|
+
async with worker:
|
|
36
|
+
await worker.start()
|
|
37
|
+
finally:
|
|
38
|
+
if connection is not None:
|
|
39
|
+
await connection.aclose()
|
|
40
|
+
if cache is not None:
|
|
41
|
+
cache.close()
|
|
42
|
+
await project.close()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def main() -> None:
|
|
46
|
+
"""Run the Worker until it stops."""
|
|
47
|
+
asyncio.run(run_worker())
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
main()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dex-connector-google-forms"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Dex-native Python connector for Google Forms"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = ["dex-connectors-sdk==0.7.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
|
|
14
|
+
|
|
15
|
+
[dependency-groups]
|
|
16
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7", "PyYAML>=6", "types-PyYAML>=6"]
|
|
17
|
+
|
|
18
|
+
[tool.hatch.build.targets.wheel]
|
|
19
|
+
packages = ["src/dex_connectors"]
|
|
20
|
+
|
|
21
|
+
[tool.pytest.ini_options]
|
|
22
|
+
testpaths = ["tests"]
|
|
23
|
+
pythonpath = [".", "src"]
|
|
24
|
+
asyncio_mode = "auto"
|
|
25
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
26
|
+
|
|
27
|
+
[tool.mypy]
|
|
28
|
+
python_version = "3.11"
|
|
29
|
+
strict = true
|
|
30
|
+
mypy_path = "src"
|
|
31
|
+
explicit_package_bases = true
|
|
32
|
+
|
|
33
|
+
[tool.ruff]
|
|
34
|
+
target-version = "py311"
|
|
35
|
+
line-length = 110
|
|
36
|
+
|
|
37
|
+
[tool.ruff.lint]
|
|
38
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Google Forms Query operations for Python Dex Flows."""
|
|
4
|
+
|
|
5
|
+
from .client import Client, Config, Credentials
|
|
6
|
+
from .connection import Connection, new_connection, new_project_connection
|
|
7
|
+
from .definitions import (
|
|
8
|
+
CONNECTOR_ID,
|
|
9
|
+
GET_FORM_DEFINITION,
|
|
10
|
+
GET_RESPONSE_DEFINITION,
|
|
11
|
+
LIST_RESPONSES_DEFINITION,
|
|
12
|
+
)
|
|
13
|
+
from .models import (
|
|
14
|
+
Form,
|
|
15
|
+
FormAnswer,
|
|
16
|
+
FormAnswerFile,
|
|
17
|
+
FormAnswerGrade,
|
|
18
|
+
FormChoice,
|
|
19
|
+
FormItem,
|
|
20
|
+
FormPublishState,
|
|
21
|
+
FormQuestion,
|
|
22
|
+
FormResponse,
|
|
23
|
+
FormScale,
|
|
24
|
+
GetFormInput,
|
|
25
|
+
GetResponseInput,
|
|
26
|
+
ListResponsesInput,
|
|
27
|
+
ResponsePage,
|
|
28
|
+
)
|
|
29
|
+
from .operations import GetFormOperation, GetResponseOperation, ListResponsesOperation
|
|
30
|
+
from .steps import new_get_form_step, new_get_response_step, new_list_responses_step
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"Client",
|
|
34
|
+
"Config",
|
|
35
|
+
"Credentials",
|
|
36
|
+
"Connection",
|
|
37
|
+
"new_connection",
|
|
38
|
+
"new_project_connection",
|
|
39
|
+
"CONNECTOR_ID",
|
|
40
|
+
"GET_FORM_DEFINITION",
|
|
41
|
+
"GET_RESPONSE_DEFINITION",
|
|
42
|
+
"LIST_RESPONSES_DEFINITION",
|
|
43
|
+
"Form",
|
|
44
|
+
"FormAnswer",
|
|
45
|
+
"FormAnswerFile",
|
|
46
|
+
"FormAnswerGrade",
|
|
47
|
+
"FormChoice",
|
|
48
|
+
"FormItem",
|
|
49
|
+
"FormPublishState",
|
|
50
|
+
"FormQuestion",
|
|
51
|
+
"FormResponse",
|
|
52
|
+
"FormScale",
|
|
53
|
+
"GetFormInput",
|
|
54
|
+
"GetResponseInput",
|
|
55
|
+
"ListResponsesInput",
|
|
56
|
+
"ResponsePage",
|
|
57
|
+
"GetFormOperation",
|
|
58
|
+
"GetResponseOperation",
|
|
59
|
+
"ListResponsesOperation",
|
|
60
|
+
"new_get_form_step",
|
|
61
|
+
"new_get_response_step",
|
|
62
|
+
"new_list_responses_step",
|
|
63
|
+
]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
endpoint: str = "https://forms.googleapis.com"
|
|
14
|
+
max_response_bytes: int = 1048576
|
|
15
|
+
response_page_size: int = 50
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.google_forms.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
auth_method_id: str = "google-oauth"
|
|
24
|
+
oauth_client_id: str | None = None
|
|
25
|
+
oauth_client_secret: SecretString | None = None
|
|
26
|
+
access_token: SecretString | None = None
|
|
27
|
+
refresh_token: SecretString | None = None
|
|
28
|
+
service_account_key: SecretString | None = None
|
|
29
|
+
delegated_user: str | None = None
|
|
30
|
+
|
|
31
|
+
setattr(Credentials, '__module__', 'dex_connectors.google_forms.client')
|