feluelle commented on a change in pull request #4923: [AIRFLOW-4092] Add gRPCOperator, unit test and added to auto doc URL: https://github.com/apache/airflow/pull/4923#discussion_r275173803
########## File path: tests/contrib/operators/test_grpc_operator.py ########## @@ -0,0 +1,111 @@ +# -*- coding: utf-8 -*- +# +# Licensed 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 unittest + +from airflow import configuration +from airflow.contrib.operators.grpc_operator import GrpcOperator + +try: + from unittest import mock +except ImportError: + try: + import mock + except ImportError: + mock = None + + +class StubClass(object): + def __init__(self, channel): + pass + + def stream_call(self, data): + pass + + +class TestGrpcOperator(unittest.TestCase): + def setUp(self): + configuration.load_test_config() + + def custom_conn_func(self, connection): + pass + + @mock.patch('airflow.contrib.operators.grpc_operator.GrpcHook') + def test_with_interceptors(self, mock_hook): + mocked_hook = mock.Mock() Review comment: What is `mocked_hook` for? You should be able to just call `mock_hook.assert_called_once_with("grpc_default", interceptors=[], custom_connection_func=None)` on the patched mock `mock_hook` you don't need to set the return value to a new mock object. ---------------------------------------------------------------- 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
