Skip to content

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

Open
NTLx wants to merge 7 commits into
oceanbase:developfrom
NTLx:feature/test-special-chars-133
Open

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

Conversation

@NTLx

@NTLx NTLx commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

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 a new unit-test module to validate escaping and SQL generation for special characters in collection IDs, document content, and metadata.
    • Includes cases for quotes, injection-like patterns, control characters, unicode, and emojis, covering both metadata value and metadata key scenarios (JSON serialization).
    • Added validation tests for collection names, asserting invalid names raise errors.
    • Introduced a mock client to capture the SQL produced during collection add/insert operations for verification.

- 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

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fcf476d3-2755-4fbd-8c8b-c7eed5d972b4

📥 Commits

Reviewing files that changed from the base of the PR and between b1ef617 and a032c6e.

📒 Files selected for processing (1)
  • tests/unit_tests/test_special_characters.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit_tests/test_special_characters.py

📝 Walkthrough

Walkthrough

Adds a unit-test module that verifies special-character handling in IDs, documents, metadata, and collection names using a mocked SQL executor.

Changes

Special-character SQL tests

Layer / File(s) Summary
Mocked client and test fixtures
tests/unit_tests/test_special_characters.py
Adds a BaseClient test double that captures SQL and shared inputs containing quotes, control characters, unicode, emojis, and injection patterns.
Escaping and validation assertions
tests/unit_tests/test_special_characters.py
Tests escaped ID, document, and metadata SQL generation, CAST(... AS BINARY) ID conversion, collection-name validation, and direct test execution.

Estimated code review effort: 2 (Simple) | ~15 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding comprehensive special-character tests across fields.
Docstring Coverage ✅ Passed Docstring coverage is 94.12% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 thread tests/unit_tests/test_special_characters.py Outdated
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))

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@frostming 谢谢提醒,已修复。

最新提交 (b1ef617) 删除了 project_root / src_root / sys.path.insert() 这三行,以及随之失去用处的 import sys / from pathlib import Path 导入和 noqa: E402 标记。现在测试完全依赖项目以 pip install -e . 方式安装,pytest 直接 from pyseekdb.client.client_base import BaseClient

顺手把 CodeRabbit 在另一个线程里指出的 F841 也修了:test_metadata_special_characters 之前构造的 metadata_key_test_collection_add 之前就断言,触发 UnboundLocalError;现在分成 value / key 两组调用,分别对 executed_sql 做了基于 pymysql.converters.escape_string 的转义断言。

本地 pytest tests/unit_tests/test_special_characters.py 4/4 通过。请 @hnwyllmm 复核,CI 也已重新触发。

- 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

NTLx commented Feb 9, 2026

Copy link
Copy Markdown
Contributor Author

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!

NTLx added 2 commits July 28, 2026 09:10
- Remove project_root/src_root/sys.path.insert() so the test relies on
  the installed package (pyseekdb is installed in the CI environment
  via `pip install -e .`).
- Drop now-unused `import sys` / `from pathlib import Path` and the
  E402 noqa markers.
- Rework test_metadata_special_characters: the previous version built
  a key-shaped metadata dict and asserted on `executed_sql` before
  any call had populated it (UnboundLocalError / F841). Now both
  {key: special_str} and {special_str: "value"} shapes are passed
  through _collection_add and their JSON+SQL escaping is asserted via
  pymysql.converters.escape_string.
Co-Authored-By: Claude Code noreply@anthropic.com
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