Skip to content
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

Open
wants to merge 3 commits into
base: development
Choose a base branch
from

Conversation

FelixFrizzy
Copy link
Collaborator

@FelixFrizzy FelixFrizzy commented Jan 9, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Updated input validation for vocabulary and term subjects to allow underscores and hyphens.
    • Improved error messages to provide clearer guidance on acceptable input characters.
  • Documentation

    • Enhanced user-facing input field titles with more precise character restriction descriptions.

Copy link

coderabbitai bot commented Jan 9, 2025

Walkthrough

The 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

File Change Summary
evoks/theme/templates/modals/create_vocabulary.html Updated input field title to clarify allowed characters (alphanumeric, underscore, hyphen)
evoks/vocabularies/views.py Modified terms function validation to permit underscores and hyphens in term_subject, with improved error messaging
evoks/tests/views/test_vocabulary_views.py Updated test cases to reflect new term subject format and added tests for invalid subjects

Possibly related PRs

Poem

🐰 A Rabbit's Validation Verse 🔍

Underscores and hyphens dance with glee,
No spaces shall disrupt our spree!
Alphanumeric, clean and bright,
Our input rules now shine just right.
Validation's magic, precise and clear! 🎉

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 00c88f8 and dc6eaeb.

📒 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)"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
title="error, only alphanumberic characters, underscore (_) or hyphen (-) allowed (no blanks)"
title="error, only alphanumeric characters, underscore (_) or hyphen (-) allowed (no blanks)"

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.91%. Comparing base (c840e4f) to head (f6b5d11).
Report is 7 commits behind head on development.

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.
📢 Have feedback on the report? Share it here.

- Tests reflect the allowed characters of term subjects (term ids)
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: 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:

  1. Verify error messages for each validation failure
  2. Test maximum length validation (if applicable)
  3. 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

📥 Commits

Reviewing files that changed from the base of the PR and between dc6eaeb and f6b5d11.

📒 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

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.

1 participant