-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add hyphen and underscore as valid term id and improve error messages #247
base: development
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request modifies input validation for vocabulary and term subjects in the application. It updates the HTML template to provide a clearer description of allowed characters and alters the backend validation logic to permit underscores and hyphens. Additionally, it enhances error messaging for invalid inputs. The test suite is also updated to reflect these changes, ensuring that both valid and invalid inputs are properly handled and tested. Changes
Possibly related PRs
Poem
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
🧹 Nitpick comments (1)
evoks/vocabularies/views.py (1)
608-609
: LGTM! Consider capitalizing the error message.The validation regex correctly implements the requirement to allow alphanumeric characters, underscores, and hyphens. The error message is clear and descriptive.
- return HttpResponseBadRequest('error, subject may only contain alphanumberic characters, underscores (_) or hyphens (-) (no blanks)') + return HttpResponseBadRequest('Error: Subject may only contain alphanumeric characters, underscores (_) or hyphens (-) (no blanks)')
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
evoks/theme/templates/modals/create_vocabulary.html
(1 hunks)evoks/vocabularies/views.py
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test-all
- GitHub Check: test-all
@@ -32,7 +32,7 @@ <h3 class="text-lg leading-6 font-medium text-gray-900" id="modal-title"> | |||
<div class="mt-1"> | |||
<input type="text" name="name" id="text" maxlength="50" required='True' | |||
pattern="[A-Za-z0-9_-]+" | |||
title="Error, only letters and numbers without blanks are supported" | |||
title="error, only alphanumberic characters, underscore (_) or hyphen (-) allowed (no blanks)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo in the title attribute.
There's a typo in "alphanumberic" which should be "alphanumeric".
- title="error, only alphanumberic characters, underscore (_) or hyphen (-) allowed (no blanks)"
+ title="error, only alphanumeric characters, underscore (_) or hyphen (-) allowed (no blanks)"
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
title="error, only alphanumberic characters, underscore (_) or hyphen (-) allowed (no blanks)" | |
title="error, only alphanumeric characters, underscore (_) or hyphen (-) allowed (no blanks)" |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## development #247 +/- ##
===============================================
+ Coverage 93.85% 93.91% +0.05%
===============================================
Files 49 49
Lines 1774 1774
===============================================
+ Hits 1665 1666 +1
+ Misses 109 108 -1 ☔ View full report in Codecov by Sentry. |
- Tests reflect the allowed characters of term subjects (term ids)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
evoks/tests/views/test_vocabulary_views.py (1)
519-539
: Consider enhancing test coverage.Consider adding the following test cases to improve coverage:
- Verify error messages for each validation failure
- Test maximum length validation (if applicable)
- Test other common special characters (e.g.,
@
,$
,%
, etc.)def test_create_term(self): # ... existing test cases ... + # verify error message for empty subject + error_response = self.c.post( + '/vocabularies/{0}/terms'.format(self.vocabulary.name), + {'create-term': '', 'term-subject': '', 'term-label': 'testlabel'} + ) + self.assertEqual(error_response.status_code, 400) + self.assertIn('Term subject cannot be empty', error_response.content.decode()) + + # test maximum length (if applicable) + error_response = self.c.post( + '/vocabularies/{0}/terms'.format(self.vocabulary.name), + {'create-term': '', 'term-subject': 'a' * 256, 'term-label': 'testlabel'} + ) + self.assertEqual(error_response.status_code, 400) + self.assertIn('Term subject exceeds maximum length', error_response.content.decode()) + + # test other special characters + for char in '@$%&*()+=[]{}|\\:;"\'<>,.?/': + error_response = self.c.post( + '/vocabularies/{0}/terms'.format(self.vocabulary.name), + {'create-term': '', 'term-subject': f'test{char}term', 'term-label': 'testlabel'} + ) + self.assertEqual(error_response.status_code, 400) + self.assertIn('Term subject contains invalid characters', error_response.content.decode())
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
evoks/tests/views/test_vocabulary_views.py
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test-all
- GitHub Check: test-all
🔇 Additional comments (2)
evoks/tests/views/test_vocabulary_views.py (2)
471-471
: LGTM! Test cases updated consistently with new term subject format.The changes consistently update the term subject format across all test cases to include both underscores and hyphens, properly testing the new allowed characters.
Also applies to: 505-505, 510-510, 515-515, 595-595
519-524
: LGTM! Good coverage of invalid term subject scenarios.The new test cases properly validate the handling of invalid term subjects:
- Empty subjects
- Subjects with spaces
- Subjects with disallowed characters
Also applies to: 526-531, 533-538
Summary by CodeRabbit
Bug Fixes
Documentation