yuseok89 commented on code in PR #77788:
URL: https://github.com/apache/airflow/pull/77788#discussion_r4756843910


##########
providers/samba/tests/unit/samba/fs/test__smb_filesystem.py:
##########
@@ -0,0 +1,144 @@
+#
+# 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.
+from __future__ import annotations
+
+import stat
+from unittest import mock
+
+import pytest
+import smbclient
+from smbclient._os import SMBStatResult
+
+from airflow.providers.samba.fs._smb_filesystem import _IsolatedSMBFileSystem, 
_SMBFileOpener
+
+SMBCLIENT_FUNCTIONS = (
+    "copyfile",
+    "listdir",
+    "makedirs",
+    "open_file",
+    "remove",
+    "rename",
+    "replace",
+    "rmdir",
+    "stat",
+)
+
+
+def make_stat(mode: int) -> SMBStatResult:
+    return SMBStatResult._make([0] * 
len(SMBStatResult._fields))._replace(st_mode=mode)
+
+
[email protected]
+def mock_smbclient():
+    """Replace the smbclient calls that fsspec and the filesystem make, with a 
regular file for ``stat``."""
+    with mock.patch.multiple(
+        smbclient, autospec=True, **dict.fromkeys(SMBCLIENT_FUNCTIONS, 
mock.DEFAULT)
+    ) as m:
+        m["stat"].return_value = make_stat(stat.S_IFREG)
+        yield m
+
+
+def make_fs() -> _IsolatedSMBFileSystem:
+    return _IsolatedSMBFileSystem(
+        host="testhost",
+        username="testuser",
+        password="testpass",
+        encrypt=True,
+        timeout=30,
+        skip_instance_cache=True,
+    )
+
+
+def assert_sends_session(call: mock._Call, fs: _IsolatedSMBFileSystem) -> None:
+    assert call.kwargs["username"] == "testuser"
+    assert call.kwargs["password"] == "testpass"
+    assert call.kwargs["port"] == 445
+    assert call.kwargs["encrypt"] is True
+    assert call.kwargs["connection_timeout"] == 30
+    assert call.kwargs["auth_protocol"] == "negotiate"
+    assert call.kwargs["connection_cache"] is fs._connection_cache
+
+
+class TestAirflowSMBFileSystem:
+    @mock.patch.object(smbclient, "register_session", autospec=True)
+    def test_does_not_connect_on_construction(self, mock_register_session):
+        make_fs()
+
+        mock_register_session.assert_not_called()
+
+    @pytest.mark.parametrize(
+        ("method", "args", "smbclient_function"),
+        [
+            pytest.param("ls", ("/share/dir", False), "listdir", id="ls"),
+            pytest.param("info", ("/share/a.csv",), "stat", id="info"),
+            pytest.param("created", ("/share/a.csv",), "stat", id="created"),
+            pytest.param("modified", ("/share/a.csv",), "stat", id="modified"),
+            pytest.param("mkdir", ("/share/new",), "makedirs", id="mkdir"),
+            pytest.param("makedirs", ("/share/new",), "makedirs", 
id="makedirs"),
+            pytest.param("rmdir", ("/share/old",), "rmdir", id="rmdir"),
+            pytest.param("_rm", ("/share/a.csv",), "remove", id="rm"),

Review Comment:
   Added the `S_IFDIR` case for `_rm`, the `auto_mkdir` cases on 
`/share/dir/a.csv` for `cp_file` and both `_open` branches, and a check that 
`created` and `modified` return their own timestamps. Each of these fails when 
the code it covers is broken.



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

Reply via email to