This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new bbbaad0864 Fix the error caused by passing unused context in 
JiraSensor.poke (#23352)
bbbaad0864 is described below

commit bbbaad08640b5a68629395351a19cca82d6b1591
Author: Kian Eliasi <[email protected]>
AuthorDate: Mon Jun 20 13:53:19 2022 +0430

    Fix the error caused by passing unused context in JiraSensor.poke (#23352)
    
    * Fix the error caused by passing unused context in JiraSensor.poke
    
    The sample ticket object used in the test is mocked more realistically and 
the original field_checker_func is used.
---
 airflow/providers/jira/sensors/jira.py    |  2 +-
 tests/providers/jira/sensors/test_jira.py | 32 +++++++++++++++++--------------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/airflow/providers/jira/sensors/jira.py 
b/airflow/providers/jira/sensors/jira.py
index 9b16b6557b..3a2cb8eddd 100644
--- a/airflow/providers/jira/sensors/jira.py
+++ b/airflow/providers/jira/sensors/jira.py
@@ -60,7 +60,7 @@ class JiraSensor(BaseSensorOperator):
         jira_result = getattr(resource, self.method_name)(**self.method_params)
         if self.result_processor is None:
             return jira_result
-        return self.result_processor(context, jira_result)
+        return self.result_processor(jira_result)
 
 
 class JiraTicketSensor(JiraSensor):
diff --git a/tests/providers/jira/sensors/test_jira.py 
b/tests/providers/jira/sensors/test_jira.py
index a23256783a..4f4c9d90e6 100644
--- a/tests/providers/jira/sensors/test_jira.py
+++ b/tests/providers/jira/sensors/test_jira.py
@@ -28,15 +28,22 @@ from airflow.utils import db, timezone
 DEFAULT_DATE = timezone.datetime(2017, 1, 1)
 jira_client_mock = Mock(name="jira_client_for_test")
 
-minimal_test_ticket = {
-    "id": "911539",
-    "self": "https://sandbox.localhost/jira/rest/api/2/issue/911539";,
-    "key": "TEST-1226",
-    "fields": {
-        "labels": ["test-label-1", "test-label-2"],
-        "description": "this is a test description",
-    },
-}
+
+class _MockJiraTicket(dict):
+    class _TicketFields:
+        labels = ["test-label-1", "test-label-2"]
+        description = "this is a test description"
+
+    fields = _TicketFields
+
+
+minimal_test_ticket = _MockJiraTicket(
+    {
+        "id": "911539",
+        "self": "https://sandbox.localhost/jira/rest/api/2/issue/911539";,
+        "key": "TEST-1226",
+    }
+)
 
 
 class TestJiraSensor(unittest.TestCase):
@@ -62,7 +69,8 @@ class TestJiraSensor(unittest.TestCase):
             method_name='issue',
             task_id='search-ticket-test',
             ticket_id='TEST-1226',
-            field_checker_func=TestJiraSensor.field_checker_func,
+            field='labels',
+            expected_value='test-label-1',
             timeout=518400,
             poke_interval=10,
             dag=self.dag,
@@ -72,7 +80,3 @@ class TestJiraSensor(unittest.TestCase):
 
         assert jira_mock.called
         assert jira_mock.return_value.issue.called
-
-    @staticmethod
-    def field_checker_func(context, issue):
-        return "test-label-1" in issue['fields']['labels']

Reply via email to