nagasrisai commented on code in PR #64575:
URL: https://github.com/apache/airflow/pull/64575#discussion_r3026116829


##########
providers/salesforce/tests/unit/salesforce/operators/test_bulk_retry.py:
##########
@@ -0,0 +1,187 @@
+# 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
+
+from unittest import mock
+
+import pytest
+
+from airflow.providers.salesforce.operators.bulk import SalesforceBulkOperator
+
+
+def _make_op(**kwargs):
+    defaults = dict(
+        task_id="test_task",
+        operation="insert",
+        object_name="Contact",
+        payload=[{"FirstName": "Ada"}, {"FirstName": "Grace"}],
+    )
+    defaults.update(kwargs)
+    return SalesforceBulkOperator(**defaults)
+
+
+def _transient_failure(status_code="UNABLE_TO_LOCK_ROW"):
+    return {"success": False, "errors": [{"statusCode": status_code, 
"message": "locked", "fields": []}]}
+
+
+def _permanent_failure():
+    return {"success": False, "errors": [{"statusCode": 
"REQUIRED_FIELD_MISSING", "message": "missing", "fields": ["Name"]}]}
+
+
+def _success():
+    return {"success": True, "errors": []}
+
+
+class TestSalesforceBulkOperatorRetry:
+    def test_no_retry_when_max_retries_zero(self):
+        op = _make_op(max_retries=0)
+        assert op.max_retries == 0
+
+        bulk_mock = mock.MagicMock()
+        bulk_mock.__getattr__("Contact").insert.return_value = [_success(), 
_success()]
+
+        with 
mock.patch("airflow.providers.salesforce.operators.bulk.SalesforceHook") as 
hook_cls:
+            
hook_cls.return_value.get_conn.return_value.__getattr__.return_value = bulk_mock
+            result = op.execute(context={})
+

Review Comment:
   I've kept plain `MagicMock` for now because the bulk object is accessed via 
`__getattr__` (e.g. `bulk.__getattr__("Contact").insert`), so `create_autospec` 
on a `SFBulkHandler` would need the real class importable in the test 
environment and the attribute-access chain still needs special handling. The 
tests are focused on the retry logic rather than the hook interface, so the 
risk of the mock allowing a non-existent attribute is low here.



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