Skip to content

[fix] Fixed the test script to execute all tests#581

Closed
pandafy wants to merge 1 commit intomasterfrom
fix-tests
Closed

[fix] Fixed the test script to execute all tests#581
pandafy wants to merge 1 commit intomasterfrom
fix-tests

Conversation

@pandafy
Copy link
Copy Markdown
Member

@pandafy pandafy commented Mar 27, 2026

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • N/A I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • N/A I have updated the documentation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

Changes made to the test runner in tests/runtests.py include: updating test_create_prefix_users to dynamically locate the sessionid cookie via get_cookies() instead of assuming the first cookie matches, modifying test_celery task registration expectations by consolidating three separate monitoring auto-create tasks into a single auto_create_check task and removing an unrelated notification task expectation, and simplifying the script entrypoint by replacing explicit unittest.TestSuite and TextTestRunner setup with a direct unittest.main() call.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete, missing critical sections like reference to existing issue, description of changes, and screenshot sections from the template. Add a 'Reference to Existing Issue' section with the issue number, provide a detailed 'Description of Changes' section explaining the modifications, and include any relevant screenshots if applicable.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required [fix] prefix and describes a test-related fix, though it is somewhat generic about what the actual changes accomplish.
Bug Fixes ✅ Passed This PR fixes a test infrastructure issue (test script only executing one test), not core user-facing functionality. Test infrastructure fixes are excluded from regression test requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/runtests.py`:
- Around line 230-235: The loop over self.base_driver.get_cookies() should use a
singular loop variable (cookie) and must explicitly handle the case where no
"sessionid" is found: iterate through cookies (cookie) to build reqHeader when
cookie["name"] == "sessionid", then before calling
request.Request(prefix_pdf_file_path, headers=reqHeader) check if reqHeader is
empty and raise a clear error or fail the test (e.g., RuntimeError or
AssertionError) that includes context (e.g., "sessionid cookie not found" and
the list of cookies) so tests don't silently proceed unauthenticated.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: a40e09a8-b88a-4c07-9e3b-87b12bba80ee

📥 Commits

Reviewing files that changed from the base of the PR and between 76cd872 and 82cfa4e.

📒 Files selected for processing (1)
  • tests/runtests.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: CI Build
🔇 Additional comments (2)
tests/runtests.py (2)

491-492: LGTM!

Using unittest.main(verbosity=2) ensures automatic discovery and execution of all TestCase classes in the module, which directly addresses the PR objective. This is cleaner and more maintainable than explicit TestSuite construction.


367-367: The Celery task consolidation from three separate auto-create tasks to auto_create_check is correct and expected for OpenWISP Monitoring 1.2.x, as confirmed by the project changelog and current Dockerfile configuration. The codebase is properly aligned with this library version, and the test at line 367 correctly reflects the consolidated task name.

Comment on lines +230 to 235
reqHeader = {}
for cookies in self.base_driver.get_cookies():
if cookies["name"] == "sessionid":
reqHeader = {"Cookie": f"sessionid={cookies['value']}"}
break
curlRequest = request.Request(prefix_pdf_file_path, headers=reqHeader)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider explicit handling when sessionid cookie is not found.

The fix correctly avoids assuming cookie order, but if no sessionid cookie exists, reqHeader remains empty and the request proceeds without authentication. This could lead to confusing test failures (e.g., 401/403) without indicating the actual root cause.

Also, the loop variable cookies should be cookie (singular) since each iteration yields a single cookie dict.

Proposed improvement
         reqHeader = {}
-        for cookies in self.base_driver.get_cookies():
-            if cookies["name"] == "sessionid":
-                reqHeader = {"Cookie": f"sessionid={cookies['value']}"}
+        for cookie in self.base_driver.get_cookies():
+            if cookie["name"] == "sessionid":
+                reqHeader = {"Cookie": f"sessionid={cookie['value']}"}
                 break
+        else:
+            self.fail("sessionid cookie not found in browser cookies")
         curlRequest = request.Request(prefix_pdf_file_path, headers=reqHeader)
📝 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
reqHeader = {}
for cookies in self.base_driver.get_cookies():
if cookies["name"] == "sessionid":
reqHeader = {"Cookie": f"sessionid={cookies['value']}"}
break
curlRequest = request.Request(prefix_pdf_file_path, headers=reqHeader)
reqHeader = {}
for cookie in self.base_driver.get_cookies():
if cookie["name"] == "sessionid":
reqHeader = {"Cookie": f"sessionid={cookie['value']}"}
break
else:
self.fail("sessionid cookie not found in browser cookies")
curlRequest = request.Request(prefix_pdf_file_path, headers=reqHeader)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/runtests.py` around lines 230 - 235, The loop over
self.base_driver.get_cookies() should use a singular loop variable (cookie) and
must explicitly handle the case where no "sessionid" is found: iterate through
cookies (cookie) to build reqHeader when cookie["name"] == "sessionid", then
before calling request.Request(prefix_pdf_file_path, headers=reqHeader) check if
reqHeader is empty and raise a clear error or fail the test (e.g., RuntimeError
or AssertionError) that includes context (e.g., "sessionid cookie not found" and
the list of cookies) so tests don't silently proceed unauthenticated.

@github-project-automation github-project-automation bot moved this from To do (general) to In progress in OpenWISP Contributor's Board Mar 27, 2026
@pandafy pandafy closed this Mar 27, 2026
@github-project-automation github-project-automation bot moved this from In progress to Done in OpenWISP Contributor's Board Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant