Skip to content

Commit

Permalink
[AIRFLOW-4322] Add test for VerticaOperator (apache#5107)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaxil authored and XD-DENG committed Apr 16, 2019
1 parent 7f60203 commit e7ed9fb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/contrib/operators/vertica_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ def __init__(self, sql, vertica_conn_id='vertica_default', *args, **kwargs):
def execute(self, context):
self.log.info('Executing: %s', self.sql)
hook = VerticaHook(vertica_conn_id=self.vertica_conn_id)
hook.run(self.sql)
hook.run(sql=self.sql)
40 changes: 40 additions & 0 deletions tests/contrib/operators/test_vertica_operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import mock
import unittest

from airflow.contrib.operators.vertica_operator import VerticaOperator


class VerticaOperatorTest(unittest.TestCase):

@mock.patch('airflow.contrib.operators.vertica_operator.VerticaHook')
def test_execute(self, mock_hook):
sql = "select a, b, c"
op = VerticaOperator(task_id='test_task_id',
sql=sql)
op.execute(None)
mock_hook.return_value.run.assert_called_once_with(
sql=sql
)


if __name__ == '__main__':
unittest.main()

0 comments on commit e7ed9fb

Please sign in to comment.