Skip to content

Commit 99468db

Browse files
committed
feat(lab-4021): add unit tests
1 parent afb2e8a commit 99468db

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/unit/domain_api/test_assets.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def mock_client(self):
2828
client.change_asset_external_ids = MagicMock()
2929
client.add_metadata = MagicMock()
3030
client.set_metadata = MagicMock()
31+
client.update_asset_consensus = MagicMock()
3132
return client
3233

3334
@pytest.fixture()
@@ -232,6 +233,70 @@ def test_delete_assets(self, assets_namespace, mock_client):
232233
asset_ids=["asset1", "asset2"], external_ids=None, project_id=""
233234
)
234235

236+
def test_update_consensus_with_asset_id(self, assets_namespace, mock_client):
237+
"""Test update_consensus method with asset_id."""
238+
mock_client.update_asset_consensus.return_value = True
239+
240+
result = assets_namespace.update_consensus(
241+
project_id="project_123",
242+
asset_id="asset1",
243+
is_consensus=True,
244+
)
245+
246+
assert result is True
247+
mock_client.update_asset_consensus.assert_called_once_with(
248+
project_id="project_123",
249+
is_consensus=True,
250+
asset_id="asset1",
251+
external_id=None,
252+
)
253+
254+
def test_update_consensus_with_external_id(self, assets_namespace, mock_client):
255+
"""Test update_consensus method with external_id."""
256+
mock_client.update_asset_consensus.return_value = True
257+
258+
result = assets_namespace.update_consensus(
259+
project_id="project_123",
260+
external_id="ext_asset1",
261+
is_consensus=True,
262+
)
263+
264+
assert result is True
265+
mock_client.update_asset_consensus.assert_called_once_with(
266+
project_id="project_123",
267+
is_consensus=True,
268+
asset_id=None,
269+
external_id="ext_asset1",
270+
)
271+
272+
def test_update_consensus_deactivate(self, assets_namespace, mock_client):
273+
"""Test update_consensus method to deactivate consensus."""
274+
mock_client.update_asset_consensus.return_value = False
275+
276+
result = assets_namespace.update_consensus(
277+
project_id="project_123",
278+
asset_id="asset1",
279+
is_consensus=False,
280+
)
281+
282+
assert result is False
283+
mock_client.update_asset_consensus.assert_called_once_with(
284+
project_id="project_123",
285+
is_consensus=False,
286+
asset_id="asset1",
287+
external_id=None,
288+
)
289+
290+
def test_update_consensus_raises_without_identifiers(self, assets_namespace):
291+
"""Test update_consensus raises ValueError when neither asset_id nor external_id is provided."""
292+
with pytest.raises(
293+
ValueError, match="At least one of asset_id or external_id must be provided"
294+
):
295+
assets_namespace.update_consensus(
296+
project_id="project_123",
297+
is_consensus=True,
298+
)
299+
235300

236301
class TestAssetsNamespaceContractCompatibility:
237302
"""Contract tests to ensure domain API matches legacy API behavior."""

0 commit comments

Comments
 (0)