def test_instance_db_create_should_abort_and_succeed_if_exists( self, mock_hook, _check_if_db_exists): _check_if_db_exists.return_value = True op = CloudSqlInstanceDatabaseCreateOperator(project_id=PROJECT_ID, instance=INSTANCE_NAME, body=DATABASE_INSERT_BODY, task_id="id") result = op.execute(None) self.assertTrue(result) mock_hook.assert_called_once_with(api_version="v1beta4", gcp_conn_id="google_cloud_default") mock_hook.return_value.create_database.assert_not_called()
def test_instance_db_create_missing_project_id(self, mock_hook, _check_if_db_exists): _check_if_db_exists.return_value = False op = CloudSqlInstanceDatabaseCreateOperator(instance=INSTANCE_NAME, body=DATABASE_INSERT_BODY, 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.create_database.assert_called_once_with( project_id=None, instance=INSTANCE_NAME, body=DATABASE_INSERT_BODY) self.assertTrue(result)
def test_instance_db_create_should_abort_and_succeed_if_exists( self, mock_hook, _check_if_db_exists): _check_if_db_exists.return_value = True op = CloudSqlInstanceDatabaseCreateOperator( project_id=PROJECT_ID, instance=INSTANCE_NAME, body=DATABASE_INSERT_BODY, task_id="id" ) result = op.execute(None) self.assertTrue(result) mock_hook.assert_called_once_with(api_version="v1beta4", gcp_conn_id="google_cloud_default") mock_hook.return_value.create_database.assert_not_called()
def test_instance_db_create_missing_project_id(self, mock_hook, _check_if_db_exists): _check_if_db_exists.return_value = False op = CloudSqlInstanceDatabaseCreateOperator( instance=INSTANCE_NAME, body=DATABASE_INSERT_BODY, 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.create_database.assert_called_once_with( project_id=None, instance=INSTANCE_NAME, body=DATABASE_INSERT_BODY ) self.assertTrue(result)
instance=INSTANCE_NAME, task_id='sql_instance_create_task' ) # [END howto_operator_cloudsql_create] # [START howto_operator_cloudsql_patch] sql_instance_patch_task = CloudSqlInstancePatchOperator( project_id=PROJECT_ID, body=patch_body, instance=INSTANCE_NAME, task_id='sql_instance_patch_task' ) # [END howto_operator_cloudsql_patch] # [START howto_operator_cloudsql_db_create] sql_db_create_task = CloudSqlInstanceDatabaseCreateOperator( project_id=PROJECT_ID, body=db_create_body, instance=INSTANCE_NAME, task_id='sql_db_create_task' ) # [END howto_operator_cloudsql_db_create] # [START howto_operator_cloudsql_db_patch] sql_db_patch_task = CloudSqlInstanceDatabasePatchOperator( project_id=PROJECT_ID, body=db_patch_body, instance=INSTANCE_NAME, database=DB_NAME, task_id='sql_db_patch_task' ) # [END howto_operator_cloudsql_db_patch] # [START howto_operator_cloudsql_db_delete] sql_db_delete_task = CloudSqlInstanceDatabaseDeleteOperator( project_id=PROJECT_ID,