-
Notifications
You must be signed in to change notification settings - Fork 37
Add listCommands tests #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c4e9f00
Add listCommands tests
PatersonProjects d7cdcb7
Update buildInfo non-existent test
PatersonProjects db1433a
Merge branch 'main' into listCommands_tests
PatersonProjects 1b70ee0
Add listCommands self-inclusion test case
PatersonProjects 24f99d3
Merge branch 'main' into listCommands_tests
eerxuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
64 changes: 64 additions & 0 deletions
64
...lity/tests/system/diagnostic/commands/listCommands/test_listCommands_argument_handling.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """Tests for listCommands command argument handling. | ||
|
|
||
| Validates that listCommands accepts any BSON type as its argument value | ||
| and rejects unrecognized fields. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from documentdb_tests.framework.assertions import assertProperties | ||
| from documentdb_tests.framework.bson_type_validator import ( | ||
| BsonType, | ||
| BsonTypeTestCase, | ||
| generate_bson_acceptance_test_cases, | ||
| ) | ||
| from documentdb_tests.framework.executor import execute_admin_command | ||
| from documentdb_tests.framework.property_checks import Eq | ||
|
|
||
| pytestmark = pytest.mark.admin | ||
|
|
||
|
|
||
| # listCommands accepts all BSON types as its argument value | ||
| LISTCOMMANDS_BSON_TYPE_PARAMS = [ | ||
| BsonTypeTestCase( | ||
| id="argument", | ||
| msg="listCommands should accept any BSON type as argument", | ||
| keyword="listCommands", | ||
| valid_types=[ | ||
| BsonType.DOUBLE, | ||
| BsonType.STRING, | ||
| BsonType.OBJECT, | ||
| BsonType.ARRAY, | ||
| BsonType.BIN_DATA, | ||
| BsonType.OBJECT_ID, | ||
| BsonType.BOOL, | ||
| BsonType.DATE, | ||
| BsonType.NULL, | ||
| BsonType.REGEX, | ||
| BsonType.JAVASCRIPT, | ||
| BsonType.INT, | ||
| BsonType.TIMESTAMP, | ||
| BsonType.LONG, | ||
| BsonType.DECIMAL, | ||
| BsonType.MIN_KEY, | ||
| BsonType.MAX_KEY, | ||
| ], | ||
| ), | ||
| ] | ||
|
|
||
| ACCEPTANCE_TESTS = generate_bson_acceptance_test_cases(LISTCOMMANDS_BSON_TYPE_PARAMS) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_TESTS) | ||
| def test_listCommands_argument_types(collection, bson_type, sample_value, spec): | ||
| """Test that listCommands accepts any BSON type as argument value.""" | ||
| result = execute_admin_command(collection, {"listCommands": sample_value}) | ||
| assertProperties(result, {"ok": Eq(1.0)}, msg=f"{spec.msg} - {bson_type.value}", raw_res=True) | ||
|
|
||
|
|
||
| def test_listCommands_extra_fields_ignored(collection): | ||
| """Test that listCommands ignores extra unrecognized fields.""" | ||
| result = execute_admin_command(collection, {"listCommands": 1, "unknownField": 1}) | ||
| assertProperties( | ||
| result, {"ok": Eq(1.0)}, msg="Should succeed even with extra fields", raw_res=True | ||
| ) |
75 changes: 75 additions & 0 deletions
75
...patibility/tests/system/diagnostic/commands/listCommands/test_listCommands_consistency.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| """Tests for listCommands command consistency and availability. | ||
|
|
||
| Validates that listCommands works across databases and returns consistent results. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| 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 | ||
|
|
||
|
|
||
| DATABASE_TESTS: list[DiagnosticTestCase] = [ | ||
| DiagnosticTestCase( | ||
| id="admin_database", | ||
| command={"listCommands": 1}, | ||
| use_admin=True, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="Should succeed on admin database", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="non_admin_database", | ||
| command={"listCommands": 1}, | ||
| use_admin=False, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="Should succeed on non-admin database", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(DATABASE_TESTS)) | ||
| def test_listCommands_database_availability(collection, test): | ||
| """Test listCommands works on both admin and non-admin databases.""" | ||
| if test.use_admin: | ||
| result = execute_admin_command(collection, test.command) | ||
| else: | ||
| result = execute_command(collection, test.command) | ||
| assertProperties(result, test.checks, msg=test.msg, raw_res=True) | ||
|
|
||
|
|
||
| def test_listCommands_nonexistent_database(collection): | ||
| """Test listCommands succeeds when run 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, {"listCommands": 1}) | ||
| assertSuccessPartial(result, {"ok": 1.0}, msg="Should succeed on non-existent database") | ||
|
|
||
|
|
||
| def test_listCommands_idempotent(collection): | ||
| """Test calling listCommands multiple times returns identical results.""" | ||
| result1 = execute_admin_command(collection, {"listCommands": 1}) | ||
| result2 = execute_admin_command(collection, {"listCommands": 1}) | ||
| assertSuccess(result2, expected=result1, msg="Should return identical results", raw_res=True) | ||
|
|
||
|
|
||
| def test_listCommands_same_result_any_database(collection): | ||
| """Test listCommands returns same result from admin and non-admin database.""" | ||
| admin_result = execute_admin_command(collection, {"listCommands": 1}) | ||
| db_result = execute_command(collection, {"listCommands": 1}) | ||
| assertSuccess( | ||
| db_result, | ||
| expected=admin_result, | ||
| msg="Should return same result from any database", | ||
| raw_res=True, | ||
| ) |
47 changes: 47 additions & 0 deletions
47
...ility/tests/system/diagnostic/commands/listCommands/test_listCommands_error_conditions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| """Tests for listCommands command error conditions. | ||
|
|
||
| Validates that invalid usages of listCommands 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, | ||
| UNKNOWN_PIPELINE_STAGE_ERROR, | ||
| ) | ||
| from documentdb_tests.framework.executor import execute_admin_command, execute_command | ||
| from documentdb_tests.framework.parametrize import pytest_params | ||
|
|
||
| pytestmark = pytest.mark.admin | ||
|
|
||
|
|
||
| ERROR_TESTS: list[DiagnosticTestCase] = [ | ||
| DiagnosticTestCase( | ||
| id="as_aggregation_stage", | ||
| command={"aggregate": "test", "pipeline": [{"$listCommands": {}}], "cursor": {}}, | ||
| use_admin=False, | ||
| error_code=UNKNOWN_PIPELINE_STAGE_ERROR, | ||
| msg="$listCommands is not a valid aggregation stage", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="case_sensitive", | ||
| command={"ListCommands": 1}, | ||
| use_admin=True, | ||
| error_code=COMMAND_NOT_FOUND_ERROR, | ||
| msg="Case-mismatched command name should fail", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(ERROR_TESTS)) | ||
| def test_listCommands_error_conditions(collection, test): | ||
| """Verifies listCommands rejects invalid usages with appropriate error codes.""" | ||
| if test.use_admin: | ||
| result = execute_admin_command(collection, test.command) | ||
| else: | ||
| result = execute_command(collection, test.command) | ||
| assertFailureCode(result, test.error_code, msg=test.msg) |
124 changes: 124 additions & 0 deletions
124
...ity/tests/system/diagnostic/commands/listCommands/test_listCommands_response_structure.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| """Tests for listCommands command response structure. | ||
|
|
||
| Validates the response format, field types, and presence of expected commands. | ||
| """ | ||
|
|
||
| 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 | ||
|
|
||
| pytestmark = pytest.mark.admin | ||
|
|
||
|
|
||
| RESPONSE_FIELD_TESTS: list[DiagnosticTestCase] = [ | ||
| DiagnosticTestCase( | ||
| id="ok_is_1", | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="'ok' field should be 1.0", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="commands_is_object", | ||
| checks={"commands": IsType("object")}, | ||
| msg="'commands' field should be an object", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(RESPONSE_FIELD_TESTS)) | ||
| def test_listCommands_response_fields(collection, test): | ||
| """Verify listCommands response contains expected fields with correct types.""" | ||
| result = execute_admin_command(collection, {"listCommands": 1}) | ||
| assertProperties(result, test.checks, msg=test.msg, raw_res=True) | ||
|
|
||
|
|
||
| COMMAND_ENTRY_STRUCTURE_TESTS: list[DiagnosticTestCase] = [ | ||
| DiagnosticTestCase( | ||
| id="find_has_help", | ||
| checks={"commands.find.help": IsType("string")}, | ||
| msg="Command entry 'find' should have 'help' field of type string", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="find_has_adminOnly", | ||
| checks={"commands.find.adminOnly": IsType("bool")}, | ||
| msg="Command entry 'find' should have 'adminOnly' field of type boolean", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="find_has_requiresAuth", | ||
| checks={"commands.find.requiresAuth": IsType("bool")}, | ||
| msg="Command entry 'find' should have 'requiresAuth' field of type boolean", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="find_has_secondaryOk", | ||
| checks={"commands.find.secondaryOk": IsType("bool")}, | ||
| msg="Command entry 'find' should have 'secondaryOk' field of type boolean", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="find_has_apiVersions", | ||
| checks={"commands.find.apiVersions": IsType("array")}, | ||
| msg="Command entry 'find' should have 'apiVersions' field of type array", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="find_has_deprecatedApiVersions", | ||
| checks={"commands.find.deprecatedApiVersions": IsType("array")}, | ||
| msg="Command entry 'find' should have 'deprecatedApiVersions' field of type array", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(COMMAND_ENTRY_STRUCTURE_TESTS)) | ||
| def test_listCommands_command_entry_structure(collection, test): | ||
| """Verify each command entry contains expected fields with correct types.""" | ||
| result = execute_admin_command(collection, {"listCommands": 1}) | ||
| assertProperties(result, test.checks, msg=test.msg, raw_res=True) | ||
|
|
||
|
|
||
| KNOWN_COMMANDS_TESTS: list[DiagnosticTestCase] = [ | ||
| DiagnosticTestCase( | ||
| id="find_present", | ||
| checks={"commands.find": Exists()}, | ||
| msg="'find' should be listed", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="insert_present", | ||
| checks={"commands.insert": Exists()}, | ||
| msg="'insert' should be listed", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="update_present", | ||
| checks={"commands.update": Exists()}, | ||
| msg="'update' should be listed", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="delete_present", | ||
| checks={"commands.delete": Exists()}, | ||
| msg="'delete' should be listed", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="aggregate_present", | ||
| checks={"commands.aggregate": Exists()}, | ||
| msg="'aggregate' should be listed", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="ping_present", | ||
| checks={"commands.ping": Exists()}, | ||
| msg="'ping' should be listed", | ||
| ), | ||
| DiagnosticTestCase( | ||
| id="listCommands_present", | ||
| checks={"commands.listCommands": Exists()}, | ||
| msg="'listCommands' should be listed in its own output", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(KNOWN_COMMANDS_TESTS)) | ||
| def test_listCommands_known_commands_present(collection, test): | ||
| """Verify well-known commands appear in the listCommands response.""" | ||
| result = execute_admin_command(collection, {"listCommands": 1}) | ||
| assertProperties(result, test.checks, msg=test.msg, raw_res=True) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.