Repository: incubator-airflow Updated Branches: refs/heads/master 5f87f8a68 -> 62f5034d6
[AIRFLOW-875] Add template to HttpSensor params Closes #2080 from jlowin/httpsensor Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/62f5034d Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/62f5034d Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/62f5034d Branch: refs/heads/master Commit: 62f5034d65fb4afa7ac0267e5e1cb85f63f245f4 Parents: 5f87f8a Author: Jeremiah Lowin <[email protected]> Authored: Sun Feb 19 09:54:23 2017 +0100 Committer: Bolke de Bruin <[email protected]> Committed: Sun Feb 19 09:54:23 2017 +0100 ---------------------------------------------------------------------- airflow/operators/sensors.py | 2 +- tests/core.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/62f5034d/airflow/operators/sensors.py ---------------------------------------------------------------------- diff --git a/airflow/operators/sensors.py b/airflow/operators/sensors.py index 5fbd21c..5830cbc 100644 --- a/airflow/operators/sensors.py +++ b/airflow/operators/sensors.py @@ -642,7 +642,7 @@ class HttpSensor(BaseSensorOperator): depends on the option that's being modified. """ - template_fields = ('endpoint',) + template_fields = ('endpoint', 'params') @apply_defaults def __init__(self, http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/62f5034d/tests/core.py ---------------------------------------------------------------------- diff --git a/tests/core.py b/tests/core.py index c7160cb..47a7d2b 100644 --- a/tests/core.py +++ b/tests/core.py @@ -1840,6 +1840,9 @@ class FakeSession(object): return self.response def prepare_request(self, request): + if 'date' in request.params: + self.response._content += ( + '/' + request.params['date']).encode('ascii', 'ignore') return self.response class HttpOpSensorTest(unittest.TestCase): @@ -1874,19 +1877,21 @@ class HttpOpSensorTest(unittest.TestCase): @mock.patch('requests.Session', FakeSession) def test_sensor(self): + sensor = sensors.HttpSensor( task_id='http_sensor_check', - conn_id='http_default', + http_conn_id='http_default', endpoint='/search', - params={"client": "ubuntu", "q": "airflow"}, + params={"client": "ubuntu", "q": "airflow", 'date': '{{ds}}'}, headers={}, - response_check=lambda response: ("airbnb/airflow" in response.text), + response_check=lambda response: ( + "airbnb/airflow/" + DEFAULT_DATE.strftime('%Y-%m-%d') + in response.text), poke_interval=5, timeout=15, dag=self.dag) sensor.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True) - class FakeWebHDFSHook(object): def __init__(self, conn_id): self.conn_id = conn_id
