turbaszek commented on a change in pull request #14191: URL: https://github.com/apache/airflow/pull/14191#discussion_r576236623
########## File path: tests/providers/google/cloud/transfers/test_gdrive_to_local.py ########## @@ -0,0 +1,38 @@ +# +# 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. +from unittest import TestCase, mock + +from airflow.providers.google.cloud.transfers.gdrive_to_local import GoogleDriveToLocalOperator + +TASK_ID = "test-drive-to-local-operator" +FOLDER_ID = "1234567890qwerty" +FILE_NAME = "file.pdf" +OUTPUT_FILE = "out_file.pdf" + + +class TestGoogleDriveToLocalOperator(TestCase): + @mock.patch("airflow.providers.google.cloud.transfers.gdrive_to_local.GoogleDriveHook") + def test_execute(self, hook_mock): + op = GoogleDriveToLocalOperator( + task_id=TASK_ID, + folder_id=FOLDER_ID, + file_name=FILE_NAME, + output_file=OUTPUT_FILE, + ) + op.execute(context=None) + hook_mock.assert_called_once() Review comment: ```suggestion hook_mock.assert_called_once_with(delegate_to=None, impersonation_chain=None) ``` This only verify instantiating the hook. We also need to check if right method was called so we need: ```py hook_mock.return_value.get_file_id.assert_called_once_with(...) hook_mock.return_value.download_file.assert_called_once_with(...) ``` where the `...` needs to be replaced with proper values. Also consider using ```py with TemporaryNamedFile("wb") as temp_file: op = GoogleDriveToLocalOperator(..., output_file=temp_file.name) ``` to avoid a side effect in form of a created file. ---------------------------------------------------------------- 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]
