Skip to content

Commit c5ddbe1

Browse files
implemented codeQL and copilot sugestions
1 parent 58678ab commit c5ddbe1

6 files changed

Lines changed: 79 additions & 661 deletions

File tree

src/tests/backend/common/database/test_database_base.py

Lines changed: 68 additions & 624 deletions
Large diffs are not rendered by default.

src/tests/backend/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import os
88
import sys
9-
from pathlib import Path
109
from types import ModuleType
1110
from unittest.mock import Mock, MagicMock
1211

src/tests/backend/test_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
os.environ.setdefault("AZURE_OPENAI_RAI_DEPLOYMENT_NAME", "test-rai-deployment")
3737

3838
# Check if v4 has been mocked by another test file (prevents import errors)
39-
_v4_is_mocked = 'v4' in sys.modules and isinstance(sys.modules['v4'], Mock)
39+
_v4_is_mocked = 'v4' in sys.modules and isinstance(sys.modules['v4'], (Mock, MagicMock))
4040
if _v4_is_mocked:
4141
# Skip this module - v4 has been mocked by another test file
4242
pytest.skip(

src/tests/backend/v4/config/test_settings.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -503,28 +503,6 @@ async def test_close_connection_with_exception(self):
503503
# Connection should still be removed
504504
self.assertNotIn(process_id, config.connections)
505505

506-
async def test_send_status_update_async_success(self):
507-
"""Test sending status update successfully."""
508-
config = ConnectionConfig()
509-
user_id = "user-123"
510-
process_id = "process-456"
511-
message = "Test message"
512-
connection = AsyncMock()
513-
514-
config.add_connection(process_id, connection, user_id)
515-
516-
await config.send_status_update_async(message, user_id)
517-
518-
connection.send_text.assert_called_once()
519-
sent_data = json.loads(connection.send_text.call_args[0][0])
520-
# Verify payload structure - type field exists (may be mocked or real enum value)
521-
self.assertIn('type', sent_data)
522-
# If not mocked, verify actual value
523-
type_val = str(sent_data['type'])
524-
if 'MagicMock' not in type_val:
525-
self.assertEqual(sent_data['type'], 'system_message')
526-
self.assertEqual(sent_data['data'], message)
527-
528506
async def test_send_status_update_async_no_user_id(self):
529507
"""Test sending status update with no user ID."""
530508

@@ -811,7 +789,7 @@ async def approve_task():
811789
result = await config.wait_for_approval(plan_id, timeout=1.0)
812790

813791
self.assertTrue(result)
814-
await approve_task_handle
792+
_ = await approve_task_handle
815793

816794
async def test_wait_for_approval_rejected(self):
817795
"""Test waiting for approval when plan is rejected."""
@@ -828,7 +806,7 @@ async def reject_task():
828806
result = await config.wait_for_approval(plan_id, timeout=1.0)
829807

830808
self.assertFalse(result)
831-
await reject_task_handle
809+
_ = await reject_task_handle
832810

833811
async def test_wait_for_clarification_key_error(self):
834812
"""Test waiting for clarification with non-existent request_id raises KeyError."""
@@ -854,7 +832,7 @@ async def answer_task():
854832
result = await config.wait_for_clarification(request_id, timeout=1.0)
855833

856834
self.assertEqual(result, "User answer")
857-
await answer_task_handle
835+
_ = await answer_task_handle
858836

859837
async def test_wait_for_approval_creates_new_event(self):
860838
"""Test that waiting for approval creates event if not exists."""
@@ -872,7 +850,7 @@ async def approve_task():
872850
result = await config.wait_for_approval(plan_id, timeout=1.0)
873851

874852
self.assertTrue(result)
875-
await approve_task_handle
853+
_ = await approve_task_handle
876854

877855

878856
if __name__ == '__main__':

src/tests/backend/v4/orchestration/helper/test_plan_to_mplan_converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
import unittest
1313
import sys
14-
from unittest.mock import Mock
14+
from unittest.mock import Mock, MagicMock
1515

1616
import pytest
1717

1818
# Check if v4 has been mocked by another test file (prevents import errors)
19-
_v4_is_mocked = 'v4' in sys.modules and isinstance(sys.modules['v4'], Mock)
20-
_v4_models_is_mocked = 'v4.models' in sys.modules and isinstance(sys.modules['v4.models'], Mock)
19+
_v4_is_mocked = 'v4' in sys.modules and isinstance(sys.modules['v4'], (Mock, MagicMock))
20+
_v4_models_is_mocked = 'v4.models' in sys.modules and isinstance(sys.modules['v4.models'], (Mock, MagicMock))
2121
if _v4_is_mocked or _v4_models_is_mocked:
2222
pytest.skip(
2323
"Skipping test_plan_to_mplan_converter.py: v4 module has been mocked by another test file. "

src/tests/backend/v4/orchestration/test_orchestration_manager.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,8 @@ def test_extract_response_text_agent_executor_response_with_agent_response(self)
927927
agent_resp = Mock()
928928
agent_resp.text = "Agent executor response"
929929

930-
executor_resp = Mock()
930+
executor_resp = Mock(spec=['agent_response'])
931931
executor_resp.agent_response = agent_resp
932-
del executor_resp.text # Remove text attr so it falls through
933932

934933
result = self.manager._extract_response_text(executor_resp)
935934
self.assertEqual(result, "Agent executor response")
@@ -941,10 +940,9 @@ def test_extract_response_text_agent_executor_response_fallback_to_conversation(
941940

942941
last_msg = MockChatMessage("Last conversation message")
943942

944-
executor_resp = Mock()
943+
executor_resp = Mock(spec=['agent_response', 'full_conversation'])
945944
executor_resp.agent_response = agent_resp
946945
executor_resp.full_conversation = [MockChatMessage("First"), last_msg]
947-
del executor_resp.text # Remove text attr
948946

949947
result = self.manager._extract_response_text(executor_resp)
950948
self.assertEqual(result, "Last conversation message")
@@ -954,10 +952,9 @@ def test_extract_response_text_agent_executor_response_empty_conversation(self):
954952
agent_resp = Mock()
955953
agent_resp.text = None
956954

957-
executor_resp = Mock()
955+
executor_resp = Mock(spec=['agent_response', 'full_conversation'])
958956
executor_resp.agent_response = agent_resp
959957
executor_resp.full_conversation = []
960-
del executor_resp.text # Remove text attr
961958

962959
result = self.manager._extract_response_text(executor_resp)
963960
self.assertEqual(result, "")

0 commit comments

Comments
 (0)