Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions backend/apps/ai/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,8 +92,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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from collections import defaultdict
from datetime import UTC, datetime
from datetime import UTC, datetime, timedelta

from django.contrib.contenttypes.models import ContentType
from django.core.management.base import BaseCommand
Expand Down Expand Up @@ -87,8 +87,6 @@ def generate_heatmap_data(self, commits, pull_requests, issues, start_at, end_at
dict: Mapping of date strings (YYYY-MM-DD) to contribution counts.

"""
from datetime import timedelta

# Initialize all dates in range with 0
heatmap_data: dict[str, int] = {}
current_date = start_at.date()
Expand Down Expand Up @@ -250,8 +248,6 @@ def generate_communication_heatmap_data(self, messages, start_at, end_at) -> dic
dict: Mapping of date strings (YYYY-MM-DD) to message counts (all dates initialized).

"""
from datetime import timedelta

# Initialize all dates in range with 0
heatmap_data: dict[str, int] = {}
current_date = start_at.date()
Expand Down
12 changes: 11 additions & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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/
Expand Down Expand Up @@ -121,6 +120,17 @@ lint.per-file-ignores."apps/api/rest/**/*.py" = [
"ARG001", # https://docs.astral.sh/ruff/rules/unused-function-argument/
"B008", # https://docs.astral.sh/ruff/rules/function-call-in-default-argument/
]
lint.per-file-ignores."apps/github/models/mixins/*.py" = [ "PLC0415" ]
lint.per-file-ignores."apps/github/models/user.py" = [ "PLC0415" ]
lint.per-file-ignores."apps/mentorship/apps.py" = [ "PLC0415" ]
lint.per-file-ignores."apps/slack/apps.py" = [ "PLC0415" ]
lint.per-file-ignores."apps/slack/commands/*.py" = [ "PLC0415" ]
lint.per-file-ignores."apps/slack/common/handlers/*.py" = [ "PLC0415" ]
lint.per-file-ignores."apps/slack/events/**/*.py" = [ "PLC0415" ]
lint.per-file-ignores."apps/slack/utils.py" = [ "PLC0415" ]
lint.per-file-ignores."tests/apps/github/management/commands/github_get_installation_id_test.py" = [ "PLC0415" ]
lint.per-file-ignores."tests/apps/slack/events/message_posted_test.py" = [ "PLC0415" ]
lint.per-file-ignores."tests/apps/slack/views_test.py" = [ "PLC0415" ]

[tool.pytest]
ini_options.DJANGO_CONFIGURATION = "Test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions backend/tests/apps/ai/models/chunk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,4 @@ def test_meta_class_attributes(self):

def test_context_relationship(self):
context_field = Chunk._meta.get_field("context")
from apps.ai.models.context import Context

assert context_field.related_model == Context
15 changes: 5 additions & 10 deletions backend/tests/apps/ai/models/context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError

from apps.ai.models.context import Context
from apps.common.models import TimestampedModel
Expand Down Expand Up @@ -107,8 +108,6 @@ def test_context_validation(self, mock_full_clean):

@patch("apps.ai.models.context.Context.full_clean")
def test_context_validation_source_too_long(self, mock_full_clean):
from django.core.exceptions import ValidationError

mock_full_clean.side_effect = ValidationError("Source too long")

context = Context()
Expand Down Expand Up @@ -299,9 +298,7 @@ def test_str_method_fallback_to_str(self):
@patch("apps.ai.models.context.Context.__init__")
def test_update_data_new_context_with_save(self, mock_init, mock_get):
"""Test update_data creating a new context with save=True."""
from apps.ai.models.context import Context as ContextModel

mock_get.side_effect = ContextModel.DoesNotExist
mock_get.side_effect = Context.DoesNotExist
mock_init.return_value = None # __init__ should return None

content = "New test content"
Expand All @@ -317,7 +314,7 @@ def test_update_data_new_context_with_save(self, mock_init, mock_get):
mock_get_for_model.return_value = mock_content_type

# Mock the context instance and its save method
with patch.object(ContextModel, "save") as mock_save:
with patch.object(Context, "save") as mock_save:
result = Context.update_data(
content, mock_content_object, source=source, save=True
)
Expand All @@ -340,9 +337,7 @@ def test_update_data_new_context_with_save(self, mock_init, mock_get):
@patch("apps.ai.models.context.Context.__init__")
def test_update_data_new_context_without_save(self, mock_init, mock_get):
"""Test update_data creating a new context with save=False."""
from apps.ai.models.context import Context as ContextModel

mock_get.side_effect = ContextModel.DoesNotExist
mock_get.side_effect = Context.DoesNotExist
mock_init.return_value = None # __init__ should return None

content = "New test content"
Expand All @@ -358,7 +353,7 @@ def test_update_data_new_context_without_save(self, mock_init, mock_get):
mock_get_for_model.return_value = mock_content_type

# Mock the context instance and its save method
with patch.object(ContextModel, "save") as mock_save:
with patch.object(Context, "save") as mock_save:
result = Context.update_data(
content, mock_content_object, source=source, save=False
)
Expand Down
6 changes: 2 additions & 4 deletions backend/tests/apps/api/rest/v0/snapshot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from apps.api.rest.v0.snapshot import (
SnapshotDetail,
SnapshotIssue,
SnapshotRelease,
get_snapshot,
list_snapshot_chapters,
list_snapshot_issues,
Expand Down Expand Up @@ -242,8 +244,6 @@ def test_list_snapshot_releases_success(self, mock_filter):
assert response[0].tag_name == self.release.tag_name

def test_snapshot_issue_resolver_no_organization(self):
from apps.api.rest.v0.snapshot import SnapshotIssue

issue = MagicMock(spec=Issue)
issue.repository = MagicMock()
issue.repository.organization = None
Expand All @@ -253,8 +253,6 @@ def test_snapshot_issue_resolver_no_organization(self):
assert SnapshotIssue.resolve_repository_name(issue) == "test-repo"

def test_snapshot_release_resolver_no_organization(self):
from apps.api.rest.v0.snapshot import SnapshotRelease

release = MagicMock(spec=Release)
release.repository = MagicMock()
release.repository.organization = None
Expand Down
Loading