codeant-ai-for-open-source[bot] commented on code in PR #40128:
URL: https://github.com/apache/superset/pull/40128#discussion_r3501523894


##########
tests/unit_tests/commands/dashboard/restore_test.py:
##########
@@ -0,0 +1,201 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Unit tests for RestoreDashboardCommand."""
+
+from __future__ import annotations
+
+from datetime import datetime, timezone
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+
+def test_restore_dashboard_not_found_raises(app_context: None) -> None:
+    """RestoreDashboardCommand raises DashboardNotFoundError for missing 
dashboard."""
+    from superset.commands.dashboard.exceptions import DashboardNotFoundError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    with patch("superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=None):
+        cmd = RestoreDashboardCommand("999")
+        with pytest.raises(DashboardNotFoundError):
+            cmd.run()
+
+
+def test_restore_active_dashboard_raises_not_found(app_context: None) -> None:
+    """RestoreDashboardCommand raises DashboardNotFoundError for non-deleted 
dashboard."""  # noqa: E501
+    from superset.commands.dashboard.exceptions import DashboardNotFoundError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    dashboard = MagicMock()
+    dashboard.deleted_at = None  # not soft-deleted
+
+    with patch(
+        "superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=dashboard
+    ):
+        cmd = RestoreDashboardCommand("1")
+        with pytest.raises(DashboardNotFoundError):
+            cmd.run()
+
+
+def test_restore_dashboard_forbidden_raises(app_context: None) -> None:
+    """RestoreDashboardCommand raises DashboardForbiddenError on permission 
check."""
+    from superset.commands.dashboard.exceptions import DashboardForbiddenError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+    from superset.exceptions import SupersetSecurityException
+
+    dashboard = MagicMock()
+    dashboard.deleted_at = datetime(2026, 1, 1, tzinfo=timezone.utc)
+
+    def raise_security(*args: object, **kwargs: object) -> None:
+        raise SupersetSecurityException(MagicMock())
+
+    with (
+        patch(
+            "superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=dashboard
+        ),
+        patch("superset.commands.restore.security_manager") as mock_sec,
+    ):
+        mock_sec.raise_for_ownership = raise_security
+
+        cmd = RestoreDashboardCommand("1")
+        with pytest.raises(DashboardForbiddenError):
+            cmd.run()
+
+
+def test_restore_dashboard_slug_conflict_raises(app_context: None) -> None:
+    """Restore raises DashboardSlugConflictError when slug is now claimed by 
an active dashboard.
+
+    The partial unique index ``WHERE deleted_at IS NULL`` allows another
+    dashboard to claim the slug while this one was soft-deleted. The
+    command catches that case before flushing so the operator sees a
+    domain-specific error instead of an opaque unique-index violation.
+    """  # noqa: E501
+    from superset.commands.dashboard.exceptions import 
DashboardSlugConflictError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    dashboard = MagicMock()
+    dashboard.deleted_at = datetime(2026, 1, 1, tzinfo=timezone.utc)
+    dashboard.slug = "q1-report"
+    dashboard.id = 42
+
+    with (
+        patch(
+            "superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=dashboard
+        ),
+        patch("superset.commands.restore.security_manager") as mock_sec,
+        patch.object(
+            RestoreDashboardCommand, "_has_active_slug_twin", return_value=True
+        ) as mock_twin_check,

Review Comment:
   **Suggestion:** Add a type annotation for the `mock_twin_check` alias 
created in the context manager to keep relevant mocked variables explicitly 
typed. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The alias `mock_twin_check` is a new variable used later in assertions, but 
it is not type-annotated. Since it is a relevant local variable in new Python 
code, the type-hint rule applies here.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0e60f859a4444a87ab57dd1da345fcac&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0e60f859a4444a87ab57dd1da345fcac&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/commands/dashboard/restore_test.py
   **Line:** 100:102
   **Comment:**
        *Custom Rule: Add a type annotation for the `mock_twin_check` alias 
created in the context manager to keep relevant mocked variables explicitly 
typed.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40128&comment_hash=2fe20be546153db0c4a93a9c152ab561a56297b39c92d1d48537599d5eb5dea4&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40128&comment_hash=2fe20be546153db0c4a93a9c152ab561a56297b39c92d1d48537599d5eb5dea4&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to