Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mdkaifansari04
Copy link
Contributor

@mdkaifansari04 mdkaifansari04 commented Nov 8, 2025

Fixes: #4751
Description:
The GitHub Actions test workflow was failing due to Django being unable to import the tests module correctly.

Error message:

ImportError: 'tests' module incorrectly imported from '/home/runner/work/BLT/BLT/website/tests'. Expected '/home/runner/work/BLT/BLT/website'.

This PR moves the tests folder to the proper location within the app structure so Django can discover and execute tests as expected.
Also verified that the directory contains an init.py file to ensure it’s recognized as a valid module.

Passed all the test in my forked repo.
image

Summary by CodeRabbit

  • Chores
    • Updated internal test module imports for better code organization.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 8, 2025

Walkthrough

Updated import statements in the test module to reference models from the parent package level instead of the current package, changing relative import path from .models to ..models for Activity, ContentType, and Domain classes.

Changes

Cohort / File(s) Summary
Import path correction
website/tests/test_main.py
Updated relative imports to reference parent package—changed from .models to ..models for Activity, ContentType, Domain class imports

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

  • Verify the import path change is correct and the parent package structure supports accessing models from the new path
  • Confirm all affected classes (Activity, ContentType, Domain) are properly exported from the parent package's models module

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: fixing test file placement for Django test discovery by updating import paths in test files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

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

Copy link
Contributor

@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 (3)
website/tests/test_main.py (3)

35-35: Avoid hardcoding the live server port to reduce CI flakiness.

Hardcoding DJANGO_LIVE_TEST_SERVER_ADDRESS = "localhost:8082" can collide if the port is in use on CI runners. Let Django pick a free port unless a fixed port is required.

-os.environ["DJANGO_LIVE_TEST_SERVER_ADDRESS"] = "localhost:8082"
+# Prefer default ephemeral port selection to avoid collisions on CI:
+# os.environ["DJANGO_LIVE_TEST_SERVER_ADDRESS"] = "localhost:8082"

78-83: Modernize Selenium locators and waits (Selenium 4).

Use By.* locators consistently (you already import By) and favor WebDriverWait over time.sleep for stability. This reduces deprecation warnings and flakes.

Example pattern:

-username = self.selenium.find_element("name", "username")
+username = self.selenium.find_element(By.NAME, "username")

-# Wait for any animations to complete
-time.sleep(1)
+# Wait for the button to be clickable instead of sleeping
+WebDriverWait(self.selenium, 10).until(EC.element_to_be_clickable((By.NAME, "signup_button")))

Repeat similarly for other find_element("name"/"id"/"tag name", ...) calls in these ranges.

Also applies to: 91-94, 99-104, 136-139, 150-153, 158-165, 175-178, 180-188


237-244: Use direct assertion helpers for clarity.

Replace unconditional asserts with direct intent‑revealing helpers.

-            if default_storage.exists(filename):
-                self.assertTrue(False, "files exist")
+            self.assertFalse(default_storage.exists(filename), "Screenshot file should be removed from storage")
...
-            if "hidden" not in filename:
-                self.assertFalse(True, "files rename failed")
+            self.assertIn("hidden", filename, "files rename failed")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 9fe68cd and 5cb0751.

📒 Files selected for processing (1)
  • website/tests/test_main.py (1 hunks)
⏰ 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). (2)
  • GitHub Check: Run Tests
  • GitHub Check: docker-test
🔇 Additional comments (1)
website/tests/test_main.py (1)

20-33: Import path fix is correct; refactoring suggestion is based on incorrect module analysis and is unnecessary.

Switching from .models to ..models is the correct fix now that tests live in website/tests/. However, the refactoring recommendation is based on a misunderstanding: ContentType and User are already legitimately available from website.models because website/models.py imports them directly from Django at lines 16 and 18:

from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType

Since website/models.py is a module file (not a package directory), these imports are automatically available for re-export to test code. The current import at lines 20–33 will work correctly as written—no refactoring needed.

Likely an incorrect or invalid review comment.

@github-project-automation github-project-automation bot moved this from Backlog to Ready in 📌 OWASP BLT Project Board Nov 8, 2025
@DonnieBLT DonnieBLT merged commit d183487 into OWASP-BLT:main Nov 8, 2025
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

CI/CD : Test workflow failing due to incorrect test file placement

2 participants