Fokko commented on a change in pull request #5928: [AIRFLOW-5168] Fix Dataproc
Operators & add tests
URL: https://github.com/apache/airflow/pull/5928#discussion_r318540545
##########
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:
Maybe we can remove these `setUp`'s with a fixture. In the end they are not
really setting up something, but just setting a global variable. Creating a
fixture is nicer, which we can reuse in multiple tests:
```
@pytest.fixture
def dag():
return DAG(
DAG_ID,
default_args={
'owner': 'airflow',
'start_date': DEFAULT_DATE,
},
schedule_interval='@daily'
)
```
And then in the actual test:
```
def test_render_template(self, dag):
task = DataProcSparkOperator(
dag=dag
)
```
WDYT?
----------------------------------------------------------------
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