kaxil commented on a change in pull request #5928: [AIRFLOW-5168] Fix Dataproc
Operators & add tests
URL: https://github.com/apache/airflow/pull/5928#discussion_r318543214
##########
File path: tests/contrib/operators/test_dataproc_operator.py
##########
@@ -683,9 +894,45 @@ def test_dataproc_job_id_is_set():
_assert_dataproc_job_id(mock_hook, dataproc_task)
+ def test_render_template(self):
+ task = DataProcPySparkOperator(
+ task_id=TASK_ID,
+
main='file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar',
+ arguments=['{{ ds }}', 'gs://pub/shakespeare/rose.txt'],
+ job_name=GCP_PROJECT_TEMPLATED,
+ cluster_name=CLUSTER_NAME_TEMPLATED,
+ region=GCP_REGION_TEMPLATED,
+ dataproc_pyspark_jars=['gs://test-bucket/{{ dag.dag_id
}}/test.jar'],
+ dataproc_pyspark_properties={},
+ dag=self.dag,
+ )
+
+ self.assertEqual(
+ task.template_fields, ['arguments', 'job_name', 'cluster_name',
+ 'region', 'dataproc_jars',
'dataproc_properties'])
+
+ ti = TaskInstance(task, DEFAULT_DATE)
+ ti.render_templates()
+
+ self.assertEqual(task.arguments, [DEFAULT_DATE.date().isoformat(),
'gs://pub/shakespeare/rose.txt'])
+ self.assertEqual(task.cluster_name, CLUSTER_NAME)
+ self.assertEqual(task.job_name, GCP_PROJECT_ID)
+ self.assertEqual(task.region, GCP_REGION)
+ self.assertEqual(task.dataproc_jars,
['gs://test-bucket/{}/test.jar'.format(DAG_ID)])
+ self.assertEqual(task.dataproc_properties, {})
+
class DataProcSparkOperatorTest(unittest.TestCase):
# Unit test for the DataProcSparkOperator
+ def setUp(self):
Review comment:
Interesting, didn't knew about `@pytest.fixture`. I will create a separate
PR for that as we already have some tests in master and then cherry-pick to
`v1-10-test`. This PR is for `v1-10-test`.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services