feat: pre depriciation

This commit is contained in:
Alex committed 2026-04-14 00:19:50 +01:00
1 parent 5fab798707
commit 0f20adcbf4
46 files changed
+5380 -587

No files matched your search

+20
View File
@@ -973,14 +973,21 @@ class TestUpdateAgent:
agent_id = ObjectId()
existing = self._make_existing_agent(agent_id)
mock_col = Mock()
mock_repo = Mock()
mock_col.find_one.return_value = existing
mock_col.update_one.return_value = Mock(matched_count=1, modified_count=1)
mock_handle_img = Mock(return_value=("", None))
def _run_dual_write(_repo_cls, fn):
fn(mock_repo)
with patch(
"application.api.user.agents.routes.agents_collection", mock_col
), patch(
"application.api.user.agents.routes.handle_image_upload", mock_handle_img
), patch(
"application.api.user.agents.routes.dual_write",
side_effect=_run_dual_write,
):
with app.test_request_context(
f"/api/update_agent/{agent_id}",
@@ -993,6 +1000,11 @@ class TestUpdateAgent:
response = UpdateAgent().put(str(agent_id))
assert response.status_code == 200
assert response.json["success"] is True
mock_repo.update_by_legacy_id.assert_called_once_with(
str(agent_id),
"user1",
{"name": "Updated Name"},
)
def test_returns_400_invalid_status(self, app):
from application.api.user.agents.routes import UpdateAgent
@@ -1945,14 +1957,21 @@ class TestDeleteAgent:
agent_id = ObjectId()
mock_col = Mock()
mock_repo = Mock()
mock_col.find_one_and_delete.return_value = {
"_id": agent_id,
"user": "user1",
"agent_type": "classic",
}
def _run_dual_write(_repo_cls, fn):
fn(mock_repo)
with patch(
"application.api.user.agents.routes.agents_collection", mock_col
), patch(
"application.api.user.agents.routes.dual_write",
side_effect=_run_dual_write,
):
with app.test_request_context(f"/api/delete_agent?id={agent_id}"):
from flask import request
@@ -1961,6 +1980,7 @@ class TestDeleteAgent:
response = DeleteAgent().delete()
assert response.status_code == 200
assert response.json["id"] == str(agent_id)
mock_repo.delete_by_legacy_id.assert_called_once_with(str(agent_id), "user1")
def test_deletes_workflow_agent_cleans_up(self, app):
from application.api.user.agents.routes import DeleteAgent
+34
View File
@@ -18,12 +18,19 @@ class TestCreatePrompt:
from application.api.user.prompts.routes import CreatePrompt
mock_collection = Mock()
mock_repo = Mock()
inserted_id = ObjectId()
mock_collection.insert_one.return_value = Mock(inserted_id=inserted_id)
def _run_dual_write(_repo_cls, fn):
fn(mock_repo)
with patch(
"application.api.user.prompts.routes.prompts_collection",
mock_collection,
), patch(
"application.api.user.prompts.routes.dual_write",
side_effect=_run_dual_write,
):
with app.test_request_context(
"/api/create_prompt",
@@ -41,6 +48,12 @@ class TestCreatePrompt:
doc = mock_collection.insert_one.call_args[0][0]
assert doc["name"] == "My Prompt"
assert doc["user"] == "user1"
mock_repo.create.assert_called_once_with(
"user1",
"My Prompt",
"You are helpful.",
legacy_mongo_id=str(inserted_id),
)
def test_returns_401_unauthenticated(self, app):
from application.api.user.prompts.routes import CreatePrompt
@@ -204,10 +217,17 @@ class TestDeletePrompt:
prompt_id = ObjectId()
mock_collection = Mock()
mock_repo = Mock()
def _run_dual_write(_repo_cls, fn):
fn(mock_repo)
with patch(
"application.api.user.prompts.routes.prompts_collection",
mock_collection,
), patch(
"application.api.user.prompts.routes.dual_write",
side_effect=_run_dual_write,
):
with app.test_request_context(
"/api/delete_prompt",
@@ -224,6 +244,7 @@ class TestDeletePrompt:
mock_collection.delete_one.assert_called_once_with(
{"_id": prompt_id, "user": "user1"}
)
mock_repo.delete_by_legacy_id.assert_called_once_with(str(prompt_id), "user1")
def test_returns_400_missing_id(self, app):
from application.api.user.prompts.routes import DeletePrompt
@@ -249,10 +270,17 @@ class TestUpdatePrompt:
prompt_id = ObjectId()
mock_collection = Mock()
mock_repo = Mock()
def _run_dual_write(_repo_cls, fn):
fn(mock_repo)
with patch(
"application.api.user.prompts.routes.prompts_collection",
mock_collection,
), patch(
"application.api.user.prompts.routes.dual_write",
side_effect=_run_dual_write,
):
with app.test_request_context(
"/api/update_prompt",
@@ -271,6 +299,12 @@ class TestUpdatePrompt:
assert response.status_code == 200
assert response.json["success"] is True
mock_collection.update_one.assert_called_once()
mock_repo.update_by_legacy_id.assert_called_once_with(
str(prompt_id),
"user1",
"Updated",
"New content",
)
def test_returns_400_missing_fields(self, app):
from application.api.user.prompts.routes import UpdatePrompt
+3 -1
View File
@@ -200,7 +200,7 @@ class TestSetupPeriodicTasks:
setup_periodic_tasks(sender)
assert sender.add_periodic_task.call_count == 3
assert sender.add_periodic_task.call_count == 4
calls = sender.add_periodic_task.call_args_list
@@ -210,6 +210,8 @@ class TestSetupPeriodicTasks:
assert calls[1][0][0] == timedelta(weeks=1)
# monthly
assert calls[2][0][0] == timedelta(days=30)
# pending_tool_state TTL cleanup (60s)
assert calls[3][0][0] == timedelta(seconds=60)
class TestMcpOauthTask: