@@ -309,7 +309,7 @@ def test_create_instance(self, get_client, instance_create, mock_project_id):
309309 @mock .patch ('google.cloud.bigtable.instance.Instance.cluster' )
310310 @mock .patch ('google.cloud.bigtable.instance.Instance.create' )
311311 @mock .patch ('airflow.providers.google.cloud.hooks.bigtable.BigtableHook._get_client' )
312- def test_create_instance_with_one_replica_cluster (
312+ def test_create_instance_with_one_replica_cluster_production (
313313 self , get_client , instance_create , cluster , mock_project_id
314314 ):
315315 operation = mock .Mock ()
@@ -325,10 +325,57 @@ def test_create_instance_with_one_replica_cluster(
325325 cluster_nodes = 1 ,
326326 cluster_storage_type = enums .StorageType .SSD ,
327327 project_id = GCP_PROJECT_ID_HOOK_UNIT_TEST ,
328+ instance_type = enums .Instance .Type .PRODUCTION ,
328329 )
329330 cluster .assert_has_calls (
330331 [
331- unittest .mock .call (CBT_CLUSTER , CBT_ZONE , 1 , enums .StorageType .SSD ),
332+ unittest .mock .call (
333+ cluster_id = CBT_CLUSTER ,
334+ location_id = CBT_ZONE ,
335+ serve_nodes = 1 ,
336+ default_storage_type = enums .StorageType .SSD ,
337+ ),
338+ unittest .mock .call (
339+ CBT_REPLICA_CLUSTER_ID , CBT_REPLICA_CLUSTER_ZONE , 1 , enums .StorageType .SSD
340+ ),
341+ ],
342+ any_order = True ,
343+ )
344+ get_client .assert_called_once_with (project_id = 'example-project' )
345+ instance_create .assert_called_once_with (clusters = mock .ANY )
346+ assert res .instance_id == 'instance'
347+
348+ @mock .patch (
349+ 'airflow.providers.google.common.hooks.base_google.GoogleBaseHook.project_id' ,
350+ new_callable = PropertyMock ,
351+ return_value = GCP_PROJECT_ID_HOOK_UNIT_TEST ,
352+ )
353+ @mock .patch ('google.cloud.bigtable.instance.Instance.cluster' )
354+ @mock .patch ('google.cloud.bigtable.instance.Instance.create' )
355+ @mock .patch ('airflow.providers.google.cloud.hooks.bigtable.BigtableHook._get_client' )
356+ def test_create_instance_with_one_replica_cluster_development (
357+ self , get_client , instance_create , cluster , mock_project_id
358+ ):
359+ operation = mock .Mock ()
360+ operation .result_return_value = Instance (instance_id = CBT_INSTANCE , client = get_client )
361+ instance_create .return_value = operation
362+
363+ res = self .bigtable_hook_default_project_id .create_instance (
364+ instance_id = CBT_INSTANCE ,
365+ main_cluster_id = CBT_CLUSTER ,
366+ main_cluster_zone = CBT_ZONE ,
367+ replica_cluster_id = CBT_REPLICA_CLUSTER_ID ,
368+ replica_cluster_zone = CBT_REPLICA_CLUSTER_ZONE ,
369+ cluster_nodes = 1 ,
370+ cluster_storage_type = enums .StorageType .SSD ,
371+ project_id = GCP_PROJECT_ID_HOOK_UNIT_TEST ,
372+ instance_type = enums .Instance .Type .DEVELOPMENT ,
373+ )
374+ cluster .assert_has_calls (
375+ [
376+ unittest .mock .call (
377+ cluster_id = CBT_CLUSTER , location_id = CBT_ZONE , default_storage_type = enums .StorageType .SSD
378+ ),
332379 unittest .mock .call (
333380 CBT_REPLICA_CLUSTER_ID , CBT_REPLICA_CLUSTER_ZONE , 1 , enums .StorageType .SSD
334381 ),
@@ -365,7 +412,12 @@ def test_create_instance_with_multiple_replica_clusters(
365412 )
366413 cluster .assert_has_calls (
367414 [
368- unittest .mock .call (CBT_CLUSTER , CBT_ZONE , 1 , enums .StorageType .SSD ),
415+ unittest .mock .call (
416+ cluster_id = CBT_CLUSTER ,
417+ location_id = CBT_ZONE ,
418+ serve_nodes = 1 ,
419+ default_storage_type = enums .StorageType .SSD ,
420+ ),
369421 unittest .mock .call ('replica-1' , 'us-west1-a' , 1 , enums .StorageType .SSD ),
370422 unittest .mock .call ('replica-2' , 'us-central1-f' , 1 , enums .StorageType .SSD ),
371423 unittest .mock .call ('replica-3' , 'us-east1-d' , 1 , enums .StorageType .SSD ),
0 commit comments