prisma-api 0.3.3__tar.gz → 0.3.5__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.
- {prisma_api-0.3.3 → prisma_api-0.3.5}/PKG-INFO +1 -1
- {prisma_api-0.3.3 → prisma_api-0.3.5}/prisma_api/__init__.py +1 -1
- {prisma_api-0.3.3 → prisma_api-0.3.5}/prisma_api/prisma_api_v2.py +41 -4
- {prisma_api-0.3.3 → prisma_api-0.3.5}/prisma_api.egg-info/PKG-INFO +1 -1
- {prisma_api-0.3.3 → prisma_api-0.3.5}/pyproject.toml +1 -1
- {prisma_api-0.3.3 → prisma_api-0.3.5}/tests/test_prisma_api_v2.py +75 -2
- {prisma_api-0.3.3 → prisma_api-0.3.5}/LICENSE +0 -0
- {prisma_api-0.3.3 → prisma_api-0.3.5}/README.md +0 -0
- {prisma_api-0.3.3 → prisma_api-0.3.5}/prisma_api/config.py +0 -0
- {prisma_api-0.3.3 → prisma_api-0.3.5}/prisma_api/prisma_api.py +0 -0
- {prisma_api-0.3.3 → prisma_api-0.3.5}/prisma_api.egg-info/SOURCES.txt +0 -0
- {prisma_api-0.3.3 → prisma_api-0.3.5}/prisma_api.egg-info/dependency_links.txt +0 -0
- {prisma_api-0.3.3 → prisma_api-0.3.5}/prisma_api.egg-info/requires.txt +0 -0
- {prisma_api-0.3.3 → prisma_api-0.3.5}/prisma_api.egg-info/top_level.txt +0 -0
- {prisma_api-0.3.3 → prisma_api-0.3.5}/setup.cfg +0 -0
- {prisma_api-0.3.3 → prisma_api-0.3.5}/tests/test_prisma_api.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: prisma_api
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: A package for interacting with PrISMa Platform APIs. PrISMa is a holistic system for numerical synthesis and assessment of Metal-Organic Frameworks and their applications, for Direct Air Capture of CO2. For more information, see: https://prisma.hw.ac.uk.
|
|
5
5
|
Author-email: RCCS-CaptureTeam <team@prisma-platform.org>
|
|
6
6
|
License: GNUv3
|
|
@@ -132,13 +132,50 @@ class PrismaAPIv2:
|
|
|
132
132
|
"""
|
|
133
133
|
return self._get(f"/flowsheets/{name}/")
|
|
134
134
|
|
|
135
|
-
def get_flowsheet_bundle(self) -> dict:
|
|
135
|
+
def get_flowsheet_bundle(self, name: str = "dac_min") -> dict:
|
|
136
136
|
"""
|
|
137
|
-
GET /api/v2/flowsheets/
|
|
137
|
+
GET /api/v2/flowsheets/{name}/bundle/
|
|
138
138
|
|
|
139
|
-
Returns the bundled flowsheet payload for the
|
|
139
|
+
Returns the bundled flowsheet payload for the named object.
|
|
140
140
|
"""
|
|
141
|
-
return self._get("/flowsheets/
|
|
141
|
+
return self._get(f"/flowsheets/{name}/bundle/")
|
|
142
|
+
|
|
143
|
+
def upsert_flowsheets(
|
|
144
|
+
self,
|
|
145
|
+
flowsheets: pd.DataFrame | list[dict],
|
|
146
|
+
on_exists: str = "append",
|
|
147
|
+
appendix: str = "_v4",
|
|
148
|
+
) -> dict:
|
|
149
|
+
"""
|
|
150
|
+
PUT /api/v2/flowsheets/upsert/
|
|
151
|
+
|
|
152
|
+
Modes:
|
|
153
|
+
* append (default): ``?on_exists=append&appendix=<suffix>``
|
|
154
|
+
* overwrite: ``?on_exists=overwrite``
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
flowsheets: DataFrame or list of dict payload records.
|
|
158
|
+
on_exists: Conflict mode; one of ``'append'`` or ``'overwrite'``.
|
|
159
|
+
appendix: Suffix used only in append mode (default ``'_v4'``).
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
API response dict.
|
|
163
|
+
"""
|
|
164
|
+
if on_exists not in ("append", "overwrite"):
|
|
165
|
+
raise ValueError("on_exists must be 'append' or 'overwrite'")
|
|
166
|
+
|
|
167
|
+
records = (
|
|
168
|
+
flowsheets.to_dict(orient="records")
|
|
169
|
+
if isinstance(flowsheets, pd.DataFrame)
|
|
170
|
+
else flowsheets
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
if on_exists == "overwrite":
|
|
174
|
+
path = "/flowsheets/upsert/?on_exists=overwrite"
|
|
175
|
+
else:
|
|
176
|
+
path = f"/flowsheets/upsert/?on_exists=append&appendix={appendix}"
|
|
177
|
+
|
|
178
|
+
return self._put(path, records)
|
|
142
179
|
|
|
143
180
|
# ── Catalog ───────────────────────────────────────────────────────────────
|
|
144
181
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: prisma_api
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: A package for interacting with PrISMa Platform APIs. PrISMa is a holistic system for numerical synthesis and assessment of Metal-Organic Frameworks and their applications, for Direct Air Capture of CO2. For more information, see: https://prisma.hw.ac.uk.
|
|
5
5
|
Author-email: RCCS-CaptureTeam <team@prisma-platform.org>
|
|
6
6
|
License: GNUv3
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "prisma_api"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.5"
|
|
8
8
|
description = "A package for interacting with PrISMa Platform APIs. PrISMa is a holistic system for numerical synthesis and assessment of Metal-Organic Frameworks and their applications, for Direct Air Capture of CO2. For more information, see: https://prisma.hw.ac.uk."
|
|
9
9
|
authors = [
|
|
10
10
|
{name = "RCCS-CaptureTeam", email = "team@prisma-platform.org"}
|
|
@@ -10,6 +10,7 @@ live network access is required. Run with:
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
12
|
import json
|
|
13
|
+
import os
|
|
13
14
|
import pytest
|
|
14
15
|
import responses as resp_lib
|
|
15
16
|
from responses import matchers
|
|
@@ -1422,7 +1423,18 @@ def test_api_key_header_sent(api):
|
|
|
1422
1423
|
|
|
1423
1424
|
# ── Flowsheets ────────────────────────────────────────────────────────────────
|
|
1424
1425
|
|
|
1426
|
+
_UPSERT_FLOWSHEET_FIXTURE = "reference_data/prisma_v2/dac_min_2026-07-01.json"
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
def _load_upsert_flowsheet_payload() -> list[dict]:
|
|
1430
|
+
with open(_UPSERT_FLOWSHEET_FIXTURE, "r", encoding="utf-8") as f:
|
|
1431
|
+
return [json.load(f)]
|
|
1432
|
+
|
|
1425
1433
|
@resp_lib.activate
|
|
1434
|
+
@pytest.mark.skipif(
|
|
1435
|
+
os.getenv("CI", "").lower() == "true",
|
|
1436
|
+
reason="Offline development fixture test is disabled in CI",
|
|
1437
|
+
)
|
|
1426
1438
|
def test_get_flowsheet_matches_reference_fixture(api):
|
|
1427
1439
|
fixture_path = "reference_data/01-prisma-v2--flowsheets/dac_min_db.json"
|
|
1428
1440
|
with open(fixture_path, "r", encoding="utf-8") as f:
|
|
@@ -1430,7 +1442,7 @@ def test_get_flowsheet_matches_reference_fixture(api):
|
|
|
1430
1442
|
|
|
1431
1443
|
resp_lib.add(resp_lib.GET, f"{PROD_BASE}/flowsheets/dac_min/",
|
|
1432
1444
|
json=expected, status=200)
|
|
1433
|
-
result = api.get_flowsheet(
|
|
1445
|
+
result = api.get_flowsheet()
|
|
1434
1446
|
assert result == expected
|
|
1435
1447
|
|
|
1436
1448
|
|
|
@@ -1438,10 +1450,18 @@ def test_get_flowsheet_matches_reference_fixture(api):
|
|
|
1438
1450
|
def test_get_flowsheet_uses_dev_mode_base_url(dev_api):
|
|
1439
1451
|
resp_lib.add(resp_lib.GET, f"{dev_api._base_url()}/flowsheets/dac_min/",
|
|
1440
1452
|
json={"template_id": "dac_min"}, status=200)
|
|
1441
|
-
result = dev_api.get_flowsheet(
|
|
1453
|
+
result = dev_api.get_flowsheet()
|
|
1442
1454
|
assert result["template_id"] == "dac_min"
|
|
1443
1455
|
|
|
1444
1456
|
|
|
1457
|
+
@resp_lib.activate
|
|
1458
|
+
def test_get_flowsheet_custom_name_routes_path(api):
|
|
1459
|
+
resp_lib.add(resp_lib.GET, f"{PROD_BASE}/flowsheets/custom_case/",
|
|
1460
|
+
json={"template_id": "custom_case"}, status=200)
|
|
1461
|
+
result = api.get_flowsheet(name="custom_case")
|
|
1462
|
+
assert result["template_id"] == "custom_case"
|
|
1463
|
+
|
|
1464
|
+
|
|
1445
1465
|
@resp_lib.activate
|
|
1446
1466
|
def test_get_flowsheet_bundle_returns_dict(api):
|
|
1447
1467
|
expected = {"template_id": "dac_min", "bundle": {"nodes": [], "edges": []}}
|
|
@@ -1457,3 +1477,56 @@ def test_get_flowsheet_bundle_uses_dev_mode_base_url(dev_api):
|
|
|
1457
1477
|
json={"template_id": "dac_min"}, status=200)
|
|
1458
1478
|
result = dev_api.get_flowsheet_bundle()
|
|
1459
1479
|
assert result["template_id"] == "dac_min"
|
|
1480
|
+
|
|
1481
|
+
|
|
1482
|
+
@resp_lib.activate
|
|
1483
|
+
def test_get_flowsheet_bundle_custom_name_routes_path(api):
|
|
1484
|
+
resp_lib.add(resp_lib.GET, f"{PROD_BASE}/flowsheets/custom_case/bundle/",
|
|
1485
|
+
json={"template_id": "custom_case"}, status=200)
|
|
1486
|
+
result = api.get_flowsheet_bundle(name="custom_case")
|
|
1487
|
+
assert result["template_id"] == "custom_case"
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
@resp_lib.activate
|
|
1491
|
+
def test_upsert_flowsheets_default_append_mode(api):
|
|
1492
|
+
resp_lib.add(
|
|
1493
|
+
resp_lib.PUT,
|
|
1494
|
+
f"{PROD_BASE}/flowsheets/upsert/?on_exists=append&appendix=_v4",
|
|
1495
|
+
json={"created": 1, "updated": 0},
|
|
1496
|
+
status=200,
|
|
1497
|
+
)
|
|
1498
|
+
payload = _load_upsert_flowsheet_payload()
|
|
1499
|
+
result = api.upsert_flowsheets(payload)
|
|
1500
|
+
assert result["created"] == 1
|
|
1501
|
+
|
|
1502
|
+
|
|
1503
|
+
@resp_lib.activate
|
|
1504
|
+
def test_upsert_flowsheets_overwrite_mode(api):
|
|
1505
|
+
resp_lib.add(
|
|
1506
|
+
resp_lib.PUT,
|
|
1507
|
+
f"{PROD_BASE}/flowsheets/upsert/?on_exists=overwrite",
|
|
1508
|
+
json={"created": 0, "updated": 1},
|
|
1509
|
+
status=200,
|
|
1510
|
+
)
|
|
1511
|
+
payload = _load_upsert_flowsheet_payload()
|
|
1512
|
+
result = api.upsert_flowsheets(payload, on_exists="overwrite")
|
|
1513
|
+
assert result["updated"] == 1
|
|
1514
|
+
|
|
1515
|
+
|
|
1516
|
+
@resp_lib.activate
|
|
1517
|
+
def test_upsert_flowsheets_uses_dev_mode_base_url(dev_api):
|
|
1518
|
+
resp_lib.add(
|
|
1519
|
+
resp_lib.PUT,
|
|
1520
|
+
"http://localhost:8000/api/v2/flowsheets/upsert/?on_exists=append&appendix=_dev",
|
|
1521
|
+
json={"created": 1, "updated": 0},
|
|
1522
|
+
status=200,
|
|
1523
|
+
)
|
|
1524
|
+
payload = _load_upsert_flowsheet_payload()
|
|
1525
|
+
result = dev_api.upsert_flowsheets(payload, appendix="_dev")
|
|
1526
|
+
assert result["created"] == 1
|
|
1527
|
+
|
|
1528
|
+
|
|
1529
|
+
def test_upsert_flowsheets_rejects_invalid_on_exists(api):
|
|
1530
|
+
payload = _load_upsert_flowsheet_payload()
|
|
1531
|
+
with pytest.raises(ValueError):
|
|
1532
|
+
api.upsert_flowsheets(payload, on_exists="replace")
|
|
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
|