[AIRFLOW-5335] Simplify GCSHook test (#5958)
This commit is contained in:
Родитель
dc0018b2f2
Коммит
6138208749
|
@ -71,16 +71,28 @@ class TestGoogleCloudStorageHook(unittest.TestCase):
|
|||
self.gcs_hook = gcs_hook.GoogleCloudStorageHook(
|
||||
google_cloud_storage_conn_id='test')
|
||||
|
||||
def test_storage_client_creation(self):
|
||||
with mock.patch('google.cloud.storage.Client') as mock_client:
|
||||
gcs_hook_1 = gcs_hook.GoogleCloudStorageHook()
|
||||
gcs_hook_1.get_conn()
|
||||
|
||||
# test that Storage Client is called with required arguments
|
||||
mock_client.assert_called_once_with(
|
||||
client_info=mock.ANY,
|
||||
credentials=mock.ANY,
|
||||
project=mock.ANY)
|
||||
@mock.patch(
|
||||
'airflow.contrib.hooks.gcp_api_base_hook.GoogleCloudBaseHook.client_info',
|
||||
new_callable=mock.PropertyMock,
|
||||
return_value="CLIENT_INFO"
|
||||
)
|
||||
@mock.patch(
|
||||
BASE_STRING.format("GoogleCloudBaseHook._get_credentials_and_project_id"),
|
||||
return_value=("CREDENTIALS", "PROJECT_ID")
|
||||
)
|
||||
@mock.patch('google.cloud.storage.Client')
|
||||
def test_storage_client_creation(self,
|
||||
mock_client,
|
||||
mock_get_creds_and_project_id,
|
||||
mock_client_info):
|
||||
hook = gcs_hook.GoogleCloudStorageHook()
|
||||
result = hook.get_conn()
|
||||
# test that Storage Client is called with required arguments
|
||||
mock_client.assert_called_once_with(
|
||||
client_info="CLIENT_INFO",
|
||||
credentials="CREDENTIALS",
|
||||
project="PROJECT_ID")
|
||||
self.assertEqual(mock_client.return_value, result)
|
||||
|
||||
@mock.patch(GCS_STRING.format('GoogleCloudStorageHook.get_conn'))
|
||||
def test_exists(self, mock_service):
|
||||
|
|
Загрузка…
Ссылка в новой задаче