From commits-return-81057-archive-asf-public=cust-asf.ponee.io@airflow.apache.org Fri Dec 13 09:22:35 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 63EB718064E for ; Fri, 13 Dec 2019 10:22:35 +0100 (CET) Received: (qmail 79092 invoked by uid 500); 13 Dec 2019 09:22:34 -0000 Mailing-List: contact commits-help@airflow.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airflow.apache.org Delivered-To: mailing list commits@airflow.apache.org Received: (qmail 79083 invoked by uid 99); 13 Dec 2019 09:22:34 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Dec 2019 09:22:34 +0000 From: GitBox To: commits@airflow.apache.org Subject: [GitHub] [airflow] ashb commented on a change in pull request #6793: [AIRFLOW-1076] Add get method for template variable accessor Message-ID: <157622895464.28267.6919500889687574240.gitbox@gitbox.apache.org> Date: Fri, 13 Dec 2019 09:22:34 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit ashb commented on a change in pull request #6793: [AIRFLOW-1076] Add get method for template variable accessor URL: https://github.com/apache/airflow/pull/6793#discussion_r357550550 ########## File path: tests/test_core.py ########## @@ -568,67 +568,6 @@ def verify_templated_field(context): t.execute = verify_templated_field t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True) - def test_template_with_variable(self): - """ - Test the availability of variables in templates - """ - val = { - 'test_value': 'a test value' - } - Variable.set("a_variable", val['test_value']) - - def verify_templated_field(context): - self.assertEqual(context['ti'].task.some_templated_field, - val['test_value']) - - t = OperatorSubclass( - task_id='test_complex_template', - some_templated_field='{{ var.value.a_variable }}', - dag=self.dag) - t.execute = verify_templated_field - t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True) - - def test_template_with_json_variable(self): - """ - Test the availability of variables (serialized as JSON) in templates - """ - val = { - 'test_value': {'foo': 'bar', 'obj': {'v1': 'yes', 'v2': 'no'}} - } - Variable.set("a_variable", val['test_value'], serialize_json=True) - - def verify_templated_field(context): - self.assertEqual(context['ti'].task.some_templated_field, - val['test_value']['obj']['v2']) - - t = OperatorSubclass( - task_id='test_complex_template', - some_templated_field='{{ var.json.a_variable.obj.v2 }}', - dag=self.dag) - t.execute = verify_templated_field - t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True) - - def test_template_with_json_variable_as_value(self): - """ - Test the availability of variables (serialized as JSON) in templates, but - accessed as a value - """ - val = { - 'test_value': {'foo': 'bar'} - } - Variable.set("a_variable", val['test_value'], serialize_json=True) - - def verify_templated_field(context): - self.assertEqual(context['ti'].task.some_templated_field, - '{\n "foo": "bar"\n}') - - t = OperatorSubclass( - task_id='test_complex_template', - some_templated_field='{{ var.value.a_variable }}', - dag=self.dag) - t.execute = verify_templated_field - t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True) Review comment: Yup, nice one! 💯 ---------------------------------------------------------------- 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: users@infra.apache.org With regards, Apache Git Services