test: add comprehensive special character tests for all fields#155
test: add comprehensive special character tests for all fields#155NTLx wants to merge 5 commits intooceanbase:developfrom
Conversation
- Add tests/unit_tests/test_special_characters.py - Cover IDs, documents, metadata, and collection name validation - Test cases include SQL injection patterns, unicode, emoji, and special chars Resolves: oceanbase#133
📝 WalkthroughWalkthroughAdds a new unit test module that verifies handling of special characters in IDs, documents, metadata, and collection names. Introduces a MockClient subclass of BaseClient and TestSpecialCharacters with four tests validating SQL generation, escaping/serialization, and collection name validation. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tests/unit_tests/test_special_characters.py`:
- Around line 2-8: The tests in test_special_characters.py create variables
executed_sql and metadata_key_test but never assert anything; update the two
test methods to assert that the SQL and metadata strings contain properly
escaped fragments by using escape_string from pymysql.converters to compute
expected escaped values and comparing them to executed_sql and metadata_key_test
(e.g., assert expected in executed_sql and assert expected_meta in
metadata_key_test), which will both validate escaping behavior and eliminate the
F841 unused-variable warnings; reference the existing variables executed_sql,
metadata_key_test and the escape_string function to locate where to inject these
assertions.
| # Ensure local src/ is on sys.path | ||
| project_root = Path(__file__).parent.parent.parent | ||
| src_root = project_root / "src" | ||
| sys.path.insert(0, str(src_root)) |
There was a problem hiding this comment.
Usually the project is installed when running the tests, so these are not necessary.
- Update uv.lock to fix lock file consistency check - Add docstrings to MockClient class methods to improve docstring coverage - This resolves the CI quality check failure Closes oceanbase#155
…e#155 - Move test_long_collection_name.py to tests/integration_tests - Use environment variables for database connection - Add proper cleanup in fixtures - Change pytest.raises(Exception) to pytest.raises(TypeError) - Add assertions to verify special character escaping
- Add assertions to verify SQL escaping of IDs, documents, and metadata
- Use escape_string to compute expected escaped segments
- Fix incorrect column name ('key' -> '_id') and table name mapping in tests
- Remove unused imports and fix F841 linting issues
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Hi @hnwyllmm! This PR is now MERGEABLE with all CI checks passing. Summary:
Ready for merge! |
Summary
Addressing issue #133.
Added a new unit test file
tests/unit_tests/test_special_characters.pyto verify that the client correctly handles special characters in:Tested scenarios include:
Test plan
Ran the new tests locally using
uv run pytest tests/unit_tests/test_special_characters.py -v.All 4 tests passed.
🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.