def test_instance_patch_missing_project_id(self, mock_hook): mock_hook.return_value.patch_instance.return_value = True op = CloudSQLInstancePatchOperator(body=PATCH_BODY, instance=INSTANCE_NAME, task_id="id") result = op.execute(None) mock_hook.assert_called_once_with(api_version="v1beta4", gcp_conn_id="google_cloud_default") mock_hook.return_value.patch_instance.assert_called_once_with( project_id=None, body=PATCH_BODY, instance=INSTANCE_NAME) self.assertTrue(result)
def test_instance_patch_should_bubble_up_ex_if_not_exists( self, mock_hook, _check_if_instance_exists): _check_if_instance_exists.return_value = False with self.assertRaises(AirflowException) as cm: op = CloudSQLInstancePatchOperator(project_id=PROJECT_ID, body=PATCH_BODY, instance=INSTANCE_NAME, task_id="id") op.execute(None) err = cm.exception self.assertIn('specify another instance to patch', str(err)) mock_hook.assert_called_once_with(api_version="v1beta4", gcp_conn_id="google_cloud_default") mock_hook.return_value.patch_instance.assert_not_called()
def test_instance_patch(self, mock_hook): mock_hook.return_value.patch_instance.return_value = True op = CloudSQLInstancePatchOperator(project_id=PROJECT_ID, body=PATCH_BODY, instance=INSTANCE_NAME, task_id="id") result = op.execute(None) mock_hook.assert_called_once_with( api_version="v1beta4", gcp_conn_id="google_cloud_default", impersonation_chain=None, ) mock_hook.return_value.patch_instance.assert_called_once_with( project_id=PROJECT_ID, body=PATCH_BODY, instance=INSTANCE_NAME) assert result
# [END howto_operator_cloudsql_create] sql_instance_read_replica_create = CloudSQLCreateInstanceOperator( project_id=GCP_PROJECT_ID, body=read_replica_body, instance=READ_REPLICA_NAME, task_id='sql_instance_read_replica_create') # ############################################## # # ### MODIFYING INSTANCE AND ITS DATABASE ###### # # ############################################## # # [START howto_operator_cloudsql_patch] sql_instance_patch_task = CloudSQLInstancePatchOperator( project_id=GCP_PROJECT_ID, body=patch_body, instance=INSTANCE_NAME, task_id='sql_instance_patch_task') # [END howto_operator_cloudsql_patch] sql_instance_patch_task2 = CloudSQLInstancePatchOperator( project_id=GCP_PROJECT_ID, body=patch_body, instance=INSTANCE_NAME, task_id='sql_instance_patch_task2') # [START howto_operator_cloudsql_db_create] sql_db_create_task = CloudSQLCreateInstanceDatabaseOperator( project_id=GCP_PROJECT_ID, body=db_create_body, instance=INSTANCE_NAME,