pam-python 0.2.15__tar.gz → 0.2.17__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.
- {pam_python-0.2.15/pam_python.egg-info → pam_python-0.2.17}/PKG-INFO +1 -1
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/__init__.py +1 -1
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/models/data_input_v2.py +19 -6
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/task_manager.py +20 -5
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/init/AGENT.md +5 -0
- {pam_python-0.2.15 → pam_python-0.2.17/pam_python.egg-info}/PKG-INFO +1 -1
- {pam_python-0.2.15 → pam_python-0.2.17}/pam_python.egg-info/SOURCES.txt +1 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_data_error_v2.py +44 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_data_input_v2.py +24 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_report_store.py +3 -1
- pam_python-0.2.17/tests/test_task_manager_upload_token.py +61 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/LICENSE.txt +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/README.md +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/api.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/cli.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/datetime_utils.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/interface_task_manager.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/logger.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/models/__init__.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/models/request_command.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/models/sqlite_download.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/__init__.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/area.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/axis.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/bar.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/box_plot.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/bubble.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/candlestick.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/collection.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/definition.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/donut.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/errors.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/fields.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/heatmap.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/line.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/manager.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/metric.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/pie.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/polar_area.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/radar.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/radial_bar.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/range_area.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/range_bar.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/range_transform.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/record.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/scatter.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/schema.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/store.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/table.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/temporal.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/transport.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/reports/treemap.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/request_file_format.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/result_batch_uploader.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/server.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/service.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/sqlite.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/temp_file_utils.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/buildcmd/pamb +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/buildcmd/pamb-base.sh +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/init/REPORTS-th.md +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/init/REPORTS.md +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/init/dockerignore.tmpl +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/init/gitignore.tmpl +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/init/main.tmpl +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/init/pylintrc.tmpl +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/init/run_unit_test.bat +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/init/run_unit_test.ps1 +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/init/run_unit_test.sh +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/project/pip/Dockerfile +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/project/pip/requirements.txt +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/project/uv/Dockerfile +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/project/uv/pyproject.toml +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/project/uv/python-version +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/service/common/service.yaml +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/service/pandas/functions.tmpl +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/service/pandas/service.test.tmpl +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/service/pandas/service_class.tmpl +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/service/polars/functions.tmpl +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/service/polars/service.test.tmpl +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/templates/service/polars/service_class.tmpl +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/tester_task.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam/utils.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam_python.egg-info/dependency_links.txt +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam_python.egg-info/entry_points.txt +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam_python.egg-info/requires.txt +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pam_python.egg-info/top_level.txt +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/pyproject.toml +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/setup.cfg +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_api.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_cli_templates.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_data_timeout_v2.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_datetime_utils.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_range_transform.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_request_data_v2.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_result_batch_uploader.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_service_dataframe_output.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_sqlite_download_v2.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_temp_file_utils.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_temporal_mode.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_area_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_bar_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_box_plot_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_bubble_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_candlestick_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_donut_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_heatmap_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_line_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_metric_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_pie_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_polar_area_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_radar_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_radial_bar_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_range_area_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_range_bar_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_scatter_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_table_report.py +0 -0
- {pam_python-0.2.15 → pam_python-0.2.17}/tests/test_typed_treemap_report.py +0 -0
|
@@ -71,21 +71,34 @@ class DataInputV2Dataset:
|
|
|
71
71
|
for part in self.parts:
|
|
72
72
|
yield from part.iter_csv_rows()
|
|
73
73
|
|
|
74
|
-
def scan_polars(self) -> Any:
|
|
75
|
-
"""Return one lazy frame across all ordered CSV or Parquet parts.
|
|
74
|
+
def scan_polars(self, empty_schema: dict[str, Any] | None = None) -> Any:
|
|
75
|
+
"""Return one lazy frame across all ordered CSV or Parquet parts.
|
|
76
|
+
|
|
77
|
+
PAM represents a valid dataset with no rows as ``row_count=0`` and no
|
|
78
|
+
physical parts. In that case the plugin may provide its domain schema
|
|
79
|
+
so downstream computation can handle the empty input normally.
|
|
80
|
+
"""
|
|
76
81
|
pl = _import_polars()
|
|
77
82
|
if not self.parts:
|
|
78
|
-
|
|
83
|
+
schema = {"id": pl.String} if empty_schema is None else empty_schema
|
|
84
|
+
return pl.LazyFrame(schema=schema)
|
|
79
85
|
scans = [part.scan_polars() for part in self.parts]
|
|
80
86
|
if len(scans) == 1:
|
|
81
87
|
return scans[0]
|
|
82
88
|
return pl.concat(scans, how="diagonal_relaxed")
|
|
83
89
|
|
|
84
|
-
def read_pandas(self) -> Any:
|
|
85
|
-
"""Materialize and concatenate all verified parts using their metadata.
|
|
90
|
+
def read_pandas(self, empty_dtypes: dict[str, Any] | None = None) -> Any:
|
|
91
|
+
"""Materialize and concatenate all verified parts using their metadata.
|
|
92
|
+
|
|
93
|
+
``empty_dtypes`` is used only for a declared empty dataset, allowing
|
|
94
|
+
the plugin to retain its domain columns without fabricating data rows.
|
|
95
|
+
"""
|
|
86
96
|
pd = _import_pandas()
|
|
87
97
|
if not self.parts:
|
|
88
|
-
|
|
98
|
+
dtypes = {"id": "string"} if empty_dtypes is None else empty_dtypes
|
|
99
|
+
return pd.DataFrame(
|
|
100
|
+
{name: pd.Series(dtype=dtype) for name, dtype in dtypes.items()}
|
|
101
|
+
)
|
|
89
102
|
frames = [part.read_pandas() for part in self.parts]
|
|
90
103
|
if len(frames) == 1:
|
|
91
104
|
return frames[0]
|
|
@@ -258,8 +258,16 @@ class TaskManager(ITaskManager):
|
|
|
258
258
|
"""
|
|
259
259
|
log(f"Start Service: {service_name}, Token: {req.token}")
|
|
260
260
|
service_instance = service_class(self, req)
|
|
261
|
-
service_instance.on_start()
|
|
262
261
|
self._add_service(req.token, service_instance)
|
|
262
|
+
try:
|
|
263
|
+
# Register the service before on_start. A service commonly requests
|
|
264
|
+
# its first page from on_start, and PAM can deliver that page before
|
|
265
|
+
# on_start returns. Registering afterwards loses that callback and
|
|
266
|
+
# also lets on_dataset_input cancel the V2 wait timer permanently.
|
|
267
|
+
service_instance.on_start()
|
|
268
|
+
except BaseException:
|
|
269
|
+
self._remove_service(req.token)
|
|
270
|
+
raise
|
|
263
271
|
|
|
264
272
|
def terminate_service(self, token):
|
|
265
273
|
"""
|
|
@@ -419,9 +427,8 @@ class TaskManager(ITaskManager):
|
|
|
419
427
|
from its worker, so failures must propagate for retry handling.
|
|
420
428
|
"""
|
|
421
429
|
endpoint = service.request.response_api
|
|
422
|
-
payload =
|
|
430
|
+
payload = {"token": service.request.token}
|
|
423
431
|
if options is not None:
|
|
424
|
-
payload = {}
|
|
425
432
|
if "is_realtime" in options:
|
|
426
433
|
is_realtime = options.get("is_realtime")
|
|
427
434
|
payload["is_realtime"] = str(is_realtime).lower() if isinstance(is_realtime, bool) else is_realtime
|
|
@@ -464,7 +471,11 @@ class TaskManager(ITaskManager):
|
|
|
464
471
|
|
|
465
472
|
def upload_wrapper():
|
|
466
473
|
"""Wrapper for the report upload to handle response logging."""
|
|
467
|
-
response = self.api.http_upload(
|
|
474
|
+
response = self.api.http_upload(
|
|
475
|
+
endpoint,
|
|
476
|
+
file_path,
|
|
477
|
+
{"token": service.request.token},
|
|
478
|
+
)
|
|
468
479
|
handle_report_response(response)
|
|
469
480
|
|
|
470
481
|
log(f"Uploading Report to: {endpoint}")
|
|
@@ -501,7 +512,11 @@ class TaskManager(ITaskManager):
|
|
|
501
512
|
column_name: json.dumps(pointer, ensure_ascii=False, sort_keys=True),
|
|
502
513
|
})
|
|
503
514
|
|
|
504
|
-
response = self.api.http_upload(
|
|
515
|
+
response = self.api.http_upload(
|
|
516
|
+
service.request.response_api,
|
|
517
|
+
csv_path,
|
|
518
|
+
{"token": service.request.token},
|
|
519
|
+
)
|
|
505
520
|
if response is None:
|
|
506
521
|
return False
|
|
507
522
|
success = response.ok
|
|
@@ -234,6 +234,11 @@ result = calculate(population, profile_frame, purchase_frame).collect()
|
|
|
234
234
|
|
|
235
235
|
`scan_polars()` returns one lazy frame across ordered CSV or Parquet parts and
|
|
236
236
|
uses verified manifest format metadata. CSV-only code may use `iter_rows()`.
|
|
237
|
+
`row_count=0` with `parts=[]` is a valid empty dataset. The plugin decides the
|
|
238
|
+
business result for the page population; it must not treat the absence of event
|
|
239
|
+
rows as a transport error. If computation requires domain columns on an empty
|
|
240
|
+
frame, call `scan_polars(empty_schema=...)` or
|
|
241
|
+
`read_pandas(empty_dtypes=...)` with the plugin-owned schema.
|
|
237
242
|
The external customer key is `id`. The population file is authoritative: in
|
|
238
243
|
`contacts` mode, contacts with no event rows remain visible there. Use the
|
|
239
244
|
opaque `data.next` cursor for the next `_request_data_v2(...)` call and stop when
|
|
@@ -94,6 +94,7 @@ tests/test_request_data_v2.py
|
|
|
94
94
|
tests/test_result_batch_uploader.py
|
|
95
95
|
tests/test_service_dataframe_output.py
|
|
96
96
|
tests/test_sqlite_download_v2.py
|
|
97
|
+
tests/test_task_manager_upload_token.py
|
|
97
98
|
tests/test_temp_file_utils.py
|
|
98
99
|
tests/test_temporal_mode.py
|
|
99
100
|
tests/test_typed_area_report.py
|
|
@@ -11,6 +11,50 @@ from pam.task_manager import TaskManager
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class DataErrorV2Test(unittest.TestCase):
|
|
14
|
+
def test_start_service_registers_before_immediate_data_callback(self):
|
|
15
|
+
manager = TaskManager.__new__(TaskManager)
|
|
16
|
+
manager.thread_lock = threading.Lock()
|
|
17
|
+
manager.services = {}
|
|
18
|
+
manager.data_wait_timers = {}
|
|
19
|
+
request = Mock(token="run-1")
|
|
20
|
+
|
|
21
|
+
class ImmediateCallbackService:
|
|
22
|
+
def __init__(self, task_manager, req):
|
|
23
|
+
self.task_manager = task_manager
|
|
24
|
+
self.request = req
|
|
25
|
+
self.received = []
|
|
26
|
+
|
|
27
|
+
def on_start(self):
|
|
28
|
+
self.task_manager.on_dataset_input(self.request)
|
|
29
|
+
|
|
30
|
+
def on_data_input(self, req):
|
|
31
|
+
self.received.append(req)
|
|
32
|
+
|
|
33
|
+
manager.start_service(ImmediateCallbackService, request, "test-service")
|
|
34
|
+
|
|
35
|
+
service = manager.services[request.token].service
|
|
36
|
+
self.assertEqual([request], service.received)
|
|
37
|
+
|
|
38
|
+
def test_start_service_removes_registration_when_on_start_fails(self):
|
|
39
|
+
manager = TaskManager.__new__(TaskManager)
|
|
40
|
+
manager.thread_lock = threading.Lock()
|
|
41
|
+
manager.services = {}
|
|
42
|
+
manager.data_wait_timers = {}
|
|
43
|
+
|
|
44
|
+
service = Mock()
|
|
45
|
+
service.on_start.side_effect = RuntimeError("start failed")
|
|
46
|
+
service.request = Mock(service_name="test-service", token="run-1")
|
|
47
|
+
service.reports = Mock()
|
|
48
|
+
service_class = Mock(return_value=service)
|
|
49
|
+
request = Mock(token="run-1")
|
|
50
|
+
|
|
51
|
+
with self.assertRaisesRegex(RuntimeError, "start failed"):
|
|
52
|
+
manager.start_service(service_class, request, "test-service")
|
|
53
|
+
|
|
54
|
+
self.assertNotIn(request.token, manager.services)
|
|
55
|
+
service.on_destroy.assert_called_once_with()
|
|
56
|
+
service.reports.close.assert_called_once_with()
|
|
57
|
+
|
|
14
58
|
def test_request_command_parses_dataset_error_without_zip(self):
|
|
15
59
|
app = Flask(__name__)
|
|
16
60
|
with app.test_request_context(
|
|
@@ -78,6 +78,30 @@ class DataInputV2Test(unittest.TestCase):
|
|
|
78
78
|
self.assertEqual(0, data_input.datasets[0].row_count)
|
|
79
79
|
self.assertEqual((), data_input.datasets[0].parts)
|
|
80
80
|
|
|
81
|
+
def test_empty_dataset_readers_use_plugin_owned_schema(self):
|
|
82
|
+
import polars as pl
|
|
83
|
+
|
|
84
|
+
manifest = self._valid_manifest()
|
|
85
|
+
manifest["datasets"][0]["row_count"] = 0
|
|
86
|
+
manifest["datasets"][0]["parts"] = []
|
|
87
|
+
self.dataset_path.unlink()
|
|
88
|
+
manifest_path = self._write_manifest(manifest)
|
|
89
|
+
dataset = parse_data_input_v2(
|
|
90
|
+
[str(manifest_path), str(self.population_path)]
|
|
91
|
+
).datasets[0]
|
|
92
|
+
|
|
93
|
+
polars_frame = dataset.scan_polars(
|
|
94
|
+
empty_schema={"id": pl.String, "netamount": pl.Float64}
|
|
95
|
+
).collect()
|
|
96
|
+
self.assertEqual(0, polars_frame.height)
|
|
97
|
+
self.assertEqual(["id", "netamount"], polars_frame.columns)
|
|
98
|
+
|
|
99
|
+
pandas_frame = dataset.read_pandas(
|
|
100
|
+
empty_dtypes={"id": "string", "netamount": "float64"}
|
|
101
|
+
)
|
|
102
|
+
self.assertTrue(pandas_frame.empty)
|
|
103
|
+
self.assertEqual(["id", "netamount"], pandas_frame.columns.tolist())
|
|
104
|
+
|
|
81
105
|
def test_streams_population_and_ordered_dataset_parts(self):
|
|
82
106
|
second_part_path = self._write_file(
|
|
83
107
|
"dataset_001_demographic_part_0002.csv",
|
|
@@ -496,8 +496,9 @@ class ReportStoreTransportTest(unittest.TestCase):
|
|
|
496
496
|
captured = {}
|
|
497
497
|
response = Mock(ok=True)
|
|
498
498
|
|
|
499
|
-
def capture_upload(endpoint, file_path):
|
|
499
|
+
def capture_upload(endpoint, file_path, payload):
|
|
500
500
|
captured["endpoint"] = endpoint
|
|
501
|
+
captured["payload"] = payload
|
|
501
502
|
with open(file_path, encoding="utf-8", newline="") as input_file:
|
|
502
503
|
captured["row"] = next(csv.DictReader(input_file))
|
|
503
504
|
return response
|
|
@@ -535,6 +536,7 @@ class ReportStoreTransportTest(unittest.TestCase):
|
|
|
535
536
|
|
|
536
537
|
self.assertTrue(published)
|
|
537
538
|
self.assertEqual(request.response_api, captured["endpoint"])
|
|
539
|
+
self.assertEqual({"token": "token-1"}, captured["payload"])
|
|
538
540
|
self.assertEqual("adapter-1", captured["row"]["customer"])
|
|
539
541
|
self.assertEqual("Customer Report Group", captured["row"]["_tracker_name"])
|
|
540
542
|
self.assertEqual(
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import tempfile
|
|
2
|
+
import unittest
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from types import SimpleNamespace
|
|
5
|
+
from unittest.mock import Mock
|
|
6
|
+
|
|
7
|
+
from pam.task_manager import TaskManager
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TaskManagerUploadTokenTest(unittest.TestCase):
|
|
11
|
+
def setUp(self):
|
|
12
|
+
self.manager = TaskManager(SimpleNamespace())
|
|
13
|
+
self.manager.api = Mock()
|
|
14
|
+
self.service = SimpleNamespace(
|
|
15
|
+
request=SimpleNamespace(
|
|
16
|
+
response_api="http://pam/api/dataadapter/adapter-1/response",
|
|
17
|
+
token="token-1",
|
|
18
|
+
service_name="service-1",
|
|
19
|
+
),
|
|
20
|
+
)
|
|
21
|
+
self.response = Mock(ok=True)
|
|
22
|
+
self.response.json.return_value = {"code": "SUCCESS"}
|
|
23
|
+
self.manager.api.http_upload.return_value = self.response
|
|
24
|
+
|
|
25
|
+
def test_result_upload_always_sends_token_with_options(self):
|
|
26
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
27
|
+
file_path = Path(directory) / "result.csv"
|
|
28
|
+
file_path.write_text("id\n1\n", encoding="utf-8")
|
|
29
|
+
|
|
30
|
+
self.manager.service_upload_result(
|
|
31
|
+
self.service,
|
|
32
|
+
str(file_path),
|
|
33
|
+
{"is_realtime": True, "is_priority": False},
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
self.manager.api.http_upload.assert_called_once_with(
|
|
37
|
+
self.service.request.response_api,
|
|
38
|
+
str(file_path),
|
|
39
|
+
{
|
|
40
|
+
"token": "token-1",
|
|
41
|
+
"is_realtime": "true",
|
|
42
|
+
"is_priority": "false",
|
|
43
|
+
},
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def test_result_upload_sends_token_without_options(self):
|
|
47
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
48
|
+
file_path = Path(directory) / "result.csv"
|
|
49
|
+
file_path.write_text("id\n1\n", encoding="utf-8")
|
|
50
|
+
|
|
51
|
+
self.manager.service_upload_result(self.service, str(file_path))
|
|
52
|
+
|
|
53
|
+
self.manager.api.http_upload.assert_called_once_with(
|
|
54
|
+
self.service.request.response_api,
|
|
55
|
+
str(file_path),
|
|
56
|
+
{"token": "token-1"},
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if __name__ == "__main__":
|
|
61
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|