You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/12/16 11:08:29 UTC
[GitHub] [airflow] Taragolis commented on a diff in pull request #28403: Correctly template Glue Jobs `create_job_kwargs` arg
Taragolis commented on code in PR #28403:
URL: https://github.com/apache/airflow/pull/28403#discussion_r1050621893
##########
tests/providers/amazon/aws/operators/test_glue.py:
##########
@@ -16,20 +16,62 @@
# under the License.
from __future__ import annotations
+import copy
from unittest import mock
import pytest
from airflow.configuration import conf
+from airflow.models import DAG, DagRun, TaskInstance
from airflow.providers.amazon.aws.hooks.glue import GlueJobHook
from airflow.providers.amazon.aws.hooks.s3 import S3Hook
from airflow.providers.amazon.aws.operators.glue import GlueJobOperator
+from airflow.utils import timezone
+
+TASK_ID = "test_glue_operator"
+DAG_ID = "test_dag_id"
+JOB_NAME = "test_job_name"
+DEFAULT_DATE = timezone.datetime(2017, 1, 1)
+
+BASE_LOCATION = "some-bucket/{{ task_instance_key_str }}"
+SCRIPT_LOCATION = f"s3://{BASE_LOCATION}/script-location.py"
+CREATE_JOB_KWARGS = {
+ "GlueVersion": "4.0",
+ "Command": {
+ "Name": "glueetl",
+ "ScriptLocation": SCRIPT_LOCATION,
+ },
+ "WorkerType": "G.1X",
+ "NumberOfWorkers": 2,
+}
+EXPECTED_BASE_LOCATION = f"some-bucket/{DAG_ID}__{TASK_ID}__20170101"
class TestGlueJobOperator:
def setup_method(self):
conf.load_test_config()
+ def test_render_template(self):
+ args = {"owner": "airflow", "start_date": DEFAULT_DATE}
+
+ dag = DAG(DAG_ID, default_args=args)
+ mock_operator = GlueJobOperator(
+ task_id=TASK_ID, dag=dag, create_job_kwargs=CREATE_JOB_KWARGS, s3_bucket=BASE_LOCATION
+ )
+
+ dag_run = DagRun(dag_id=mock_operator.dag_id, execution_date=DEFAULT_DATE, run_id="test")
+ ti = TaskInstance(task=mock_operator)
+ ti.dag_run = dag_run
Review Comment:
You could simplify this code by fixture [`create_task_instance`](https://github.com/apache/airflow/blob/4d0fa01f72ac4a947db2352e18f4721c2e2ec7a3/tests/conftest.py#L729-L734)
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org