[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(
|
self.gcs_hook = gcs_hook.GoogleCloudStorageHook(
|
||||||
google_cloud_storage_conn_id='test')
|
google_cloud_storage_conn_id='test')
|
||||||
|
|
||||||
def test_storage_client_creation(self):
|
@mock.patch(
|
||||||
with mock.patch('google.cloud.storage.Client') as mock_client:
|
'airflow.contrib.hooks.gcp_api_base_hook.GoogleCloudBaseHook.client_info',
|
||||||
gcs_hook_1 = gcs_hook.GoogleCloudStorageHook()
|
new_callable=mock.PropertyMock,
|
||||||
gcs_hook_1.get_conn()
|
return_value="CLIENT_INFO"
|
||||||
|
)
|
||||||
# test that Storage Client is called with required arguments
|
@mock.patch(
|
||||||
mock_client.assert_called_once_with(
|
BASE_STRING.format("GoogleCloudBaseHook._get_credentials_and_project_id"),
|
||||||
client_info=mock.ANY,
|
return_value=("CREDENTIALS", "PROJECT_ID")
|
||||||
credentials=mock.ANY,
|
)
|
||||||
project=mock.ANY)
|
@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'))
|
@mock.patch(GCS_STRING.format('GoogleCloudStorageHook.get_conn'))
|
||||||
def test_exists(self, mock_service):
|
def test_exists(self, mock_service):
|
||||||
|
|
Загрузка…
Ссылка в новой задаче