Skip to content

Commit 3ee0c88

Browse files
authored
Pass instanceId via query_string in upload tests (#1500)
## Summary - Use Flask `test_client` `query_string={"instanceId": ...}` for local upload integration tests instead of `f"...?instanceId=..."` URLs. - Updates `make_report` fixture docstring to match. Closes #1501. ## Why Aligns with the preferred testing pattern (proper query encoding, no ad-hoc URL concatenation). ## Testing - [x] `pnpm flask:test -- backend/ttnn_visualizer/tests/test_file_uploads.py` Made with [Cursor](https://cursor.com)
2 parents dfc0b71 + 0790dfa commit 3ee0c88

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

backend/ttnn_visualizer/tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ def make_report(app):
6565
``make_report()`` call produces an empty database with the default schema.
6666
6767
The inner function registers the database as a profiler instance and
68-
returns the ``instance_id`` string to pass as ``?instanceId=`` in API
69-
requests. All temporary files are removed automatically after the test.
68+
returns the ``instance_id`` string to pass as the ``instanceId`` query parameter
69+
in API requests (e.g. ``query_string={"instanceId": instance_id}``). All
70+
temporary files are removed automatically after the test.
7071
"""
7172
paths = []
7273
counter = [0]

backend/ttnn_visualizer/tests/test_file_uploads.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def test_mlir_upload_traversal_does_not_escape_target_directory(
310310
"""
311311
# The handler calls `update_instance(instance_id=...)` and requires a row
312312
# to update, so provision one via the standard `make_report` fixture and
313-
# thread its id through the `?instanceId=` query param.
313+
# thread its id through the `instanceId` query param.
314314
instance_id = make_report()
315315

316316
# The shared `conftest.app` fixture sets `LOCAL_DATA_DIRECTORY` as a
@@ -326,7 +326,8 @@ def test_mlir_upload_traversal_does_not_escape_target_directory(
326326
"files": (BytesIO(b"{}"), "../escape.json"),
327327
}
328328
response = client.post(
329-
f"/api/local/upload/mlir?instanceId={instance_id}",
329+
"/api/local/upload/mlir",
330+
query_string={"instanceId": instance_id},
330331
data=payload,
331332
content_type="multipart/form-data",
332333
)
@@ -364,7 +365,8 @@ def test_mlir_upload_forbidden_when_server_mode(app, client, make_report):
364365
assert app.config["SERVER_MODE"] is True
365366

366367
response = client.post(
367-
f"/api/local/upload/mlir?instanceId={instance_id}",
368+
"/api/local/upload/mlir",
369+
query_string={"instanceId": instance_id},
368370
data={"files": (BytesIO(b"{}"), "model.json")},
369371
content_type="multipart/form-data",
370372
)
@@ -393,7 +395,8 @@ def test_mlir_upload_invokes_configured_malware_scanner(app, client, make_report
393395
"ttnn_visualizer.file_uploads.subprocess.run", return_value=mock_result
394396
) as mock_run:
395397
response = client.post(
396-
f"/api/local/upload/mlir?instanceId={instance_id}",
398+
"/api/local/upload/mlir",
399+
query_string={"instanceId": instance_id},
397400
data={"files": (BytesIO(b'{"x": 1}'), "model.json")},
398401
content_type="multipart/form-data",
399402
)
@@ -423,7 +426,8 @@ def test_mlir_upload_malware_scanner_positive_blocks_save(app, client, make_repo
423426

424427
with patch("ttnn_visualizer.file_uploads.subprocess.run", return_value=mock_result):
425428
response = client.post(
426-
f"/api/local/upload/mlir?instanceId={instance_id}",
429+
"/api/local/upload/mlir",
430+
query_string={"instanceId": instance_id},
427431
data={"files": (BytesIO(b"{}"), "bad.json")},
428432
content_type="multipart/form-data",
429433
)
@@ -455,7 +459,8 @@ def test_profiler_upload_chromium_style_lands_under_report_folder(
455459
).resolve()
456460

457461
response = client.post(
458-
f"/api/local/upload/profiler?instanceId={instance_id}",
462+
"/api/local/upload/profiler",
463+
query_string={"instanceId": instance_id},
459464
data={
460465
"files": [
461466
(BytesIO(b"sqlite-bytes"), "unique_name2/db.sqlite"),
@@ -495,7 +500,8 @@ def test_profiler_upload_safari_style_lands_under_report_folder(
495500
).resolve()
496501

497502
response = client.post(
498-
f"/api/local/upload/profiler?instanceId={instance_id}",
503+
"/api/local/upload/profiler",
504+
query_string={"instanceId": instance_id},
499505
data={
500506
"files": [
501507
(BytesIO(b"sqlite-bytes"), "db.sqlite"),
@@ -533,7 +539,8 @@ def test_profiler_upload_rejects_files_from_multiple_folders(app, client, make_r
533539
).resolve()
534540

535541
response = client.post(
536-
f"/api/local/upload/profiler?instanceId={instance_id}",
542+
"/api/local/upload/profiler",
543+
query_string={"instanceId": instance_id},
537544
data={
538545
"files": [
539546
(BytesIO(b"sqlite-bytes"), "reportA/db.sqlite"),
@@ -575,7 +582,8 @@ def test_performance_upload_chromium_style_lands_under_report_folder(
575582
).resolve()
576583

577584
response = client.post(
578-
f"/api/local/upload/performance?instanceId={instance_id}",
585+
"/api/local/upload/performance",
586+
query_string={"instanceId": instance_id},
579587
data={
580588
"files": [
581589
(BytesIO(b"csv,bytes\n"), "perf_run/profile_log_device.csv"),

0 commit comments

Comments
 (0)