diff --git a/backend/apps/ai/common/utils.py b/backend/apps/ai/common/utils.py index 8a258f7f3b..154bbff6d3 100644 --- a/backend/apps/ai/common/utils.py +++ b/backend/apps/ai/common/utils.py @@ -40,8 +40,6 @@ def create_chunks_and_embeddings( ValueError: If context is None or invalid """ - from apps.ai.models.chunk import Chunk - try: last_request_time = datetime.now(UTC) - timedelta( seconds=DEFAULT_LAST_REQUEST_OFFSET_SECONDS @@ -77,8 +75,6 @@ def regenerate_chunks_for_context(context: Context): context (Context): The specific context instance to be updated. """ - from apps.ai.models.chunk import Chunk - context.chunks.all().delete() new_chunk_texts = Chunk.split_text(context.content) diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 1192dad228..0ccdf88983 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -75,7 +75,6 @@ lint.ignore = [ "D407", # https://docs.astral.sh/ruff/rules/missing-dashed-underline-after-section/ "DJ012", # https://docs.astral.sh/ruff/rules/django-unordered-body-content-in-model/ "FIX002", # https://docs.astral.sh/ruff/rules/line-contains-todo/ - "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ "PLR0912", # https://docs.astral.sh/ruff/rules/too-many-branches/ "PLR0913", # https://docs.astral.sh/ruff/rules/too-many-arguments/ "PLR0915", # https://docs.astral.sh/ruff/rules/too-many-statements/ @@ -120,6 +119,56 @@ lint.per-file-ignores."**/tests/**/*.py" = [ "SLF001", # https://docs.astral.sh/ruff/rules/private-member-access/ ] +# specific files that need PLC0415 ignored +lint.per-file-ignores."apps/github/models/mixins/organization.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/github/models/mixins/user.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/mentorship/apps.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/slack/apps.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/slack/commands/events.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/slack/commands/leaders.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/slack/common/handlers/chapters.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/slack/common/handlers/committees.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/slack/common/handlers/contribute.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/slack/common/handlers/projects.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/slack/common/handlers/users.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/slack/events/member_joined_channel/contribute.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."apps/slack/utils.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."tests/apps/ai/models/chunk_test.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."tests/apps/ai/models/context_test.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] +lint.per-file-ignores."tests/apps/slack/views_test.py" = [ + "PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ +] + [tool.pytest.ini_options] DJANGO_CONFIGURATION = "Test" DJANGO_SETTINGS_MODULE = "settings.test" diff --git a/backend/tests/apps/ai/management/commands/ai_update_chapter_chunks_test.py b/backend/tests/apps/ai/management/commands/ai_update_chapter_chunks_test.py index 7df18a89bd..f846e33501 100644 --- a/backend/tests/apps/ai/management/commands/ai_update_chapter_chunks_test.py +++ b/backend/tests/apps/ai/management/commands/ai_update_chapter_chunks_test.py @@ -4,6 +4,7 @@ from django.core.management.base import BaseCommand from apps.ai.management.commands.ai_update_chapter_chunks import Command +from apps.owasp.models.chapter import Chapter @pytest.fixture @@ -24,8 +25,6 @@ def test_command_inheritance(self, command): assert isinstance(command, BaseCommand) def test_model_class_property(self, command): - from apps.owasp.models.chapter import Chapter - assert command.model_class == Chapter def test_entity_name_property(self, command): diff --git a/backend/tests/apps/ai/management/commands/ai_update_chapter_context_test.py b/backend/tests/apps/ai/management/commands/ai_update_chapter_context_test.py index 792e2f2f02..5a8d637c5b 100644 --- a/backend/tests/apps/ai/management/commands/ai_update_chapter_context_test.py +++ b/backend/tests/apps/ai/management/commands/ai_update_chapter_context_test.py @@ -4,7 +4,9 @@ import pytest +from apps.ai.common.base.context_command import BaseContextCommand from apps.ai.management.commands.ai_update_chapter_context import Command +from apps.owasp.models.chapter import Chapter @pytest.fixture @@ -23,8 +25,6 @@ def mock_chapter(): class TestAiCreateChapterContextCommand: def test_command_inheritance(self, command): """Test that the command inherits from BaseContextCommand.""" - from apps.ai.common.base.context_command import BaseContextCommand - assert isinstance(command, BaseContextCommand) def test_command_help_text(self, command): @@ -33,8 +33,6 @@ def test_command_help_text(self, command): def test_model_class_property(self, command): """Test the model_class property returns Chapter.""" - from apps.owasp.models.chapter import Chapter - assert command.model_class == Chapter def test_entity_name_property(self, command): diff --git a/backend/tests/apps/ai/management/commands/ai_update_committee_chunks_test.py b/backend/tests/apps/ai/management/commands/ai_update_committee_chunks_test.py index e889fe5b11..2244b6c5d1 100644 --- a/backend/tests/apps/ai/management/commands/ai_update_committee_chunks_test.py +++ b/backend/tests/apps/ai/management/commands/ai_update_committee_chunks_test.py @@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand from apps.ai.management.commands.ai_update_committee_chunks import Command +from apps.owasp.models.committee import Committee @pytest.fixture @@ -35,8 +36,6 @@ def test_command_inheritance(self, command): def test_model_class_method(self, command): """Test the model_class method returns Committee.""" - from apps.owasp.models.committee import Committee - assert command.model_class == Committee def test_entity_name_method(self, command): diff --git a/backend/tests/apps/ai/management/commands/ai_update_committee_context_test.py b/backend/tests/apps/ai/management/commands/ai_update_committee_context_test.py index 6c1940dca1..65fecc20d4 100644 --- a/backend/tests/apps/ai/management/commands/ai_update_committee_context_test.py +++ b/backend/tests/apps/ai/management/commands/ai_update_committee_context_test.py @@ -4,7 +4,9 @@ import pytest +from apps.ai.common.base.context_command import BaseContextCommand from apps.ai.management.commands.ai_update_committee_context import Command +from apps.owasp.models.committee import Committee @pytest.fixture @@ -30,8 +32,6 @@ class TestAiCreateCommitteeContextCommand: def test_command_inheritance(self, command): """Test that the command inherits from BaseContextCommand.""" - from apps.ai.common.base.context_command import BaseContextCommand - assert isinstance(command, BaseContextCommand) def test_command_help_text(self, command): @@ -40,8 +40,6 @@ def test_command_help_text(self, command): def test_model_class_method(self, command): """Test the model_class method returns Committee.""" - from apps.owasp.models.committee import Committee - assert command.model_class == Committee def test_entity_name_method(self, command): diff --git a/backend/tests/apps/ai/management/commands/ai_update_event_chunks_test.py b/backend/tests/apps/ai/management/commands/ai_update_event_chunks_test.py index 298b50b185..b72307f09d 100644 --- a/backend/tests/apps/ai/management/commands/ai_update_event_chunks_test.py +++ b/backend/tests/apps/ai/management/commands/ai_update_event_chunks_test.py @@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand from apps.ai.management.commands.ai_update_event_chunks import Command +from apps.owasp.models.event import Event @pytest.fixture @@ -32,8 +33,6 @@ def test_command_inheritance(self, command): def test_model_class_property(self, command): """Test the model_class property returns Event.""" - from apps.owasp.models.event import Event - assert command.model_class == Event def test_entity_name_property(self, command): diff --git a/backend/tests/apps/ai/management/commands/ai_update_event_context_test.py b/backend/tests/apps/ai/management/commands/ai_update_event_context_test.py index 8f4d2d12ce..6159cbffb8 100644 --- a/backend/tests/apps/ai/management/commands/ai_update_event_context_test.py +++ b/backend/tests/apps/ai/management/commands/ai_update_event_context_test.py @@ -4,7 +4,9 @@ import pytest +from apps.ai.common.base.context_command import BaseContextCommand from apps.ai.management.commands.ai_update_event_context import Command +from apps.owasp.models.event import Event @pytest.fixture @@ -23,8 +25,6 @@ def mock_event(): class TestAiCreateEventContextCommand: def test_command_inheritance(self, command): """Test that the command inherits from BaseContextCommand.""" - from apps.ai.common.base.context_command import BaseContextCommand - assert isinstance(command, BaseContextCommand) def test_command_help_text(self, command): @@ -33,8 +33,6 @@ def test_command_help_text(self, command): def test_model_class_property(self, command): """Test the model_class property returns Event.""" - from apps.owasp.models.event import Event - assert command.model_class == Event def test_entity_name_property(self, command): diff --git a/backend/tests/apps/ai/management/commands/ai_update_project_chunks_test.py b/backend/tests/apps/ai/management/commands/ai_update_project_chunks_test.py index 85f889ddaf..ac731a9ace 100644 --- a/backend/tests/apps/ai/management/commands/ai_update_project_chunks_test.py +++ b/backend/tests/apps/ai/management/commands/ai_update_project_chunks_test.py @@ -4,6 +4,7 @@ from django.core.management.base import BaseCommand from apps.ai.management.commands.ai_update_project_chunks import Command +from apps.owasp.models.project import Project @pytest.fixture @@ -24,8 +25,6 @@ def test_command_inheritance(self, command): assert isinstance(command, BaseCommand) def test_model_class_property(self, command): - from apps.owasp.models.project import Project - assert command.model_class == Project def test_entity_name_property(self, command): diff --git a/backend/tests/apps/ai/management/commands/ai_update_project_context_test.py b/backend/tests/apps/ai/management/commands/ai_update_project_context_test.py index 82df257634..c7958c150b 100644 --- a/backend/tests/apps/ai/management/commands/ai_update_project_context_test.py +++ b/backend/tests/apps/ai/management/commands/ai_update_project_context_test.py @@ -2,7 +2,9 @@ import pytest +from apps.ai.common.base.context_command import BaseContextCommand from apps.ai.management.commands.ai_update_project_context import Command +from apps.owasp.models.project import Project @pytest.fixture @@ -21,8 +23,6 @@ def mock_project(): class TestAiCreateProjectContextCommand: def test_command_inheritance(self, command): """Test that the command inherits from BaseContextCommand.""" - from apps.ai.common.base.context_command import BaseContextCommand - assert isinstance(command, BaseContextCommand) def test_command_help_text(self, command): @@ -31,8 +31,6 @@ def test_command_help_text(self, command): def test_model_class_property(self, command): """Test the model_class property returns Project.""" - from apps.owasp.models.project import Project - assert command.model_class == Project def test_entity_name_property(self, command): diff --git a/backend/tests/apps/ai/management/commands/ai_update_slack_message_chunks_test.py b/backend/tests/apps/ai/management/commands/ai_update_slack_message_chunks_test.py index 22c9db9772..b220b544cb 100644 --- a/backend/tests/apps/ai/management/commands/ai_update_slack_message_chunks_test.py +++ b/backend/tests/apps/ai/management/commands/ai_update_slack_message_chunks_test.py @@ -4,6 +4,7 @@ from django.core.management.base import BaseCommand from apps.ai.management.commands.ai_update_slack_message_chunks import Command +from apps.slack.models.message import Message @pytest.fixture @@ -24,8 +25,6 @@ def test_command_inheritance(self, command): assert isinstance(command, BaseCommand) def test_model_class_property(self, command): - from apps.slack.models.message import Message - assert command.model_class == Message def test_entity_name_property(self, command): diff --git a/backend/tests/apps/ai/management/commands/ai_update_slack_message_context_test.py b/backend/tests/apps/ai/management/commands/ai_update_slack_message_context_test.py index 2d6ea5fec3..6765ec9f9f 100644 --- a/backend/tests/apps/ai/management/commands/ai_update_slack_message_context_test.py +++ b/backend/tests/apps/ai/management/commands/ai_update_slack_message_context_test.py @@ -2,7 +2,9 @@ import pytest +from apps.ai.common.base.context_command import BaseContextCommand from apps.ai.management.commands.ai_update_slack_message_context import Command +from apps.slack.models.message import Message @pytest.fixture @@ -21,14 +23,10 @@ def mock_message(): class TestAiCreateSlackMessageContextCommand: def test_command_inheritance(self, command): """Test that the command inherits from BaseContextCommand.""" - from apps.ai.common.base.context_command import BaseContextCommand - assert isinstance(command, BaseContextCommand) def test_model_class_property(self, command): """Test the model_class property returns Message.""" - from apps.slack.models.message import Message - assert command.model_class == Message def test_entity_name_property(self, command): diff --git a/backend/tests/apps/github/management/commands/github_get_installation_id_test.py b/backend/tests/apps/github/management/commands/github_get_installation_id_test.py index 0389c5563d..f60bb5f2cc 100644 --- a/backend/tests/apps/github/management/commands/github_get_installation_id_test.py +++ b/backend/tests/apps/github/management/commands/github_get_installation_id_test.py @@ -6,6 +6,8 @@ import pytest from django.test import SimpleTestCase +from apps.github.management.commands.github_get_installation_id import Command + class TestGitHubGetInstallationId(SimpleTestCase): """Test the GitHub get installation ID management command.""" @@ -22,8 +24,6 @@ def setUp(self): @mock.patch("apps.github.management.commands.github_get_installation_id.Auth.AppAuth") def test_get_installation_id_success(self, mock_app_auth, mock_github_integration): """Test successful retrieval of installation ID.""" - from apps.github.management.commands.github_get_installation_id import Command - # Mock the installation mock_installation = mock.MagicMock() mock_installation.id = 12345 @@ -57,8 +57,6 @@ def test_get_installation_id_success(self, mock_app_auth, mock_github_integratio @mock.patch("apps.github.management.commands.github_get_installation_id.Auth.AppAuth") def test_get_installation_id_no_installations(self, mock_app_auth, mock_github_integration): """Test when no installations are found.""" - from apps.github.management.commands.github_get_installation_id import Command - # Mock empty installations mock_gi_instance = mock.MagicMock() mock_gi_instance.get_installations.return_value = [] @@ -78,16 +76,12 @@ def test_get_installation_id_no_installations(self, mock_app_auth, mock_github_i def test_get_installation_id_no_app_id(self): """Test when no app ID is provided.""" - from apps.github.management.commands.github_get_installation_id import Command - command = Command() with pytest.raises(SystemExit): command.handle() def test_get_installation_id_private_key_file_not_found(self): """Test when private key file is not found.""" - from apps.github.management.commands.github_get_installation_id import Command - command = Command() with ( mock.patch("pathlib.Path.exists", return_value=False), @@ -97,8 +91,6 @@ def test_get_installation_id_private_key_file_not_found(self): def test_get_installation_id_empty_private_key_file(self): """Test when private key file is empty.""" - from apps.github.management.commands.github_get_installation_id import Command - command = Command() with ( mock.patch("pathlib.Path.open", mock.mock_open(read_data="")), @@ -109,8 +101,6 @@ def test_get_installation_id_empty_private_key_file(self): def test_get_installation_id_with_custom_private_key_file(self): """Test with custom private key file path.""" - from apps.github.management.commands.github_get_installation_id import Command - custom_key_path = "/custom/path/key.pem" command = Command() @@ -130,8 +120,6 @@ def test_get_installation_id_with_environment_app_id( self, mock_app_auth, mock_github_integration ): """Test using app ID from environment variable.""" - from apps.github.management.commands.github_get_installation_id import Command - mock_gi_instance = mock.MagicMock() mock_gi_instance.get_installations.return_value = [] mock_github_integration.return_value = mock_gi_instance