Skip to content

Commit df12fd0

Browse files
committed
Added specific test for handling multiple echem files
1 parent 4194b1f commit df12fd0

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

pydatalab/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ datalab-app-plugin-insitu = { git = "https://github.com/datalab-org/datalab-app-
137137
addopts = "--cov-report=term --cov-report=xml --cov ./src/pydatalab"
138138
filterwarnings = [
139139
"error",
140+
"ignore:.*Capacity columns are not equal, replacing with new capacity column calculated from current and time columns and renaming the old capacity column to Old Capacity:UserWarning",
140141
"ignore:.*np.bool8*:DeprecationWarning",
141142
"ignore::pytest.PytestUnraisableExceptionWarning",
142143
"ignore:.*JCAMP-DX key without value*:UserWarning",

pydatalab/tests/server/test_blocks.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,76 @@ def test_uvvis_block_lifecycle(admin_client, default_sample_dict, example_data_d
258258
assert web_block.get("errors") is None
259259

260260

261+
def test_echem_block_lifecycle(admin_client, default_sample_dict, example_data_dir):
262+
block_type = "cycle"
263+
264+
sample_id = f"test_sample_with_files-{block_type}-lifecycle"
265+
sample_data = default_sample_dict.copy()
266+
sample_data["item_id"] = sample_id
267+
268+
response = admin_client.post("/new-sample/", json=sample_data)
269+
assert response.status_code == 201
270+
assert response.json["status"] == "success"
271+
272+
response = admin_client.post(
273+
"/add-data-block/",
274+
json={
275+
"block_type": block_type,
276+
"item_id": sample_id,
277+
"index": 0,
278+
},
279+
)
280+
281+
assert response.status_code == 200, f"Failed to add {block_type} block: {response.json}"
282+
assert response.json["status"] == "success"
283+
284+
block_data = response.json["new_block_obj"]
285+
block_id = block_data["block_id"]
286+
287+
# Upload multiple echem files
288+
echem_folder = example_data_dir / "echem"
289+
example_files = list(echem_folder.glob("*.mpr"))[:2]
290+
print("example_files:", example_files)
291+
example_file_ids = []
292+
293+
for example_file in example_files:
294+
with open(example_file, "rb") as f:
295+
response = admin_client.post(
296+
"/upload-file/",
297+
buffered=True,
298+
content_type="multipart/form-data",
299+
data={
300+
"item_id": sample_id,
301+
"file": [(f, example_file.name)],
302+
"type": "application/octet-stream",
303+
"replace_file": "null",
304+
"relativePath": "null",
305+
},
306+
)
307+
assert response.status_code == 201, f"Failed to upload {example_file.name}"
308+
assert response.json["status"] == "success"
309+
file_ids = response.json["file_id"]
310+
example_file_ids.append(file_ids)
311+
312+
assert len(example_file_ids) == 2
313+
314+
# Update block with multiple file_ids
315+
response = admin_client.get(f"/get-item-data/{sample_id}")
316+
assert response.status_code == 200
317+
item_data = response.json["item_data"]
318+
block_data = item_data["blocks_obj"][block_id]
319+
block_data["file_ids"] = example_file_ids
320+
321+
response = admin_client.post("/update-block/", json={"block_data": block_data})
322+
assert response.status_code == 200
323+
web_block = response.json["new_block_data"]
324+
if "bokeh_plot_data" not in web_block:
325+
print("Block errors:", web_block.get("errors"))
326+
327+
assert "bokeh_plot_data" in web_block
328+
assert web_block.get("errors") is None
329+
330+
261331
def test_xrd_block_lifecycle(admin_client, default_sample_dict, example_data_dir):
262332
from pydatalab.apps.xrd import XRDBlock
263333

0 commit comments

Comments
 (0)