Skip to content

test: add comprehensive special character tests for all fields#155

Open
NTLx wants to merge 5 commits intooceanbase:developfrom
NTLx:feature/test-special-chars-133
Open

test: add comprehensive special character tests for all fields#155
NTLx wants to merge 5 commits intooceanbase:developfrom
NTLx:feature/test-special-chars-133

Conversation

@NTLx
Copy link
Contributor

@NTLx NTLx commented Jan 30, 2026

Summary

Addressing issue #133.
Added a new unit test file tests/unit_tests/test_special_characters.py to verify that the client correctly handles special characters in:

  • Collection names (validation)
  • IDs (escaping and binary casting)
  • Documents (escaping)
  • Metadata (JSON serialization and escaping)

Tested scenarios include:

  • SQL injection attempts
  • Special syntax characters (newlines, null bytes, backslashes)
  • Unicode characters (Chinese, Arabic, Hebrew, Emoji)
  • Whitespace

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

  • Tests
    • Added unit tests verifying handling of special characters in IDs, document content, and metadata serialization.
    • Added tests to validate collection naming rules and proper error handling for invalid names.
    • Introduced mock testing support to simulate backend interactions and assert generated SQL and operations.

✏️ Tip: You can customize this high-level summary in your review settings.

- 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
@coderabbitai
Copy link

coderabbitai bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Special characters tests
tests/unit_tests/test_special_characters.py
Adds MockClient (subclass of BaseClient with a mocked executor) and TestSpecialCharacters (unittest.TestCase) containing tests for IDs with special characters (CAST ... AS BINARY), documents with special characters, metadata JSON serialization/escaping and INSERT SQL checks, and collection name validation via _validate_collection_name.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested reviewers

  • hnwyllmm

Poem

🐰 I nibble on strings with cheer,

Quotes and slashes, never fear,
IDs and docs tucked safe at night,
Metadata twinkles, escaped just right,
Hopping through tests, I hold the light.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding comprehensive tests for special character handling across all fields (IDs, documents, metadata, collection names).
Docstring Coverage ✅ Passed Docstring coverage is 94.12% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +10 to +13
# 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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
NTLx added a commit to NTLx/pyseekdb that referenced this pull request Jan 31, 2026
…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
NTLx and others added 3 commits February 1, 2026 23:12
- 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>
@NTLx
Copy link
Contributor Author

NTLx commented Feb 9, 2026

Hi @hnwyllmm! This PR is now MERGEABLE with all CI checks passing.

Summary:

  • Added comprehensive special character tests for IDs, documents, metadata, and collection names
  • All unit and integration tests passing
  • Docstring coverage at 94.12%

Ready for merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants