Normalizing the AquaSec fetched input for parent issues#70
Conversation
WalkthroughRuleDetails.post_init normalization logic is refactored to group target display fields (impact, likelihood, confidence) into a _display_fields tuple and apply consistent string-strip-or-NOT_AVAILABLE normalization via a single loop. Test coverage is added to validate the behavior with parameterized inputs including None fallback cases. ChangesRuleDetails Display Field Normalization
🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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
🧹 Nitpick comments (1)
tests/security/alerts/test_models.py (1)
65-69: ⚡ Quick winConsider adding edge case test parameters.
The current test cases cover the main scenarios, but two important edge cases are missing:
- Empty string
""→ should normalize toNOT_AVAILABLE- Whitespace-only string
" "→ should strip to empty and becomeNOT_AVAILABLEThese edge cases would strengthen confidence in the normalization contract without violating the "minimal tests" guideline.
🧪 Suggested additional test cases
`@pytest.mark.parametrize`("raw, expected", [ ("HIGH\n", "HIGH"), (" MEDIUM ", "MEDIUM"), + ("", NOT_AVAILABLE), + (" ", NOT_AVAILABLE), (None, NOT_AVAILABLE), ])🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/security/alerts/test_models.py` around lines 65 - 69, Add two edge-case parameters to the existing pytest.mark.parametrize tuple in tests/security/alerts/test_models.py so the normalization covers empty and whitespace-only inputs: include ("", NOT_AVAILABLE) and (" ", NOT_AVAILABLE) alongside the existing ("HIGH\n", "HIGH"), (" MEDIUM ", "MEDIUM"), (None, NOT_AVAILABLE) entries; keep the param names raw and expected and use the NOT_AVAILABLE sentinel so the test asserts the normalization function treats empty/blank strings as NOT_AVAILABLE.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/security/alerts/test_models.py`:
- Line 61: The comment line containing "RuleDetails – whitespace stripping and
NOT_AVAILABLE fallback" uses an EN DASH; replace that character with a standard
hyphen-minus so it reads "RuleDetails - whitespace stripping and NOT_AVAILABLE
fallback" to satisfy the RUF003 ambiguous-unicode-characters check and remove
the warning.
---
Nitpick comments:
In `@tests/security/alerts/test_models.py`:
- Around line 65-69: Add two edge-case parameters to the existing
pytest.mark.parametrize tuple in tests/security/alerts/test_models.py so the
normalization covers empty and whitespace-only inputs: include ("",
NOT_AVAILABLE) and (" ", NOT_AVAILABLE) alongside the existing ("HIGH\n",
"HIGH"), (" MEDIUM ", "MEDIUM"), (None, NOT_AVAILABLE) entries; keep the param
names raw and expected and use the NOT_AVAILABLE sentinel so the test asserts
the normalization function treats empty/blank strings as NOT_AVAILABLE.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9e8b9fce-ed46-4cfc-9339-6c7910292402
📒 Files selected for processing (2)
src/security/alerts/models.pytests/security/alerts/test_models.py
Overview
This pull request enhances the data normalization logic in the
RuleDetailsmodel and adds comprehensive tests to ensure correct handling of whitespace and missing values. The changes improve the robustness and consistency of how display fields are processed and validated.Release Notes
RuleDetailsmodelRelated
Closes #69
Summary by CodeRabbit
Refactor
Tests