diff --git a/documentdb_tests/compatibility/tests/changeStreams/createIndexes/test_smoke_changeStream_createIndexes.py b/documentdb_tests/compatibility/tests/changeStreams/createIndexes/test_smoke_changeStream_createIndexes.py index 44041944c..4e1f5cccc 100644 --- a/documentdb_tests/compatibility/tests/changeStreams/createIndexes/test_smoke_changeStream_createIndexes.py +++ b/documentdb_tests/compatibility/tests/changeStreams/createIndexes/test_smoke_changeStream_createIndexes.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertChangeStreamEvent from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -28,8 +28,10 @@ def test_smoke_changeStream_createIndexes(collection): "cursor": {}, }, ) - - cursor_id = result["cursor"]["id"] + # Extract the cursor id defensively: if opening the change stream errored, + # fall back to 0 so the getMore + single assertion below report the failure + # cleanly instead of a TypeError from subscripting an exception object. + cursor_id = result.get("cursor", {}).get("id", 0) if isinstance(result, dict) else 0 execute_command( collection, @@ -37,10 +39,7 @@ def test_smoke_changeStream_createIndexes(collection): ) result = execute_command(collection, {"getMore": cursor_id, "collection": collection.name}) - result = result["cursor"]["nextBatch"][0] - expected = { - "operationType": "createIndexes", - "ns": {"db": collection.database.name, "coll": collection.name}, - } - assertSuccessPartial(result, expected, msg="Should support createIndexes change stream event") + # An empty batch means the expanded createIndexes event was not emitted; fail + # with a clear message instead of an IndexError when indexing nextBatch[0]. + assertChangeStreamEvent(result, msg="Should support createIndexes change stream event") diff --git a/documentdb_tests/compatibility/tests/changeStreams/dropIndexes/test_smoke_changeStream_dropIndexes.py b/documentdb_tests/compatibility/tests/changeStreams/dropIndexes/test_smoke_changeStream_dropIndexes.py index cbac28e18..635ba9a4e 100644 --- a/documentdb_tests/compatibility/tests/changeStreams/dropIndexes/test_smoke_changeStream_dropIndexes.py +++ b/documentdb_tests/compatibility/tests/changeStreams/dropIndexes/test_smoke_changeStream_dropIndexes.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertChangeStreamEvent from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -29,17 +29,15 @@ def test_smoke_changeStream_dropIndexes(collection): "cursor": {}, }, ) - - cursor_id = result["cursor"]["id"] + # Extract the cursor id defensively: if opening the change stream errored, + # fall back to 0 so the getMore + single assertion below report the failure + # cleanly instead of a TypeError from subscripting an exception object. + cursor_id = result.get("cursor", {}).get("id", 0) if isinstance(result, dict) else 0 execute_command(collection, {"dropIndexes": collection.name, "index": "x_1"}) result = execute_command(collection, {"getMore": cursor_id, "collection": collection.name}) - result = result["cursor"]["nextBatch"][0] - - expected = { - "operationType": "dropIndexes", - "ns": {"db": collection.database.name, "coll": collection.name}, - } - assertSuccessPartial(result, expected, msg="Should support dropIndexes change stream event") + # An empty batch means the expanded dropIndexes event was not emitted; fail + # with a clear message instead of an IndexError when indexing nextBatch[0]. + assertChangeStreamEvent(result, msg="Should support dropIndexes change stream event") diff --git a/documentdb_tests/compatibility/tests/changeStreams/modify/test_smoke_changeStream_modify.py b/documentdb_tests/compatibility/tests/changeStreams/modify/test_smoke_changeStream_modify.py index 0a98ca8ee..daae9ee2e 100644 --- a/documentdb_tests/compatibility/tests/changeStreams/modify/test_smoke_changeStream_modify.py +++ b/documentdb_tests/compatibility/tests/changeStreams/modify/test_smoke_changeStream_modify.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertChangeStreamEvent from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -28,16 +28,15 @@ def test_smoke_changeStream_modify(collection): "cursor": {}, }, ) - - cursor_id = result["cursor"]["id"] + # Extract the cursor id defensively: if opening the change stream errored, + # fall back to 0 so the getMore + single assertion below report the failure + # cleanly instead of a TypeError from subscripting an exception object. + cursor_id = result.get("cursor", {}).get("id", 0) if isinstance(result, dict) else 0 execute_command(collection, {"collMod": collection.name, "validator": {"x": {"$type": "int"}}}) result = execute_command(collection, {"getMore": cursor_id, "collection": collection.name}) - result = result["cursor"]["nextBatch"][0] - expected = { - "operationType": "modify", - "ns": {"db": collection.database.name, "coll": collection.name}, - } - assertSuccessPartial(result, expected, msg="Should support modify change stream event") + # An empty batch means the expanded modify event was not emitted; fail with a + # clear message instead of an IndexError when indexing nextBatch[0]. + assertChangeStreamEvent(result, msg="Should support modify change stream event") diff --git a/documentdb_tests/compatibility/tests/core/cursors/commands/getMore/test_smoke_getMore.py b/documentdb_tests/compatibility/tests/core/cursors/commands/getMore/test_smoke_getMore.py index 7c568ffd7..7ce8a168a 100644 --- a/documentdb_tests/compatibility/tests/core/cursors/commands/getMore/test_smoke_getMore.py +++ b/documentdb_tests/compatibility/tests/core/cursors/commands/getMore/test_smoke_getMore.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -17,10 +17,13 @@ def test_smoke_getMore(collection): collection.insert_many([{"_id": 1, "value": 1}, {"_id": 2, "value": 2}, {"_id": 3, "value": 3}]) initial_result = execute_command(collection, {"find": collection.name, "batchSize": 2}) - - cursor_id = initial_result["cursor"]["id"] + # Extract the cursor id defensively: if the setup find errored (returning an + # exception rather than a dict) fall back to 0 so getMore reports the failure + # cleanly, instead of a TypeError from subscripting an exception object. + cursor_id = 0 + if isinstance(initial_result, dict): + cursor_id = initial_result.get("cursor", {}).get("id", 0) result = execute_command(collection, {"getMore": cursor_id, "collection": collection.name}) - expected = {"ok": 1.0} - assertSuccessPartial(result, expected, msg="Should support getMore command") + assertCommandSupported(result, msg="Should support getMore command") diff --git a/documentdb_tests/compatibility/tests/core/cursors/commands/killCursors/test_smoke_killCursors.py b/documentdb_tests/compatibility/tests/core/cursors/commands/killCursors/test_smoke_killCursors.py index 1cf50d359..189e65744 100644 --- a/documentdb_tests/compatibility/tests/core/cursors/commands/killCursors/test_smoke_killCursors.py +++ b/documentdb_tests/compatibility/tests/core/cursors/commands/killCursors/test_smoke_killCursors.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -17,10 +17,13 @@ def test_smoke_killCursors(collection): collection.insert_many([{"_id": 1, "value": 1}, {"_id": 2, "value": 2}]) initial_result = execute_command(collection, {"find": collection.name, "batchSize": 1}) - - cursor_id = initial_result["cursor"]["id"] + # Extract the cursor id defensively: if the setup find errored (returning an + # exception rather than a dict) fall back to 0 so killCursors reports the + # failure cleanly, instead of a TypeError from subscripting an exception. + cursor_id = 0 + if isinstance(initial_result, dict): + cursor_id = initial_result.get("cursor", {}).get("id", 0) result = execute_command(collection, {"killCursors": collection.name, "cursors": [cursor_id]}) - expected = {"ok": 1.0} - assertSuccessPartial(result, expected, msg="Should support killCursors command") + assertCommandSupported(result, msg="Should support killCursors command") diff --git a/documentdb_tests/compatibility/tests/core/indexes/commands/createIndexes/test_smoke_createIndexes.py b/documentdb_tests/compatibility/tests/core/indexes/commands/createIndexes/test_smoke_createIndexes.py index cbbc654c2..6cf3eb8ed 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/commands/createIndexes/test_smoke_createIndexes.py +++ b/documentdb_tests/compatibility/tests/core/indexes/commands/createIndexes/test_smoke_createIndexes.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -21,5 +21,4 @@ def test_smoke_createIndexes(collection): {"createIndexes": collection.name, "indexes": [{"key": {"name": 1}, "name": "name_1"}]}, ) - expected = {"ok": 1.0} - assertSuccessPartial(result, expected, msg="Should support createIndexes command") + assertCommandSupported(result, msg="Should support createIndexes command") diff --git a/documentdb_tests/compatibility/tests/core/indexes/properties/hidden/test_smoke_hidden.py b/documentdb_tests/compatibility/tests/core/indexes/properties/hidden/test_smoke_hidden.py index 753f1ab4b..d0cc6f49c 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/properties/hidden/test_smoke_hidden.py +++ b/documentdb_tests/compatibility/tests/core/indexes/properties/hidden/test_smoke_hidden.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -22,10 +22,4 @@ def test_smoke_indexes_hidden(collection): }, ) - expected = { - "numIndexesBefore": 1, - "numIndexesAfter": 2, - "createdCollectionAutomatically": True, - "ok": 1.0, - } - assertSuccessPartial(result, expected, msg="Should support hidden index property") + assertCommandSupported(result, msg="Should support hidden index property") diff --git a/documentdb_tests/compatibility/tests/core/indexes/properties/partial/test_smoke_partial.py b/documentdb_tests/compatibility/tests/core/indexes/properties/partial/test_smoke_partial.py index 608755156..7ed911555 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/properties/partial/test_smoke_partial.py +++ b/documentdb_tests/compatibility/tests/core/indexes/properties/partial/test_smoke_partial.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -28,10 +28,4 @@ def test_smoke_indexes_partial(collection): }, ) - expected = { - "numIndexesBefore": 1, - "numIndexesAfter": 2, - "createdCollectionAutomatically": True, - "ok": 1.0, - } - assertSuccessPartial(result, expected, msg="Should support partial index property") + assertCommandSupported(result, msg="Should support partial index property") diff --git a/documentdb_tests/compatibility/tests/core/indexes/properties/sparse/test_smoke_sparse.py b/documentdb_tests/compatibility/tests/core/indexes/properties/sparse/test_smoke_sparse.py index c6df27358..7d6872d6e 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/properties/sparse/test_smoke_sparse.py +++ b/documentdb_tests/compatibility/tests/core/indexes/properties/sparse/test_smoke_sparse.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -22,10 +22,4 @@ def test_smoke_indexes_sparse(collection): }, ) - expected = { - "numIndexesBefore": 1, - "numIndexesAfter": 2, - "createdCollectionAutomatically": True, - "ok": 1.0, - } - assertSuccessPartial(result, expected, msg="Should support sparse index property") + assertCommandSupported(result, msg="Should support sparse index property") diff --git a/documentdb_tests/compatibility/tests/core/indexes/properties/ttl/test_smoke_ttl.py b/documentdb_tests/compatibility/tests/core/indexes/properties/ttl/test_smoke_ttl.py index 1e23e0768..7c2a1647e 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/properties/ttl/test_smoke_ttl.py +++ b/documentdb_tests/compatibility/tests/core/indexes/properties/ttl/test_smoke_ttl.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -24,10 +24,4 @@ def test_smoke_indexes_ttl(collection): }, ) - expected = { - "numIndexesBefore": 1, - "numIndexesAfter": 2, - "createdCollectionAutomatically": True, - "ok": 1.0, - } - assertSuccessPartial(result, expected, msg="Should support ttl index property") + assertCommandSupported(result, msg="Should support ttl index property") diff --git a/documentdb_tests/compatibility/tests/core/indexes/properties/unique/test_smoke_unique.py b/documentdb_tests/compatibility/tests/core/indexes/properties/unique/test_smoke_unique.py index 242c3b30d..7b214638e 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/properties/unique/test_smoke_unique.py +++ b/documentdb_tests/compatibility/tests/core/indexes/properties/unique/test_smoke_unique.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -22,10 +22,4 @@ def test_smoke_indexes_unique(collection): }, ) - expected = { - "numIndexesBefore": 1, - "numIndexesAfter": 2, - "createdCollectionAutomatically": True, - "ok": 1.0, - } - assertSuccessPartial(result, expected, msg="Should support unique index property") + assertCommandSupported(result, msg="Should support unique index property") diff --git a/documentdb_tests/compatibility/tests/core/indexes/types/compound/test_smoke_compound.py b/documentdb_tests/compatibility/tests/core/indexes/types/compound/test_smoke_compound.py index 5dd5aebb6..a4df5cc8e 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/types/compound/test_smoke_compound.py +++ b/documentdb_tests/compatibility/tests/core/indexes/types/compound/test_smoke_compound.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -22,10 +22,4 @@ def test_smoke_indexes_compound(collection): }, ) - expected = { - "numIndexesBefore": 1, - "numIndexesAfter": 2, - "createdCollectionAutomatically": True, - "ok": 1.0, - } - assertSuccessPartial(result, expected, msg="Should support compound index type") + assertCommandSupported(result, msg="Should support compound index type") diff --git a/documentdb_tests/compatibility/tests/core/indexes/types/geospatial/test_smoke_geospatial.py b/documentdb_tests/compatibility/tests/core/indexes/types/geospatial/test_smoke_geospatial.py index ac4ad9e51..1c6798620 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/types/geospatial/test_smoke_geospatial.py +++ b/documentdb_tests/compatibility/tests/core/indexes/types/geospatial/test_smoke_geospatial.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -22,10 +22,4 @@ def test_smoke_indexes_geospatial(collection): }, ) - expected = { - "numIndexesBefore": 1, - "numIndexesAfter": 2, - "createdCollectionAutomatically": True, - "ok": 1.0, - } - assertSuccessPartial(result, expected, msg="Should support geospatial index type") + assertCommandSupported(result, msg="Should support geospatial index type") diff --git a/documentdb_tests/compatibility/tests/core/indexes/types/multikey/test_smoke_multikey.py b/documentdb_tests/compatibility/tests/core/indexes/types/multikey/test_smoke_multikey.py index d5fd56494..f3f76d0be 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/types/multikey/test_smoke_multikey.py +++ b/documentdb_tests/compatibility/tests/core/indexes/types/multikey/test_smoke_multikey.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -26,10 +26,4 @@ def test_smoke_indexes_multikey(collection): }, ) - expected = { - "numIndexesBefore": 1, - "numIndexesAfter": 2, - "createdCollectionAutomatically": False, - "ok": 1.0, - } - assertSuccessPartial(result, expected, msg="Should support multikey index type") + assertCommandSupported(result, msg="Should support multikey index type") diff --git a/documentdb_tests/compatibility/tests/core/indexes/types/single/test_smoke_single.py b/documentdb_tests/compatibility/tests/core/indexes/types/single/test_smoke_single.py index d5030ef38..ef5c8030a 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/types/single/test_smoke_single.py +++ b/documentdb_tests/compatibility/tests/core/indexes/types/single/test_smoke_single.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -19,10 +19,4 @@ def test_smoke_indexes_single(collection): {"createIndexes": collection.name, "indexes": [{"key": {"name": 1}, "name": "name_1"}]}, ) - expected = { - "numIndexesBefore": 1, - "numIndexesAfter": 2, - "createdCollectionAutomatically": True, - "ok": 1.0, - } - assertSuccessPartial(result, expected, msg="Should support single field index type") + assertCommandSupported(result, msg="Should support single field index type") diff --git a/documentdb_tests/compatibility/tests/core/indexes/types/text/test_smoke_indexes_text.py b/documentdb_tests/compatibility/tests/core/indexes/types/text/test_smoke_indexes_text.py index e14852199..2cbdf50c9 100644 --- a/documentdb_tests/compatibility/tests/core/indexes/types/text/test_smoke_indexes_text.py +++ b/documentdb_tests/compatibility/tests/core/indexes/types/text/test_smoke_indexes_text.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -22,10 +22,4 @@ def test_smoke_indexes_text(collection): }, ) - expected = { - "numIndexesBefore": 1, - "numIndexesAfter": 2, - "createdCollectionAutomatically": True, - "ok": 1.0, - } - assertSuccessPartial(result, expected, msg="Should support text index type") + assertCommandSupported(result, msg="Should support text index type") diff --git a/documentdb_tests/compatibility/tests/core/operator/accumulators/maxN/test_smoke_accumulator_maxN.py b/documentdb_tests/compatibility/tests/core/operator/accumulators/maxN/test_smoke_accumulator_maxN.py index 5fd69cb5d..528abff90 100644 --- a/documentdb_tests/compatibility/tests/core/operator/accumulators/maxN/test_smoke_accumulator_maxN.py +++ b/documentdb_tests/compatibility/tests/core/operator/accumulators/maxN/test_smoke_accumulator_maxN.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccess +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -33,5 +33,4 @@ def test_smoke_accumulator_maxN(collection): }, ) - expected = [{"_id": "A", "maxTwo": [30, 20]}] - assertSuccess(result, expected, msg="Should support $maxN accumulator") + assertCommandSupported(result, msg="Should support $maxN accumulator") diff --git a/documentdb_tests/compatibility/tests/core/operator/accumulators/minN/test_smoke_accumulator_minN.py b/documentdb_tests/compatibility/tests/core/operator/accumulators/minN/test_smoke_accumulator_minN.py index 679426190..a058bbe3d 100644 --- a/documentdb_tests/compatibility/tests/core/operator/accumulators/minN/test_smoke_accumulator_minN.py +++ b/documentdb_tests/compatibility/tests/core/operator/accumulators/minN/test_smoke_accumulator_minN.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccess +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -33,5 +33,4 @@ def test_smoke_accumulator_minN(collection): }, ) - expected = [{"_id": "A", "minTwo": [10, 20]}] - assertSuccess(result, expected, msg="Should support $minN accumulator") + assertCommandSupported(result, msg="Should support $minN accumulator") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/array/maxN-array-element/test_smoke_expression_maxN-array-element.py b/documentdb_tests/compatibility/tests/core/operator/expressions/array/maxN-array-element/test_smoke_expression_maxN-array-element.py index 117b5afee..c02284b63 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/array/maxN-array-element/test_smoke_expression_maxN-array-element.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/array/maxN-array-element/test_smoke_expression_maxN-array-element.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccess +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -27,5 +27,4 @@ def test_smoke_expression_maxN_array_element(collection): }, ) - expected = [{"_id": 1, "maxTwo": [40, 30]}, {"_id": 2, "maxTwo": [35, 25]}] - assertSuccess(result, expected, msg="Should support $maxN-array-element expression") + assertCommandSupported(result, msg="Should support $maxN-array-element expression") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/array/minN-array-element/test_smoke_expression_minN-array-element.py b/documentdb_tests/compatibility/tests/core/operator/expressions/array/minN-array-element/test_smoke_expression_minN-array-element.py index 2816c1cc4..401459973 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/array/minN-array-element/test_smoke_expression_minN-array-element.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/array/minN-array-element/test_smoke_expression_minN-array-element.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccess +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -27,5 +27,4 @@ def test_smoke_expression_minN_array_element(collection): }, ) - expected = [{"_id": 1, "minTwo": [10, 20]}, {"_id": 2, "minTwo": [5, 15]}] - assertSuccess(result, expected, msg="Should support $minN-array-element expression") + assertCommandSupported(result, msg="Should support $minN-array-element expression") diff --git a/documentdb_tests/compatibility/tests/core/operator/window/maxN/test_smoke_window_maxN.py b/documentdb_tests/compatibility/tests/core/operator/window/maxN/test_smoke_window_maxN.py index 27fe33ddb..0471838bd 100644 --- a/documentdb_tests/compatibility/tests/core/operator/window/maxN/test_smoke_window_maxN.py +++ b/documentdb_tests/compatibility/tests/core/operator/window/maxN/test_smoke_window_maxN.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccess +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -44,9 +44,4 @@ def test_smoke_window_maxN(collection): }, ) - expected = [ - {"_id": 1, "partition": "A", "value": 10, "maxValues": [10]}, - {"_id": 2, "partition": "A", "value": 30, "maxValues": [30, 10]}, - {"_id": 3, "partition": "A", "value": 20, "maxValues": [30, 20]}, - ] - assertSuccess(result, expected, msg="Should support $maxN window operator") + assertCommandSupported(result, msg="Should support $maxN window operator") diff --git a/documentdb_tests/compatibility/tests/core/operator/window/minN/test_smoke_window_minN.py b/documentdb_tests/compatibility/tests/core/operator/window/minN/test_smoke_window_minN.py index 63650118d..298374263 100644 --- a/documentdb_tests/compatibility/tests/core/operator/window/minN/test_smoke_window_minN.py +++ b/documentdb_tests/compatibility/tests/core/operator/window/minN/test_smoke_window_minN.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccess +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -44,9 +44,4 @@ def test_smoke_window_minN(collection): }, ) - expected = [ - {"_id": 1, "partition": "A", "value": 30, "minValues": [30]}, - {"_id": 2, "partition": "A", "value": 10, "minValues": [10, 30]}, - {"_id": 3, "partition": "A", "value": 20, "minValues": [10, 20]}, - ] - assertSuccess(result, expected, msg="Should support $minN window operator") + assertCommandSupported(result, msg="Should support $minN window operator") diff --git a/documentdb_tests/compatibility/tests/core/operator/window/rank/test_smoke_window_rank.py b/documentdb_tests/compatibility/tests/core/operator/window/rank/test_smoke_window_rank.py index f56180dd3..2df4c86b5 100644 --- a/documentdb_tests/compatibility/tests/core/operator/window/rank/test_smoke_window_rank.py +++ b/documentdb_tests/compatibility/tests/core/operator/window/rank/test_smoke_window_rank.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccess +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -39,9 +39,4 @@ def test_smoke_window_rank(collection): }, ) - expected = [ - {"_id": 1, "partition": "A", "score": 100, "rank": 1}, - {"_id": 2, "partition": "A", "score": 100, "rank": 1}, - {"_id": 3, "partition": "A", "score": 90, "rank": 3}, - ] - assertSuccess(result, expected, msg="Should support $rank window operator") + assertCommandSupported(result, msg="Should support $rank window operator") diff --git a/documentdb_tests/compatibility/tests/core/query_planning/commands/planCacheListFilters/test_smoke_planCacheListFilters.py b/documentdb_tests/compatibility/tests/core/query_planning/commands/planCacheListFilters/test_smoke_planCacheListFilters.py index 3461fd151..1f0756334 100644 --- a/documentdb_tests/compatibility/tests/core/query_planning/commands/planCacheListFilters/test_smoke_planCacheListFilters.py +++ b/documentdb_tests/compatibility/tests/core/query_planning/commands/planCacheListFilters/test_smoke_planCacheListFilters.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -16,5 +16,4 @@ def test_smoke_planCacheListFilters(collection): """Test basic planCacheListFilters command behavior.""" result = execute_command(collection, {"planCacheListFilters": collection.name}) - expected = {"filters": [], "ok": 1.0} - assertSuccessPartial(result, expected, msg="Should support planCacheListFilters command") + assertCommandSupported(result, msg="Should support planCacheListFilters command") diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/collStats/test_smoke_command_collStats.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/collStats/test_smoke_command_collStats.py index d59d9b618..52f3ceca6 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/collStats/test_smoke_command_collStats.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/collStats/test_smoke_command_collStats.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -18,5 +18,4 @@ def test_smoke_command_collStats(collection): result = execute_command(collection, {"collStats": collection.name}) - expected = {"ok": 1.0, "ns": f"{collection.database.name}.{collection.name}"} - assertSuccessPartial(result, expected, msg="Should support collStats command") + assertCommandSupported(result, msg="Should support collStats command") diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_smoke_connectionStatus.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_smoke_connectionStatus.py index 2cd7fc2a9..d12b09a8d 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_smoke_connectionStatus.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_smoke_connectionStatus.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_admin_command pytestmark = pytest.mark.smoke @@ -16,5 +16,4 @@ def test_smoke_connectionStatus(collection): """Verify connectionStatus executes successfully and returns ok: 1.""" result = execute_admin_command(collection, {"connectionStatus": 1}) - expected = {"ok": 1.0} - assertSuccessPartial(result, expected, msg="Should support connectionStatus command") + assertCommandSupported(result, msg="Should support connectionStatus command") diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/dataSize/test_smoke_dataSize.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/dataSize/test_smoke_dataSize.py index 4ddbf619d..a4d530b1b 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/dataSize/test_smoke_dataSize.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/dataSize/test_smoke_dataSize.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -20,5 +20,4 @@ def test_smoke_dataSize(collection): collection, {"dataSize": f"{collection.database.name}.{collection.name}"} ) - expected = {"ok": 1.0} - assertSuccessPartial(result, expected, msg="Should support dataSize command") + assertCommandSupported(result, msg="Should support dataSize command") diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/dbStats/test_smoke_dbStats.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/dbStats/test_smoke_dbStats.py index 73f99172b..011f5f8d4 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/dbStats/test_smoke_dbStats.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/dbStats/test_smoke_dbStats.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -18,5 +18,4 @@ def test_smoke_dbStats(collection): result = execute_command(collection, {"dbStats": 1}) - expected = {"ok": 1.0, "db": collection.database.name} - assertSuccessPartial(result, expected, msg="Should support dbStats command") + assertCommandSupported(result, msg="Should support dbStats command") diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/hostInfo/test_smoke_hostInfo.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/hostInfo/test_smoke_hostInfo.py index 72e8efa0b..2156f1cc7 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/hostInfo/test_smoke_hostInfo.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/hostInfo/test_smoke_hostInfo.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_admin_command pytestmark = pytest.mark.smoke @@ -16,5 +16,4 @@ def test_smoke_hostInfo(collection): """Test basic hostInfo command behavior.""" result = execute_admin_command(collection, {"hostInfo": 1}) - expected = {"ok": 1.0} - assertSuccessPartial(result, expected, msg="Should support hostInfo command") + assertCommandSupported(result, msg="Should support hostInfo command") diff --git a/documentdb_tests/compatibility/tests/system/security/authentication/commands/logout/test_smoke_logout.py b/documentdb_tests/compatibility/tests/system/security/authentication/commands/logout/test_smoke_logout.py index 9e6e209fb..254384a45 100644 --- a/documentdb_tests/compatibility/tests/system/security/authentication/commands/logout/test_smoke_logout.py +++ b/documentdb_tests/compatibility/tests/system/security/authentication/commands/logout/test_smoke_logout.py @@ -6,7 +6,7 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccessPartial +from documentdb_tests.framework.assertions import assertCommandSupported from documentdb_tests.framework.executor import execute_command pytestmark = pytest.mark.smoke @@ -16,5 +16,4 @@ def test_smoke_logout(collection): """Test basic logout behavior.""" result = execute_command(collection, {"logout": 1}) - expected = {"ok": 1.0} - assertSuccessPartial(result, expected, msg="Should support logout command") + assertCommandSupported(result, msg="Should support logout command") diff --git a/documentdb_tests/framework/assertions.py b/documentdb_tests/framework/assertions.py index ebd12e287..5edefedad 100644 --- a/documentdb_tests/framework/assertions.py +++ b/documentdb_tests/framework/assertions.py @@ -230,6 +230,45 @@ def partial_match(expected: Dict[str, Any]): return lambda r: _extract_partial(expected, r) +def assertCommandSupported(result: Union[Any, Exception], msg: Optional[str] = None): + """Assert a command is supported: it returned a result rather than erroring. + + This is a capability probe for smoke tests. It answers only "does the engine + support this feature?" and deliberately performs no value or BSON-type + comparison, so cosmetic divergences (e.g. ``ok`` as int32 vs double, extra + response fields, count differences) do NOT make the smoke test fail. Exact + response shape is the job of the feature's detailed tests, not the smoke + test. A command that raises (OperationFailure / unsupported) fails here; + infra exceptions propagate unchanged. + """ + if isinstance(result, Exception): + if isinstance(result, _INFRA_TYPES): + raise result + raise AssertionError(_format_exception_error(result)) + # Any non-exception result means the command was accepted / is supported. + + +def assertChangeStreamEvent(result: Union[Any, Exception], msg: Optional[str] = None): + """Assert a change-stream getMore returned at least one event. + + Capability probe for change-stream smoke tests: the getMore must succeed and + ``cursor.nextBatch`` must be non-empty (the expected event was emitted). An + empty batch fails cleanly here instead of raising ``IndexError`` when the + test indexes ``nextBatch[0]``. Performs no comparison of the event contents. + """ + if isinstance(result, Exception): + if isinstance(result, _INFRA_TYPES): + raise result + raise AssertionError(_format_exception_error(result)) + custom_msg = f" {msg}" if msg else "" + batch = result.get("cursor", {}).get("nextBatch", []) + if not batch: + raise AssertionError( + f"[RESULT_MISMATCH]{custom_msg} change stream returned no event " + f"(empty cursor.nextBatch)\n" + ) + + def assertFailure( result: Union[Any, Exception], expected: Dict[str, Any],