-
Notifications
You must be signed in to change notification settings - Fork 11
Add collation tests #225
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
Add collation tests #225
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d62de70
Add collation tests
danielfrankcom a78e067
Restructure tests into subdirs
danielfrankcom 7a7f089
Add test verifying view collation does not affect source collection
danielfrankcom 26e54f6
Create second index on same key with different collation
danielfrankcom 2d2996f
Redistribute edge case tests, add geospatial index coverage
danielfrankcom 91ae535
Add timeseries and clustered collection collation tests
danielfrankcom 205c1c8
Move projection tests to command_level/operations
danielfrankcom cbc0470
Fold dotted path test into find operations
danielfrankcom 062f564
merge from upstream/main
danielfrankcom f453ef0
merge from upstream/main
danielfrankcom 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
Empty file.
Empty file.
112 changes: 112 additions & 0 deletions
112
...tests/compatibility/tests/core/collation/collection_level/test_collection_level_capped.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,112 @@ | ||
| """Tests for collation behavior with capped collections.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from documentdb_tests.compatibility.tests.core.collections.commands.utils.command_test_case import ( | ||
| CommandContext, | ||
| CommandTestCase, | ||
| ) | ||
| from documentdb_tests.framework.assertions import assertResult | ||
| from documentdb_tests.framework.executor import execute_command | ||
| from documentdb_tests.framework.parametrize import pytest_params | ||
| from documentdb_tests.framework.target_collection import CappedCollection, CustomCollection | ||
|
|
||
| # Property [Capped Collection Collation]: a capped collection can be created | ||
| # with a default collation, and collation affects filter matching and sort | ||
| # ordering on capped collections the same as regular collections. | ||
| COLLATION_CAPPED_TESTS: list[CommandTestCase] = [ | ||
| CommandTestCase( | ||
| "capped_with_default_collation_filter", | ||
| target_collection=CustomCollection( | ||
| options={"capped": True, "size": 4096, "collation": {"locale": "en", "strength": 2}} | ||
| ), | ||
| docs=[ | ||
| {"_id": 1, "x": "apple"}, | ||
| {"_id": 2, "x": "Apple"}, | ||
| {"_id": 3, "x": "banana"}, | ||
| ], | ||
| command=lambda ctx: { | ||
| "find": ctx.collection, | ||
| "filter": {"x": "apple"}, | ||
| }, | ||
| expected=[ | ||
| {"_id": 1, "x": "apple"}, | ||
| {"_id": 2, "x": "Apple"}, | ||
| ], | ||
| msg="capped collection with default collation should use it for filter matching", | ||
| ), | ||
| CommandTestCase( | ||
| "capped_explicit_collation_filter", | ||
| target_collection=CappedCollection(size=4096), | ||
| docs=[ | ||
| {"_id": 1, "x": "apple"}, | ||
| {"_id": 2, "x": "Apple"}, | ||
| {"_id": 3, "x": "banana"}, | ||
| ], | ||
| command=lambda ctx: { | ||
| "find": ctx.collection, | ||
| "filter": {"x": "apple"}, | ||
| "collation": {"locale": "en", "strength": 2}, | ||
| }, | ||
| expected=[ | ||
| {"_id": 1, "x": "apple"}, | ||
| {"_id": 2, "x": "Apple"}, | ||
| ], | ||
| msg="capped collection should support explicit collation on find", | ||
| ), | ||
| CommandTestCase( | ||
| "capped_collation_sort", | ||
| target_collection=CappedCollection(size=4096), | ||
| docs=[ | ||
| {"_id": 1, "x": "banana"}, | ||
| {"_id": 2, "x": "Apple"}, | ||
| {"_id": 3, "x": "cherry"}, | ||
| ], | ||
| command=lambda ctx: { | ||
| "find": ctx.collection, | ||
| "filter": {}, | ||
| "sort": {"x": 1}, | ||
| "collation": {"locale": "en", "strength": 2}, | ||
| }, | ||
| expected=[ | ||
| {"_id": 2, "x": "Apple"}, | ||
| {"_id": 1, "x": "banana"}, | ||
| {"_id": 3, "x": "cherry"}, | ||
| ], | ||
| msg="capped collection should support collation sort ordering", | ||
| ), | ||
| CommandTestCase( | ||
| "capped_count_with_collation", | ||
| target_collection=CappedCollection(size=4096), | ||
| docs=[ | ||
| {"_id": 1, "x": "apple"}, | ||
| {"_id": 2, "x": "Apple"}, | ||
| {"_id": 3, "x": "banana"}, | ||
| ], | ||
| command=lambda ctx: { | ||
| "count": ctx.collection, | ||
| "query": {"x": "apple"}, | ||
| "collation": {"locale": "en", "strength": 2}, | ||
| }, | ||
| expected={"n": 2, "ok": 1.0}, | ||
| msg="count on capped collection should support collation", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(COLLATION_CAPPED_TESTS)) | ||
| def test_collation_capped(database_client, collection, test): | ||
| """Test collation behavior with capped collections.""" | ||
| collection = test.prepare(database_client, collection) | ||
| ctx = CommandContext.from_collection(collection) | ||
| result = execute_command(collection, test.build_command(ctx)) | ||
| expected = test.build_expected(ctx) | ||
| assertResult( | ||
| result, | ||
| expected=expected, | ||
| error_code=test.error_code, | ||
| msg=test.msg, | ||
| raw_res=not isinstance(expected, list), | ||
| ) | ||
94 changes: 94 additions & 0 deletions
94
...ts/compatibility/tests/core/collation/collection_level/test_collection_level_clustered.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,94 @@ | ||
| """Tests for collation behavior with clustered collections.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from documentdb_tests.compatibility.tests.core.collections.commands.utils.command_test_case import ( | ||
| CommandContext, | ||
| CommandTestCase, | ||
| ) | ||
| from documentdb_tests.framework.assertions import assertResult | ||
| from documentdb_tests.framework.error_codes import DUPLICATE_KEY_ERROR | ||
| from documentdb_tests.framework.executor import execute_command | ||
| from documentdb_tests.framework.parametrize import pytest_params | ||
| from documentdb_tests.framework.target_collection import CustomCollection | ||
|
|
||
| # Property [Clustered Collection Collation]: a clustered collection can be | ||
| # created with a default collation, and collation affects filter matching and | ||
| # _id uniqueness enforcement. | ||
| COLLATION_CLUSTERED_TESTS: list[CommandTestCase] = [ | ||
| CommandTestCase( | ||
| "clustered_default_collation_filter", | ||
| target_collection=CustomCollection( | ||
| options={ | ||
| "clusteredIndex": {"key": {"_id": 1}, "unique": True}, | ||
| "collation": {"locale": "en", "strength": 2}, | ||
| } | ||
| ), | ||
| docs=[ | ||
| {"_id": "apple", "v": 1}, | ||
| {"_id": "banana", "v": 2}, | ||
| ], | ||
| command=lambda ctx: { | ||
| "find": ctx.collection, | ||
| "filter": {"_id": "Apple"}, | ||
| }, | ||
| expected=[{"_id": "apple", "v": 1}], | ||
| msg="clustered collection with default collation should use it for _id filter matching", | ||
| ), | ||
| CommandTestCase( | ||
| "clustered_collation_rejects_case_variant_id", | ||
| target_collection=CustomCollection( | ||
| options={ | ||
| "clusteredIndex": {"key": {"_id": 1}, "unique": True}, | ||
| "collation": {"locale": "en", "strength": 2}, | ||
| } | ||
| ), | ||
| docs=[{"_id": "apple", "v": 1}], | ||
| command=lambda ctx: { | ||
| "insert": ctx.collection, | ||
| "documents": [{"_id": "Apple", "v": 2}], | ||
| }, | ||
| error_code=DUPLICATE_KEY_ERROR, | ||
| msg="clustered collection with collation should reject case-variant _id as duplicate", | ||
| ), | ||
| CommandTestCase( | ||
| "clustered_explicit_collation_filter", | ||
| target_collection=CustomCollection( | ||
| options={"clusteredIndex": {"key": {"_id": 1}, "unique": True}} | ||
| ), | ||
| docs=[ | ||
| {"_id": "apple", "v": 1}, | ||
| {"_id": "Apple", "v": 2}, | ||
| {"_id": "banana", "v": 3}, | ||
| ], | ||
| command=lambda ctx: { | ||
| "find": ctx.collection, | ||
| "filter": {"_id": "apple"}, | ||
| "sort": {"_id": 1}, | ||
| "collation": {"locale": "en", "strength": 2}, | ||
| }, | ||
| expected=[ | ||
| {"_id": "Apple", "v": 2}, | ||
| {"_id": "apple", "v": 1}, | ||
| ], | ||
| msg="clustered collection should support explicit collation on find", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(COLLATION_CLUSTERED_TESTS)) | ||
| def test_collation_clustered(database_client, collection, test): | ||
| """Test collation behavior with clustered collections.""" | ||
| collection = test.prepare(database_client, collection) | ||
| ctx = CommandContext.from_collection(collection) | ||
| result = execute_command(collection, test.build_command(ctx)) | ||
| expected = test.build_expected(ctx) | ||
| assertResult( | ||
| result, | ||
| expected=expected, | ||
| error_code=test.error_code, | ||
| msg=test.msg, | ||
| raw_res=not isinstance(expected, list), | ||
| ) |
Oops, something went wrong.
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.