Skip to content

Fix misleading names in test_forms.py: rename inner function and camelCase method#868

Merged
chrismaddalena merged 3 commits intomasterfrom
copilot/rename-mock-rate-limit-check-function
Apr 14, 2026
Merged

Fix misleading names in test_forms.py: rename inner function and camelCase method#868
chrismaddalena merged 3 commits intomasterfrom
copilot/rename-mock-rate-limit-check-function

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Two naming issues in ghostwriter/users/tests/test_forms.py: an inner function named clear_rate_limit (implying rate limit clearing) that actually mocks a passing rate-limit check, and a helper method createAuthenticator using camelCase contrary to PEP 8.

Description of the Change

  • clear_rate_limitrate_limit_check: The inner function returned by mock_rate_limit_check() was named after the wrong operation. Renamed to match its actual role as a mock check that always passes.
# Before
def mock_rate_limit_check():
    def clear_rate_limit():
        pass
    return clear_rate_limit

# After
def mock_rate_limit_check():
    def rate_limit_check():
        pass
    return rate_limit_check
  • createAuthenticatorcreate_authenticator: Renamed to snake_case per PEP 8, consistent with other helpers in the same class (e.g., form_data). No call sites exist in the file, so no cascading changes required.

Alternate Designs

The inner function could also be named always_succeed for even more clarity, but rate_limit_check mirrors the patched function's role more directly.

Possible Drawbacks

None. Changes are confined to test helper naming with no effect on production code or test logic.

Verification Process

Confirmed via grep that no call sites reference the old createAuthenticator name. CodeQL scan returned zero alerts.

Release Notes

N/A

Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The function `mock_rate_limit_check` returns a function named `clear_rate_limit`, but based on its usage in the tests (lines 139-141, 195-197, etc.), it appears to be used as a rate limit check function. The name `clear_rate_limit` is misleading as it suggests clearing rate limits rather than checking them. Consider renaming the inner function to `rate_limit_check` or `always_succeed` to better reflect its purpose.","fixFiles":[{"filePath":"ghostwriter/users/tests/test_forms.py","diff":"diff --git a/ghostwriter/users/tests/test_forms.py b/ghostwriter/users/tests/test_forms.py\n--- a/ghostwriter/users/tests/test_forms.py\n+++ b/ghostwriter/users/tests/test_forms.py\n@@ -28,9 +28,9 @@\n # Helper function: returns a mock rate limit check that always succeeds\n def mock_rate_limit_check(): # pragma: no cover\n     \"\"\"Mock rate limit check that always succeeds\"\"\"\n-    def clear_rate_limit():\n+    def rate_limit_check():\n         pass\n-    return clear_rate_limit\n+    return rate_limit_check\n \n # Helper function: Generate a valid TOTP code from a secret\n def get_code_from_totp_device(secret) -> str:\n"}]},{"message":"The method name `createAuthenticator` uses camelCase, which is inconsistent with Python's PEP 8 style guide that recommends snake_case for method names. Consider renaming to `create_authenticator` to match the project's coding conventions and improve consistency with other methods like `form_data`.","fixFiles":[{"filePath":"ghostwriter/users/tests/test_forms.py","diff":"diff --git a/ghostwriter/users/tests/test_forms.py b/ghostwriter/users/tests/test_forms.py\n--- a/ghostwriter/users/tests/test_forms.py\n+++ b/ghostwriter/users/tests/test_forms.py\n@@ -155,7 +155,7 @@\n         self.consume_patcher.stop()\n         self.clear_patcher.stop()  # Stop the new patcher\n \n-    def createAuthenticator(self, user):\n+    def create_authenticator(self, user):\n         \"\"\"Helper function to create an Authenticator instance for a user.\"\"\"\n         return user.totpdevice_set.create()\n \n"}]}]

Copilot AI changed the title [WIP] Rename mock_rate_limit_check function to reflect its purpose Fix misleading names in test_forms.py: rename inner function and camelCase method Apr 14, 2026
Copilot AI requested a review from chrismaddalena April 14, 2026 00:31
@chrismaddalena chrismaddalena marked this pull request as ready for review April 14, 2026 11:41
Copilot AI review requested due to automatic review settings April 14, 2026 11:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses two misleading/inconsistent names in ghostwriter/users/tests/test_forms.py to improve clarity and align with Python naming conventions in the test suite.

Changes:

  • Renamed the inner function returned by mock_rate_limit_check() from clear_rate_limit to rate_limit_check to reflect its actual role (a mock “check” that always succeeds).
  • Renamed the test helper method createAuthenticator to create_authenticator to match PEP 8 snake_case naming.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.21%. Comparing base (1db46ff) to head (523ffc2).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #868   +/-   ##
=======================================
  Coverage   92.21%   92.21%           
=======================================
  Files         384      384           
  Lines       23990    23990           
=======================================
  Hits        22123    22123           
  Misses       1867     1867           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chrismaddalena chrismaddalena merged commit 2694822 into master Apr 14, 2026
8 checks passed
@chrismaddalena chrismaddalena deleted the copilot/rename-mock-rate-limit-check-function branch April 14, 2026 14:26
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.

3 participants