From eb675ce26d602fd6eb6d414e2195ca3388922526 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 17 Jun 2026 11:08:15 -0700 Subject: [PATCH 1/8] initial generated tests Signed-off-by: Alina (Xi) Li --- .../commands/whatsmyuri/__init__.py | 0 .../test_whatsmyuri_argument_handling.py | 144 ++++++++++++++++++ .../whatsmyuri/test_whatsmyuri_consistency.py | 49 ++++++ .../test_whatsmyuri_error_conditions.py | 44 ++++++ .../test_whatsmyuri_response_structure.py | 49 ++++++ 5 files changed, 286 insertions(+) create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/__init__.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/__init__.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py new file mode 100644 index 000000000..810c84aae --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py @@ -0,0 +1,144 @@ +"""Tests for whatsmyuri command argument handling. + +Validates that whatsmyuri accepts any BSON type as its argument value. +""" + +from datetime import datetime, timezone + +import pytest +from bson import Binary, Code, Decimal128, Int64, MaxKey, MinKey, ObjectId, Regex, Timestamp + +from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( + DiagnosticTestCase, +) +from documentdb_tests.framework.assertions import assertProperties +from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.property_checks import Eq + +pytestmark = pytest.mark.admin + + +ARGUMENT_TYPE_TESTS: list[DiagnosticTestCase] = [ + DiagnosticTestCase( + "int_1", command={"whatsmyuri": 1}, checks={"ok": Eq(1.0)}, msg="Should accept int 1" + ), + DiagnosticTestCase( + "int_0", command={"whatsmyuri": 0}, checks={"ok": Eq(1.0)}, msg="Should accept int 0" + ), + DiagnosticTestCase( + "int_neg1", command={"whatsmyuri": -1}, checks={"ok": Eq(1.0)}, msg="Should accept int -1" + ), + DiagnosticTestCase( + "bool_true", command={"whatsmyuri": True}, checks={"ok": Eq(1.0)}, msg="Should accept true" + ), + DiagnosticTestCase( + "bool_false", + command={"whatsmyuri": False}, + checks={"ok": Eq(1.0)}, + msg="Should accept false", + ), + DiagnosticTestCase( + "string", + command={"whatsmyuri": "hello"}, + checks={"ok": Eq(1.0)}, + msg="Should accept string", + ), + DiagnosticTestCase( + "null", command={"whatsmyuri": None}, checks={"ok": Eq(1.0)}, msg="Should accept null" + ), + DiagnosticTestCase( + "empty_object", + command={"whatsmyuri": {}}, + checks={"ok": Eq(1.0)}, + msg="Should accept empty object", + ), + DiagnosticTestCase( + "empty_array", + command={"whatsmyuri": []}, + checks={"ok": Eq(1.0)}, + msg="Should accept empty array", + ), + DiagnosticTestCase( + "double", command={"whatsmyuri": 1.5}, checks={"ok": Eq(1.0)}, msg="Should accept double" + ), + DiagnosticTestCase( + "int64", + command={"whatsmyuri": Int64(1)}, + checks={"ok": Eq(1.0)}, + msg="Should accept int64", + ), + DiagnosticTestCase( + "decimal128", + command={"whatsmyuri": Decimal128("1")}, + checks={"ok": Eq(1.0)}, + msg="Should accept decimal128", + ), + DiagnosticTestCase( + "decimal128_nan", + command={"whatsmyuri": Decimal128("NaN")}, + checks={"ok": Eq(1.0)}, + msg="Should accept decimal128 NaN", + ), + DiagnosticTestCase( + "infinity", + command={"whatsmyuri": float("inf")}, + checks={"ok": Eq(1.0)}, + msg="Should accept infinity", + ), + DiagnosticTestCase( + "date", + command={"whatsmyuri": datetime(2024, 1, 1, tzinfo=timezone.utc)}, + checks={"ok": Eq(1.0)}, + msg="Should accept date", + ), + DiagnosticTestCase( + "binData", + command={"whatsmyuri": Binary(b"")}, + checks={"ok": Eq(1.0)}, + msg="Should accept binData", + ), + DiagnosticTestCase( + "objectId", + command={"whatsmyuri": ObjectId()}, + checks={"ok": Eq(1.0)}, + msg="Should accept objectId", + ), + DiagnosticTestCase( + "regex", + command={"whatsmyuri": Regex("test")}, + checks={"ok": Eq(1.0)}, + msg="Should accept regex", + ), + DiagnosticTestCase( + "timestamp", + command={"whatsmyuri": Timestamp(0, 0)}, + checks={"ok": Eq(1.0)}, + msg="Should accept timestamp", + ), + DiagnosticTestCase( + "minKey", + command={"whatsmyuri": MinKey()}, + checks={"ok": Eq(1.0)}, + msg="Should accept minKey", + ), + DiagnosticTestCase( + "maxKey", + command={"whatsmyuri": MaxKey()}, + checks={"ok": Eq(1.0)}, + msg="Should accept maxKey", + ), + DiagnosticTestCase( + "code", + command={"whatsmyuri": Code("function(){}")}, + checks={"ok": Eq(1.0)}, + msg="Should accept JavaScript code", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ARGUMENT_TYPE_TESTS)) +def test_whatsmyuri_argument_types(collection, test): + """Test that whatsmyuri accepts various BSON types as argument value.""" + result = execute_admin_command(collection, test.command) + assertProperties(result, test.checks, msg=test.msg, raw_res=True) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py new file mode 100644 index 000000000..ec0ceb625 --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py @@ -0,0 +1,49 @@ +"""Tests for whatsmyuri command consistency and database independence. + +Validates that whatsmyuri returns consistent results across calls, +databases, and is unaffected by server settings. +""" + +import pytest + +from documentdb_tests.framework.assertions import assertSuccess, assertSuccessPartial +from documentdb_tests.framework.executor import execute_admin_command, execute_command + +pytestmark = pytest.mark.admin + + +def test_whatsmyuri_idempotent(collection): + """Test calling whatsmyuri multiple times returns identical results.""" + result1 = execute_admin_command(collection, {"whatsmyuri": 1}) + result2 = execute_admin_command(collection, {"whatsmyuri": 1}) + assertSuccess(result2, expected=result1, msg="Should return identical results", raw_res=True) + + +def test_whatsmyuri_any_database(collection): + """Test whatsmyuri can be run on any database (not just admin).""" + result = execute_command(collection, {"whatsmyuri": 1}) + assertSuccessPartial(result, {"ok": 1.0}, msg="Should succeed on non-admin db") + + +def test_whatsmyuri_same_result_any_database(collection): + """Test whatsmyuri returns same result from admin and non-admin database.""" + admin_result = execute_admin_command(collection, {"whatsmyuri": 1}) + db_result = execute_command(collection, {"whatsmyuri": 1}) + assertSuccess( + db_result, + expected=admin_result, + msg="Should return same result from any database", + raw_res=True, + ) + + +def test_whatsmyuri_nonexistent_database(collection): + """Test whatsmyuri succeeds on a non-existent database.""" + other_db = f"{collection.name}_nonexistent_db" + other_col = collection.database.client[other_db][collection.name] + result = execute_command(other_col, {"whatsmyuri": 1}) + assertSuccessPartial( + result, + {"ok": 1.0}, + msg="Should succeed on non-existent database", + ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py new file mode 100644 index 000000000..6a219d58b --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py @@ -0,0 +1,44 @@ +"""Tests for whatsmyuri command error conditions. + +Validates that invalid usages of whatsmyuri produce appropriate errors. +""" + +import pytest + +from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( + DiagnosticTestCase, +) +from documentdb_tests.framework.assertions import assertFailureCode +from documentdb_tests.framework.error_codes import ( + COMMAND_NOT_FOUND_ERROR, + UNRECOGNIZED_COMMAND_FIELD_ERROR, +) +from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.parametrize import pytest_params + +pytestmark = pytest.mark.admin + + +ERROR_TESTS: list[DiagnosticTestCase] = [ + DiagnosticTestCase( + id="case_sensitive", + command={"WhatsMyUri": 1}, + use_admin=True, + error_code=COMMAND_NOT_FOUND_ERROR, + msg="Case-mismatched command name should fail", + ), + DiagnosticTestCase( + id="unrecognized_field", + command={"whatsmyuri": 1, "unknownField": 1}, + use_admin=True, + error_code=UNRECOGNIZED_COMMAND_FIELD_ERROR, + msg="Should reject unrecognized fields", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ERROR_TESTS)) +def test_whatsmyuri_error_conditions(collection, test): + """Verify whatsmyuri rejects invalid usages with appropriate error codes.""" + result = execute_admin_command(collection, test.command) + assertFailureCode(result, test.error_code, msg=test.msg) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py new file mode 100644 index 000000000..9ec81d5b7 --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py @@ -0,0 +1,49 @@ +"""Tests for whatsmyuri command response structure. + +Validates presence, types, and values of response fields returned +by whatsmyuri. The response contains a 'you' field with the client's +connection URI (ip:port) and the standard 'ok' field. +""" + +import pytest + +from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( + DiagnosticTestCase, +) +from documentdb_tests.framework.assertions import assertProperties +from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.property_checks import Eq, Exists, IsType, NonEmptyStr + +pytestmark = pytest.mark.admin + + +PROPERTY_TESTS: list[DiagnosticTestCase] = [ + DiagnosticTestCase( + id="ok_is_1", + checks={"ok": Eq(1.0)}, + msg="'ok' field should be 1.0", + ), + DiagnosticTestCase( + id="you_exists", + checks={"you": Exists()}, + msg="'you' field should always exist", + ), + DiagnosticTestCase( + id="you_is_string", + checks={"you": IsType("string")}, + msg="'you' field should be a string", + ), + DiagnosticTestCase( + id="you_is_non_empty", + checks={"you": NonEmptyStr()}, + msg="'you' field should be a non-empty string containing the client URI", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(PROPERTY_TESTS)) +def test_whatsmyuri_response_properties(collection, test): + """Verify whatsmyuri response fields have expected types and values.""" + result = execute_admin_command(collection, {"whatsmyuri": 1}) + assertProperties(result, test.checks, msg=test.msg, raw_res=True) From 7fe5bf1b10a9c2d7e1124570776534f14120367d Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 17 Jun 2026 11:17:11 -0700 Subject: [PATCH 2/8] update according to style guide Signed-off-by: Alina (Xi) Li --- .../test_whatsmyuri_argument_handling.py | 65 ++++++++++++------- .../whatsmyuri/test_whatsmyuri_consistency.py | 19 ++++-- .../test_whatsmyuri_error_conditions.py | 40 +++++++----- .../test_whatsmyuri_response_structure.py | 11 ++-- 4 files changed, 85 insertions(+), 50 deletions(-) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py index 810c84aae..3a79f4320 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py @@ -19,126 +19,145 @@ pytestmark = pytest.mark.admin +# Property [Type Acceptance]: whatsmyuri accepts all BSON types as the command field value. ARGUMENT_TYPE_TESTS: list[DiagnosticTestCase] = [ DiagnosticTestCase( - "int_1", command={"whatsmyuri": 1}, checks={"ok": Eq(1.0)}, msg="Should accept int 1" + "int_1", + command={"whatsmyuri": 1}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept int 1", ), DiagnosticTestCase( - "int_0", command={"whatsmyuri": 0}, checks={"ok": Eq(1.0)}, msg="Should accept int 0" + "int_0", + command={"whatsmyuri": 0}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept int 0", ), DiagnosticTestCase( - "int_neg1", command={"whatsmyuri": -1}, checks={"ok": Eq(1.0)}, msg="Should accept int -1" + "int_neg1", + command={"whatsmyuri": -1}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept int -1", ), DiagnosticTestCase( - "bool_true", command={"whatsmyuri": True}, checks={"ok": Eq(1.0)}, msg="Should accept true" + "bool_true", + command={"whatsmyuri": True}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept true", ), DiagnosticTestCase( "bool_false", command={"whatsmyuri": False}, checks={"ok": Eq(1.0)}, - msg="Should accept false", + msg="whatsmyuri should accept false", ), DiagnosticTestCase( "string", command={"whatsmyuri": "hello"}, checks={"ok": Eq(1.0)}, - msg="Should accept string", + msg="whatsmyuri should accept string", ), DiagnosticTestCase( - "null", command={"whatsmyuri": None}, checks={"ok": Eq(1.0)}, msg="Should accept null" + "null", + command={"whatsmyuri": None}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept null", ), DiagnosticTestCase( "empty_object", command={"whatsmyuri": {}}, checks={"ok": Eq(1.0)}, - msg="Should accept empty object", + msg="whatsmyuri should accept empty object", ), DiagnosticTestCase( "empty_array", command={"whatsmyuri": []}, checks={"ok": Eq(1.0)}, - msg="Should accept empty array", + msg="whatsmyuri should accept empty array", ), DiagnosticTestCase( - "double", command={"whatsmyuri": 1.5}, checks={"ok": Eq(1.0)}, msg="Should accept double" + "double", + command={"whatsmyuri": 1.5}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept double", ), DiagnosticTestCase( "int64", command={"whatsmyuri": Int64(1)}, checks={"ok": Eq(1.0)}, - msg="Should accept int64", + msg="whatsmyuri should accept int64", ), DiagnosticTestCase( "decimal128", command={"whatsmyuri": Decimal128("1")}, checks={"ok": Eq(1.0)}, - msg="Should accept decimal128", + msg="whatsmyuri should accept decimal128", ), DiagnosticTestCase( "decimal128_nan", command={"whatsmyuri": Decimal128("NaN")}, checks={"ok": Eq(1.0)}, - msg="Should accept decimal128 NaN", + msg="whatsmyuri should accept decimal128 NaN", ), DiagnosticTestCase( "infinity", command={"whatsmyuri": float("inf")}, checks={"ok": Eq(1.0)}, - msg="Should accept infinity", + msg="whatsmyuri should accept infinity", ), DiagnosticTestCase( "date", command={"whatsmyuri": datetime(2024, 1, 1, tzinfo=timezone.utc)}, checks={"ok": Eq(1.0)}, - msg="Should accept date", + msg="whatsmyuri should accept date", ), DiagnosticTestCase( "binData", command={"whatsmyuri": Binary(b"")}, checks={"ok": Eq(1.0)}, - msg="Should accept binData", + msg="whatsmyuri should accept binData", ), DiagnosticTestCase( "objectId", command={"whatsmyuri": ObjectId()}, checks={"ok": Eq(1.0)}, - msg="Should accept objectId", + msg="whatsmyuri should accept objectId", ), DiagnosticTestCase( "regex", command={"whatsmyuri": Regex("test")}, checks={"ok": Eq(1.0)}, - msg="Should accept regex", + msg="whatsmyuri should accept regex", ), DiagnosticTestCase( "timestamp", command={"whatsmyuri": Timestamp(0, 0)}, checks={"ok": Eq(1.0)}, - msg="Should accept timestamp", + msg="whatsmyuri should accept timestamp", ), DiagnosticTestCase( "minKey", command={"whatsmyuri": MinKey()}, checks={"ok": Eq(1.0)}, - msg="Should accept minKey", + msg="whatsmyuri should accept minKey", ), DiagnosticTestCase( "maxKey", command={"whatsmyuri": MaxKey()}, checks={"ok": Eq(1.0)}, - msg="Should accept maxKey", + msg="whatsmyuri should accept maxKey", ), DiagnosticTestCase( "code", command={"whatsmyuri": Code("function(){}")}, checks={"ok": Eq(1.0)}, - msg="Should accept JavaScript code", + msg="whatsmyuri should accept JavaScript code", ), ] @pytest.mark.parametrize("test", pytest_params(ARGUMENT_TYPE_TESTS)) def test_whatsmyuri_argument_types(collection, test): - """Test that whatsmyuri accepts various BSON types as argument value.""" + """Test whatsmyuri argument type acceptance.""" result = execute_admin_command(collection, test.command) assertProperties(result, test.checks, msg=test.msg, raw_res=True) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py index ec0ceb625..93d667ca2 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py @@ -13,16 +13,21 @@ def test_whatsmyuri_idempotent(collection): - """Test calling whatsmyuri multiple times returns identical results.""" + """Test whatsmyuri idempotency.""" result1 = execute_admin_command(collection, {"whatsmyuri": 1}) result2 = execute_admin_command(collection, {"whatsmyuri": 1}) - assertSuccess(result2, expected=result1, msg="Should return identical results", raw_res=True) + assertSuccess( + result2, + expected=result1, + msg="whatsmyuri should return identical results across calls", + raw_res=True, + ) def test_whatsmyuri_any_database(collection): - """Test whatsmyuri can be run on any database (not just admin).""" + """Test whatsmyuri on a non-admin database.""" result = execute_command(collection, {"whatsmyuri": 1}) - assertSuccessPartial(result, {"ok": 1.0}, msg="Should succeed on non-admin db") + assertSuccessPartial(result, {"ok": 1.0}, msg="whatsmyuri should succeed on non-admin database") def test_whatsmyuri_same_result_any_database(collection): @@ -32,18 +37,18 @@ def test_whatsmyuri_same_result_any_database(collection): assertSuccess( db_result, expected=admin_result, - msg="Should return same result from any database", + msg="whatsmyuri should return same result from any database", raw_res=True, ) def test_whatsmyuri_nonexistent_database(collection): - """Test whatsmyuri succeeds on a non-existent database.""" + """Test whatsmyuri on a non-existent database.""" other_db = f"{collection.name}_nonexistent_db" other_col = collection.database.client[other_db][collection.name] result = execute_command(other_col, {"whatsmyuri": 1}) assertSuccessPartial( result, {"ok": 1.0}, - msg="Should succeed on non-existent database", + msg="whatsmyuri should succeed on non-existent database", ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py index 6a219d58b..4b766a8e8 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py @@ -8,37 +8,47 @@ from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( DiagnosticTestCase, ) -from documentdb_tests.framework.assertions import assertFailureCode -from documentdb_tests.framework.error_codes import ( - COMMAND_NOT_FOUND_ERROR, - UNRECOGNIZED_COMMAND_FIELD_ERROR, -) +from documentdb_tests.framework.assertions import assertFailureCode, assertProperties +from documentdb_tests.framework.error_codes import COMMAND_NOT_FOUND_ERROR from documentdb_tests.framework.executor import execute_admin_command from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.property_checks import Eq pytestmark = pytest.mark.admin -ERROR_TESTS: list[DiagnosticTestCase] = [ +# Property [Case Sensitivity]: whatsmyuri is case-sensitive and rejects mismatched casing. +CASE_SENSITIVITY_TESTS: list[DiagnosticTestCase] = [ DiagnosticTestCase( id="case_sensitive", command={"WhatsMyUri": 1}, use_admin=True, error_code=COMMAND_NOT_FOUND_ERROR, - msg="Case-mismatched command name should fail", + msg="whatsmyuri should reject case-mismatched command name", ), +] + + +@pytest.mark.parametrize("test", pytest_params(CASE_SENSITIVITY_TESTS)) +def test_whatsmyuri_error_conditions(collection, test): + """Test whatsmyuri error conditions.""" + result = execute_admin_command(collection, test.command) + assertFailureCode(result, test.error_code, msg=test.msg) + + +# Property [Extra Fields Ignored]: whatsmyuri ignores unrecognized fields. +EXTRA_FIELD_TESTS: list[DiagnosticTestCase] = [ DiagnosticTestCase( - id="unrecognized_field", + id="extra_field_ignored", command={"whatsmyuri": 1, "unknownField": 1}, - use_admin=True, - error_code=UNRECOGNIZED_COMMAND_FIELD_ERROR, - msg="Should reject unrecognized fields", + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should succeed even with unrecognized fields", ), ] -@pytest.mark.parametrize("test", pytest_params(ERROR_TESTS)) -def test_whatsmyuri_error_conditions(collection, test): - """Verify whatsmyuri rejects invalid usages with appropriate error codes.""" +@pytest.mark.parametrize("test", pytest_params(EXTRA_FIELD_TESTS)) +def test_whatsmyuri_extra_fields(collection, test): + """Test whatsmyuri with extra fields.""" result = execute_admin_command(collection, test.command) - assertFailureCode(result, test.error_code, msg=test.msg) + assertProperties(result, test.checks, msg=test.msg, raw_res=True) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py index 9ec81d5b7..213aa7c6b 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py @@ -18,32 +18,33 @@ pytestmark = pytest.mark.admin +# Property [Response Structure]: whatsmyuri returns ok and a non-empty you field. PROPERTY_TESTS: list[DiagnosticTestCase] = [ DiagnosticTestCase( id="ok_is_1", checks={"ok": Eq(1.0)}, - msg="'ok' field should be 1.0", + msg="whatsmyuri should return ok equal to 1.0", ), DiagnosticTestCase( id="you_exists", checks={"you": Exists()}, - msg="'you' field should always exist", + msg="whatsmyuri should return a you field", ), DiagnosticTestCase( id="you_is_string", checks={"you": IsType("string")}, - msg="'you' field should be a string", + msg="whatsmyuri should return you as a string", ), DiagnosticTestCase( id="you_is_non_empty", checks={"you": NonEmptyStr()}, - msg="'you' field should be a non-empty string containing the client URI", + msg="whatsmyuri should return a non-empty you field containing the client URI", ), ] @pytest.mark.parametrize("test", pytest_params(PROPERTY_TESTS)) def test_whatsmyuri_response_properties(collection, test): - """Verify whatsmyuri response fields have expected types and values.""" + """Test whatsmyuri response structure.""" result = execute_admin_command(collection, {"whatsmyuri": 1}) assertProperties(result, test.checks, msg=test.msg, raw_res=True) From 9bf2930d6ef146e94be4c8a582e23d04e554fed9 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 17 Jun 2026 11:26:08 -0700 Subject: [PATCH 3/8] add missing tests from spec Signed-off-by: Alina (Xi) Li --- .../test_whatsmyuri_argument_handling.py | 54 +++++++++++++++++++ .../test_whatsmyuri_error_conditions.py | 36 +++++++++++-- .../test_whatsmyuri_response_structure.py | 52 ++++++++++++++++++ 3 files changed, 138 insertions(+), 4 deletions(-) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py index 3a79f4320..2f43b1944 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py @@ -57,6 +57,12 @@ checks={"ok": Eq(1.0)}, msg="whatsmyuri should accept string", ), + DiagnosticTestCase( + "empty_string", + command={"whatsmyuri": ""}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept empty string", + ), DiagnosticTestCase( "null", command={"whatsmyuri": None}, @@ -69,18 +75,42 @@ checks={"ok": Eq(1.0)}, msg="whatsmyuri should accept empty object", ), + DiagnosticTestCase( + "nested_object", + command={"whatsmyuri": {"a": {"b": 1}}}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept nested object", + ), DiagnosticTestCase( "empty_array", command={"whatsmyuri": []}, checks={"ok": Eq(1.0)}, msg="whatsmyuri should accept empty array", ), + DiagnosticTestCase( + "array_with_elements", + command={"whatsmyuri": [1, 2, 3]}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept array with elements", + ), DiagnosticTestCase( "double", command={"whatsmyuri": 1.5}, checks={"ok": Eq(1.0)}, msg="whatsmyuri should accept double", ), + DiagnosticTestCase( + "negative_double", + command={"whatsmyuri": -1.5}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept negative double", + ), + DiagnosticTestCase( + "large_int", + command={"whatsmyuri": 999_999_999}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept large int", + ), DiagnosticTestCase( "int64", command={"whatsmyuri": Int64(1)}, @@ -99,12 +129,36 @@ checks={"ok": Eq(1.0)}, msg="whatsmyuri should accept decimal128 NaN", ), + DiagnosticTestCase( + "decimal128_infinity", + command={"whatsmyuri": Decimal128("Infinity")}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept decimal128 Infinity", + ), + DiagnosticTestCase( + "decimal128_neg_zero", + command={"whatsmyuri": Decimal128("-0")}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept decimal128 negative zero", + ), DiagnosticTestCase( "infinity", command={"whatsmyuri": float("inf")}, checks={"ok": Eq(1.0)}, msg="whatsmyuri should accept infinity", ), + DiagnosticTestCase( + "neg_infinity", + command={"whatsmyuri": float("-inf")}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept negative infinity", + ), + DiagnosticTestCase( + "nan", + command={"whatsmyuri": float("nan")}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should accept NaN", + ), DiagnosticTestCase( "date", command={"whatsmyuri": datetime(2024, 1, 1, tzinfo=timezone.utc)}, diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py index 4b766a8e8..afd61944b 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py @@ -9,8 +9,11 @@ DiagnosticTestCase, ) from documentdb_tests.framework.assertions import assertFailureCode, assertProperties -from documentdb_tests.framework.error_codes import COMMAND_NOT_FOUND_ERROR -from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.error_codes import ( + COMMAND_NOT_FOUND_ERROR, + UNKNOWN_PIPELINE_STAGE_ERROR, +) +from documentdb_tests.framework.executor import execute_admin_command, execute_command from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.property_checks import Eq @@ -20,11 +23,18 @@ # Property [Case Sensitivity]: whatsmyuri is case-sensitive and rejects mismatched casing. CASE_SENSITIVITY_TESTS: list[DiagnosticTestCase] = [ DiagnosticTestCase( - id="case_sensitive", + id="case_sensitive_capital_w", command={"WhatsMyUri": 1}, use_admin=True, error_code=COMMAND_NOT_FOUND_ERROR, - msg="whatsmyuri should reject case-mismatched command name", + msg="whatsmyuri should reject camel-cased command name", + ), + DiagnosticTestCase( + id="case_sensitive_all_upper", + command={"WHATSMYURI": 1}, + use_admin=True, + error_code=COMMAND_NOT_FOUND_ERROR, + msg="whatsmyuri should reject all-uppercase command name", ), ] @@ -36,6 +46,24 @@ def test_whatsmyuri_error_conditions(collection, test): assertFailureCode(result, test.error_code, msg=test.msg) +# Property [Not a Pipeline Stage]: whatsmyuri is not usable as an aggregation stage. +def test_whatsmyuri_as_aggregation_stage(collection): + """Test whatsmyuri is rejected as an aggregation pipeline stage.""" + result = execute_command( + collection, + { + "aggregate": collection.name, + "pipeline": [{"$whatsmyuri": {}}], + "cursor": {}, + }, + ) + assertFailureCode( + result, + UNKNOWN_PIPELINE_STAGE_ERROR, + msg="whatsmyuri should not be usable as an aggregation stage", + ) + + # Property [Extra Fields Ignored]: whatsmyuri ignores unrecognized fields. EXTRA_FIELD_TESTS: list[DiagnosticTestCase] = [ DiagnosticTestCase( diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py index 213aa7c6b..96a275f16 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py @@ -5,6 +5,8 @@ connection URI (ip:port) and the standard 'ok' field. """ +import re + import pytest from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( @@ -25,6 +27,11 @@ checks={"ok": Eq(1.0)}, msg="whatsmyuri should return ok equal to 1.0", ), + DiagnosticTestCase( + id="ok_is_double", + checks={"ok": IsType("double")}, + msg="whatsmyuri should return ok as a double", + ), DiagnosticTestCase( id="you_exists", checks={"you": Exists()}, @@ -48,3 +55,48 @@ def test_whatsmyuri_response_properties(collection, test): """Test whatsmyuri response structure.""" result = execute_admin_command(collection, {"whatsmyuri": 1}) assertProperties(result, test.checks, msg=test.msg, raw_res=True) + + +# Property [URI Format]: the you field contains an ip:port pair with a colon separator. +_COLON_PATTERN = re.compile(r":") +_NUMERIC_PORT_PATTERN = re.compile(r":\d+$") + + +def test_whatsmyuri_you_contains_colon(collection): + """Test whatsmyuri you field contains ip:port separator.""" + result = execute_admin_command(collection, {"whatsmyuri": 1}) + assertProperties( + result, + {"you": _MatchesRegex(_COLON_PATTERN, "contain ':'")}, + msg="whatsmyuri should return a you field containing a colon separator", + raw_res=True, + ) + + +def test_whatsmyuri_you_port_is_numeric(collection): + """Test whatsmyuri you field has a numeric port.""" + result = execute_admin_command(collection, {"whatsmyuri": 1}) + assertProperties( + result, + {"you": _MatchesRegex(_NUMERIC_PORT_PATTERN, "have a numeric port after ':'")}, + msg="whatsmyuri should return a you field with a numeric port", + raw_res=True, + ) + + +class _MatchesRegex: + """Inline check: assert that a string field matches a regex pattern.""" + + def __init__(self, pattern: re.Pattern, description: str) -> None: + self._pattern = pattern + self._description = description + + def check(self, value, path: str): # noqa: ANN001 + if not isinstance(value, str): + return f"expected '{path}' to be a string, got {type(value).__name__}" + if not self._pattern.search(value): + return f"expected '{path}' to {self._description}, got {value!r}" + return None + + def __repr__(self) -> str: + return f"_MatchesRegex({self._pattern.pattern!r})" From dd3d5b4891b24a4745eea8390b49cf37baaa8259 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 17 Jun 2026 11:32:56 -0700 Subject: [PATCH 4/8] inline tests regex Signed-off-by: Alina (Xi) Li --- .../test_whatsmyuri_response_structure.py | 45 ++++--------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py index 96a275f16..0e754ac17 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_response_structure.py @@ -5,8 +5,6 @@ connection URI (ip:port) and the standard 'ok' field. """ -import re - import pytest from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( @@ -58,45 +56,20 @@ def test_whatsmyuri_response_properties(collection, test): # Property [URI Format]: the you field contains an ip:port pair with a colon separator. -_COLON_PATTERN = re.compile(r":") -_NUMERIC_PORT_PATTERN = re.compile(r":\d+$") - - def test_whatsmyuri_you_contains_colon(collection): """Test whatsmyuri you field contains ip:port separator.""" result = execute_admin_command(collection, {"whatsmyuri": 1}) - assertProperties( - result, - {"you": _MatchesRegex(_COLON_PATTERN, "contain ':'")}, - msg="whatsmyuri should return a you field containing a colon separator", - raw_res=True, - ) + you = result["you"] + if ":" not in you: + raise AssertionError(f"whatsmyuri you field should contain ':' (ip:port), got {you!r}") def test_whatsmyuri_you_port_is_numeric(collection): """Test whatsmyuri you field has a numeric port.""" result = execute_admin_command(collection, {"whatsmyuri": 1}) - assertProperties( - result, - {"you": _MatchesRegex(_NUMERIC_PORT_PATTERN, "have a numeric port after ':'")}, - msg="whatsmyuri should return a you field with a numeric port", - raw_res=True, - ) - - -class _MatchesRegex: - """Inline check: assert that a string field matches a regex pattern.""" - - def __init__(self, pattern: re.Pattern, description: str) -> None: - self._pattern = pattern - self._description = description - - def check(self, value, path: str): # noqa: ANN001 - if not isinstance(value, str): - return f"expected '{path}' to be a string, got {type(value).__name__}" - if not self._pattern.search(value): - return f"expected '{path}' to {self._description}, got {value!r}" - return None - - def __repr__(self) -> str: - return f"_MatchesRegex({self._pattern.pattern!r})" + you = result["you"] + port = you.rsplit(":", 1)[-1] + if not port.isdigit(): + raise AssertionError( + f"whatsmyuri you field should have a numeric port after ':', got {you!r}" + ) From f3192eea0747ebb123d612f589e19b3bb081157e Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Tue, 23 Jun 2026 12:41:01 -0700 Subject: [PATCH 5/8] move extra field test from error_conditions to argument_handling Signed-off-by: Alina (Xi) Li --- .../test_whatsmyuri_argument_handling.py | 16 ++++++++++++-- .../test_whatsmyuri_error_conditions.py | 21 +------------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py index 2f43b1944..5d719d32a 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py @@ -1,6 +1,7 @@ """Tests for whatsmyuri command argument handling. -Validates that whatsmyuri accepts any BSON type as its argument value. +Validates that whatsmyuri accepts any BSON type as its argument value +and ignores unrecognized fields. """ from datetime import datetime, timezone @@ -11,7 +12,7 @@ from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( DiagnosticTestCase, ) -from documentdb_tests.framework.assertions import assertProperties +from documentdb_tests.framework.assertions import assertProperties, assertSuccessPartial from documentdb_tests.framework.executor import execute_admin_command from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.property_checks import Eq @@ -215,3 +216,14 @@ def test_whatsmyuri_argument_types(collection, test): """Test whatsmyuri argument type acceptance.""" result = execute_admin_command(collection, test.command) assertProperties(result, test.checks, msg=test.msg, raw_res=True) + + +# Property [Extra Fields Ignored]: whatsmyuri ignores unrecognized fields. +def test_whatsmyuri_extra_field_ignored(collection): + """Test whatsmyuri succeeds with unrecognized fields.""" + result = execute_admin_command(collection, {"whatsmyuri": 1, "unknownField": 1}) + assertSuccessPartial( + result, + {"ok": 1.0}, + msg="whatsmyuri should succeed even with unrecognized fields", + ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py index afd61944b..237e1b4bd 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py @@ -8,14 +8,13 @@ from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( DiagnosticTestCase, ) -from documentdb_tests.framework.assertions import assertFailureCode, assertProperties +from documentdb_tests.framework.assertions import assertFailureCode from documentdb_tests.framework.error_codes import ( COMMAND_NOT_FOUND_ERROR, UNKNOWN_PIPELINE_STAGE_ERROR, ) from documentdb_tests.framework.executor import execute_admin_command, execute_command from documentdb_tests.framework.parametrize import pytest_params -from documentdb_tests.framework.property_checks import Eq pytestmark = pytest.mark.admin @@ -62,21 +61,3 @@ def test_whatsmyuri_as_aggregation_stage(collection): UNKNOWN_PIPELINE_STAGE_ERROR, msg="whatsmyuri should not be usable as an aggregation stage", ) - - -# Property [Extra Fields Ignored]: whatsmyuri ignores unrecognized fields. -EXTRA_FIELD_TESTS: list[DiagnosticTestCase] = [ - DiagnosticTestCase( - id="extra_field_ignored", - command={"whatsmyuri": 1, "unknownField": 1}, - checks={"ok": Eq(1.0)}, - msg="whatsmyuri should succeed even with unrecognized fields", - ), -] - - -@pytest.mark.parametrize("test", pytest_params(EXTRA_FIELD_TESTS)) -def test_whatsmyuri_extra_fields(collection, test): - """Test whatsmyuri with extra fields.""" - result = execute_admin_command(collection, test.command) - assertProperties(result, test.checks, msg=test.msg, raw_res=True) From e9227c5f69751b4ab5847c0f88d18be97fb62d2c Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Tue, 23 Jun 2026 14:55:48 -0700 Subject: [PATCH 6/8] add setup field to DiagnosticTestCase and convert standalone to dataclass Signed-off-by: Alina (Xi) Li --- .../test_whatsmyuri_argument_handling.py | 31 ++++++++++--------- .../diagnostic/utils/diagnostic_test_case.py | 4 ++- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py index 5d719d32a..727f62ff7 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_argument_handling.py @@ -12,7 +12,7 @@ from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( DiagnosticTestCase, ) -from documentdb_tests.framework.assertions import assertProperties, assertSuccessPartial +from documentdb_tests.framework.assertions import assertProperties from documentdb_tests.framework.executor import execute_admin_command from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.property_checks import Eq @@ -210,20 +210,21 @@ ), ] +# Property [Extra Fields Ignored]: whatsmyuri ignores unrecognized fields. +EXTRA_FIELD_TESTS: list[DiagnosticTestCase] = [ + DiagnosticTestCase( + "extra_field_ignored", + command={"whatsmyuri": 1, "unknownField": 1}, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should succeed even with unrecognized fields", + ), +] -@pytest.mark.parametrize("test", pytest_params(ARGUMENT_TYPE_TESTS)) -def test_whatsmyuri_argument_types(collection, test): - """Test whatsmyuri argument type acceptance.""" - result = execute_admin_command(collection, test.command) - assertProperties(result, test.checks, msg=test.msg, raw_res=True) +ALL_TESTS = ARGUMENT_TYPE_TESTS + EXTRA_FIELD_TESTS -# Property [Extra Fields Ignored]: whatsmyuri ignores unrecognized fields. -def test_whatsmyuri_extra_field_ignored(collection): - """Test whatsmyuri succeeds with unrecognized fields.""" - result = execute_admin_command(collection, {"whatsmyuri": 1, "unknownField": 1}) - assertSuccessPartial( - result, - {"ok": 1.0}, - msg="whatsmyuri should succeed even with unrecognized fields", - ) +@pytest.mark.parametrize("test", pytest_params(ALL_TESTS)) +def test_whatsmyuri_argument_handling(collection, test): + """Test whatsmyuri argument handling.""" + result = execute_admin_command(collection, test.command) + assertProperties(result, test.checks, msg=test.msg, raw_res=True) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/utils/diagnostic_test_case.py b/documentdb_tests/compatibility/tests/system/diagnostic/utils/diagnostic_test_case.py index 39adb13d7..3d08d60c0 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/utils/diagnostic_test_case.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/utils/diagnostic_test_case.py @@ -1,7 +1,7 @@ """Shared test case for diagnostic command tests.""" from dataclasses import dataclass, field -from typing import Any, Dict, Optional +from typing import Any, Dict, List, Optional from documentdb_tests.framework.test_case import BaseTestCase @@ -11,11 +11,13 @@ class DiagnosticTestCase(BaseTestCase): """Test case for diagnostic command tests. Attributes: + setup: Commands to run before the test command to establish state. command: The command document to execute. use_admin: If True, execute against the admin database. checks: Mapping of dotted field paths to property check objects. """ + setup: List[Dict[str, Any]] = field(default_factory=list) command: Optional[Dict[str, Any]] = None use_admin: bool = True checks: Dict[str, Any] = field(default_factory=dict) From 759c2caa39587ea93e68ab5071af009a734c4560 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Tue, 23 Jun 2026 15:04:48 -0700 Subject: [PATCH 7/8] convert test_whatsmyuri_any_database Signed-off-by: Alina (Xi) Li --- .../whatsmyuri/test_whatsmyuri_consistency.py | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py index 93d667ca2..f5dce61bc 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_consistency.py @@ -6,12 +6,40 @@ import pytest -from documentdb_tests.framework.assertions import assertSuccess, assertSuccessPartial +from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( + DiagnosticTestCase, +) +from documentdb_tests.framework.assertions import ( + assertProperties, + assertSuccess, + assertSuccessPartial, +) from documentdb_tests.framework.executor import execute_admin_command, execute_command +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.property_checks import Eq pytestmark = pytest.mark.admin +# Property [Database Independence]: whatsmyuri succeeds on any database. +DATABASE_INDEPENDENCE_TESTS: list[DiagnosticTestCase] = [ + DiagnosticTestCase( + "any_database", + command={"whatsmyuri": 1}, + use_admin=False, + checks={"ok": Eq(1.0)}, + msg="whatsmyuri should succeed on non-admin database", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(DATABASE_INDEPENDENCE_TESTS)) +def test_whatsmyuri_consistency(collection, test): + """Test whatsmyuri consistency.""" + result = execute_command(collection, test.command) + assertProperties(result, test.checks, msg=test.msg, raw_res=True) + + def test_whatsmyuri_idempotent(collection): """Test whatsmyuri idempotency.""" result1 = execute_admin_command(collection, {"whatsmyuri": 1}) @@ -24,12 +52,6 @@ def test_whatsmyuri_idempotent(collection): ) -def test_whatsmyuri_any_database(collection): - """Test whatsmyuri on a non-admin database.""" - result = execute_command(collection, {"whatsmyuri": 1}) - assertSuccessPartial(result, {"ok": 1.0}, msg="whatsmyuri should succeed on non-admin database") - - def test_whatsmyuri_same_result_any_database(collection): """Test whatsmyuri returns same result from admin and non-admin database.""" admin_result = execute_admin_command(collection, {"whatsmyuri": 1}) From 442dd897076842b39ddbe1cbccce6cd3dd9e9000 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Tue, 23 Jun 2026 15:23:23 -0700 Subject: [PATCH 8/8] convert to use test case Signed-off-by: Alina (Xi) Li --- .../test_whatsmyuri_error_conditions.py | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py index 237e1b4bd..1d22a4dee 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/whatsmyuri/test_whatsmyuri_error_conditions.py @@ -1,14 +1,17 @@ """Tests for whatsmyuri command error conditions. Validates that invalid usages of whatsmyuri produce appropriate errors. +Uses CommandTestCase because the aggregation stage test needs ctx.collection +for the aggregate command. """ import pytest -from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( - DiagnosticTestCase, +from documentdb_tests.compatibility.tests.core.utils.command_test_case import ( + CommandContext, + CommandTestCase, ) -from documentdb_tests.framework.assertions import assertFailureCode +from documentdb_tests.framework.assertions import assertResult from documentdb_tests.framework.error_codes import ( COMMAND_NOT_FOUND_ERROR, UNKNOWN_PIPELINE_STAGE_ERROR, @@ -20,44 +23,46 @@ # Property [Case Sensitivity]: whatsmyuri is case-sensitive and rejects mismatched casing. -CASE_SENSITIVITY_TESTS: list[DiagnosticTestCase] = [ - DiagnosticTestCase( - id="case_sensitive_capital_w", +CASE_SENSITIVITY_TESTS: list[CommandTestCase] = [ + CommandTestCase( + "case_sensitive_capital_w", command={"WhatsMyUri": 1}, - use_admin=True, error_code=COMMAND_NOT_FOUND_ERROR, msg="whatsmyuri should reject camel-cased command name", ), - DiagnosticTestCase( - id="case_sensitive_all_upper", + CommandTestCase( + "case_sensitive_all_upper", command={"WHATSMYURI": 1}, - use_admin=True, error_code=COMMAND_NOT_FOUND_ERROR, msg="whatsmyuri should reject all-uppercase command name", ), ] - -@pytest.mark.parametrize("test", pytest_params(CASE_SENSITIVITY_TESTS)) -def test_whatsmyuri_error_conditions(collection, test): - """Test whatsmyuri error conditions.""" - result = execute_admin_command(collection, test.command) - assertFailureCode(result, test.error_code, msg=test.msg) - - # Property [Not a Pipeline Stage]: whatsmyuri is not usable as an aggregation stage. -def test_whatsmyuri_as_aggregation_stage(collection): - """Test whatsmyuri is rejected as an aggregation pipeline stage.""" - result = execute_command( - collection, - { - "aggregate": collection.name, +PIPELINE_STAGE_TESTS: list[CommandTestCase] = [ + CommandTestCase( + "as_aggregation_stage", + command=lambda ctx: { + "aggregate": ctx.collection, "pipeline": [{"$whatsmyuri": {}}], "cursor": {}, }, - ) - assertFailureCode( - result, - UNKNOWN_PIPELINE_STAGE_ERROR, + error_code=UNKNOWN_PIPELINE_STAGE_ERROR, msg="whatsmyuri should not be usable as an aggregation stage", - ) + ), +] + +ALL_TESTS = CASE_SENSITIVITY_TESTS + PIPELINE_STAGE_TESTS + + +@pytest.mark.parametrize("test", pytest_params(ALL_TESTS)) +def test_whatsmyuri_error_conditions(collection, test): + """Test whatsmyuri error conditions.""" + ctx = CommandContext.from_collection(collection) + cmd = test.build_command(ctx) + # Case sensitivity tests target the admin db; the aggregate test does not. + if next(iter(cmd)).lower() == "whatsmyuri": + result = execute_admin_command(collection, cmd) + else: + result = execute_command(collection, cmd) + assertResult(result, error_code=test.error_code, msg=test.msg)