rebenitez1802 commented on code in PR #43994:
URL: https://github.com/apache/superset/pull/43994#discussion_r3967082037


##########
tests/unit_tests/models/sql_lab_test.py:
##########
@@ -159,6 +159,49 @@ def _compile(column_element) -> str:
     )
 
 
[email protected](
+    ("catalog", "schema", "database_name", "expected"),
+    [
+        (None, "s1", "db", "[db].[s1]"),
+        ("cat", "s1", "db", "[db].[cat].[s1]"),
+        (None, None, "db", ""),
+    ],
+)
+def test_query_schema_perm(catalog, schema, database_name, expected) -> None:
+    """Query.schema_perm yields the canonical bracketed permission string.
+
+    Regression test for the schema_access explore fix: the property must
+    delegate to security_manager.get_schema_perm (which produces the format
+    created by sync_permissions) so that can_access_schema can match granted
+    schema_access, and must not raise when the schema is unset.
+    """
+    database = MagicMock()
+    database.database_name = database_name
+    query = Query(sql="SELECT * FROM t1", schema=schema, catalog=catalog)
+    query.database = database
+    with patch.object(
+        sql_lab_module.security_manager,
+        "get_schema_perm",
+        return_value=expected or None,
+    ) as mock_get_schema_perm:
+        result = query.schema_perm
+        assert result == expected
+        if expected:
+            mock_get_schema_perm.assert_called_once_with(database_name, 
catalog, schema)
+        else:
+            mock_get_schema_perm.assert_called_once_with(database_name, 
catalog, schema)

Review Comment:
   Both branches of this `if`/`else` are identical, so the conditional is dead 
— collapse to a single unconditional assertion.
   
   ```suggestion
           mock_get_schema_perm.assert_called_once_with(database_name, catalog, 
schema)
   ```



-- 
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