From f1e0165373cc8539462810fba093bd6993979900 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Mar 2026 12:19:18 +0000 Subject: [PATCH 1/2] Add unit tests for listDatasets without org_id to prevent regression The fix from 804dd90 correctly removed @validate_call from listDatasets (and createDataset/listAllDatasets), making org_id optional and resolved from client config. These unit tests verify the fix works and guard against regression. https://claude.ai/code/session_011B2Dj4a62UZAffje5gGero --- tests/test_cloud_api_datasets.py | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/test_cloud_api_datasets.py diff --git a/tests/test_cloud_api_datasets.py b/tests/test_cloud_api_datasets.py new file mode 100644 index 0000000..d6f308e --- /dev/null +++ b/tests/test_cloud_api_datasets.py @@ -0,0 +1,86 @@ +"""Unit tests for ndi.cloud.api.datasets — no network required.""" + +from __future__ import annotations + +from unittest.mock import MagicMock, patch + +import pytest + + +def _make_client(org_id: str = "org-123") -> MagicMock: + """Return a mock CloudClient with a config carrying *org_id*.""" + client = MagicMock() + client.config.org_id = org_id + client.config.api_url = "https://api.ndi-cloud.com/v1" + client.get.return_value = { + "datasets": [{"id": "ds-1", "name": "Test"}], + "totalNumber": 1, + } + return client + + +class TestListDatasets: + """listDatasets should work with or without an explicit org_id.""" + + def test_without_org_id_uses_client_config(self): + """Calling listDatasets() with no org_id should resolve it from client config.""" + from ndi.cloud.api.datasets import listDatasets + + client = _make_client(org_id="org-abc") + result = listDatasets(client=client) + + client.get.assert_called_once() + call_kwargs = client.get.call_args + assert call_kwargs.kwargs["organizationId"] == "org-abc" + assert result["datasets"][0]["name"] == "Test" + + def test_with_explicit_org_id(self): + """Passing org_id explicitly should use that value.""" + from ndi.cloud.api.datasets import listDatasets + + client = _make_client(org_id="org-abc") + listDatasets("org-explicit", client=client) + + call_kwargs = client.get.call_args + assert call_kwargs.kwargs["organizationId"] == "org-explicit" + + def test_no_org_id_and_no_config_raises(self): + """If org_id is omitted and client config has none, raise ValueError.""" + from ndi.cloud.api.datasets import listDatasets + + client = _make_client(org_id="") + with pytest.raises(ValueError, match="org_id is required"): + listDatasets(client=client) + + +class TestListAllDatasets: + """listAllDatasets should work without an explicit org_id.""" + + def test_without_org_id(self): + from ndi.cloud.api.datasets import listAllDatasets + + client = _make_client(org_id="org-abc") + result = listAllDatasets(client=client) + + assert len(result.data) == 1 + + +class TestCreateDataset: + """createDataset should work without an explicit org_id.""" + + def test_without_org_id(self): + from ndi.cloud.api.datasets import createDataset + + client = _make_client(org_id="org-abc") + client.post.return_value = {"id": "ds-new", "name": "NewDS"} + result = createDataset(name="NewDS", client=client) + + call_kwargs = client.post.call_args + assert call_kwargs.kwargs["organizationId"] == "org-abc" + + def test_without_org_id_and_no_config_raises(self): + from ndi.cloud.api.datasets import createDataset + + client = _make_client(org_id="") + with pytest.raises(ValueError, match="org_id is required"): + createDataset(name="NewDS", client=client) From 04f5fc30f6d0a022baafd067a07dc7c59571ee66 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Mar 2026 13:03:48 +0000 Subject: [PATCH 2/2] Fix lint errors: remove unused import and variable assignment https://claude.ai/code/session_011B2Dj4a62UZAffje5gGero --- tests/test_cloud_api_datasets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cloud_api_datasets.py b/tests/test_cloud_api_datasets.py index d6f308e..89dcc75 100644 --- a/tests/test_cloud_api_datasets.py +++ b/tests/test_cloud_api_datasets.py @@ -2,7 +2,7 @@ from __future__ import annotations -from unittest.mock import MagicMock, patch +from unittest.mock import MagicMock import pytest @@ -73,7 +73,7 @@ def test_without_org_id(self): client = _make_client(org_id="org-abc") client.post.return_value = {"id": "ds-new", "name": "NewDS"} - result = createDataset(name="NewDS", client=client) + createDataset(name="NewDS", client=client) call_kwargs = client.post.call_args assert call_kwargs.kwargs["organizationId"] == "org-abc"