def test_execute(self, mock_extract_object_id, mock_create_dataset, mock_xcom): op = AutoMLCreateDatasetOperator( dataset=DATASET, location=GCP_LOCATION, project_id=GCP_PROJECT_ID, task_id=TASK_ID, ) op.execute(context=None) mock_create_dataset.assert_called_once_with( dataset=DATASET, location=GCP_LOCATION, metadata=None, project_id=GCP_PROJECT_ID, retry=None, timeout=None, ) mock_xcom.assert_called_once_with(None, key="dataset_id", value=DATASET_ID)
IMPORT_INPUT_CONFIG = {"gcs_source": {"input_uris": [GCP_AUTOML_TEXT_BUCKET]}} default_args = {"start_date": days_ago(1)} extract_object_id = CloudAutoMLHook.extract_object_id # Example DAG for AutoML Natural Language Entities Extraction with models.DAG( "example_automl_text", default_args=default_args, schedule_interval=None, # Override to match your needs user_defined_macros={"extract_object_id": extract_object_id}, tags=['example'], ) as example_dag: create_dataset_task = AutoMLCreateDatasetOperator( task_id="create_dataset_task", dataset=DATASET, location=GCP_AUTOML_LOCATION) dataset_id = ( '{{ task_instance.xcom_pull("create_dataset_task", key="dataset_id") }}' ) import_dataset_task = AutoMLImportDataOperator( task_id="import_dataset_task", dataset_id=dataset_id, location=GCP_AUTOML_LOCATION, input_config=IMPORT_INPUT_CONFIG, ) MODEL["dataset_id"] = dataset_id
# Example DAG to create dataset, train model_id and deploy it. with models.DAG( "example_create_and_deploy", default_args=default_args, schedule_interval=None, # Override to match your needs user_defined_macros={ "get_target_column_spec": get_target_column_spec, "target": TARGET, "extract_object_id": extract_object_id, }, ) as create_deploy_dag: # [START howto_operator_automl_create_dataset] create_dataset_task = AutoMLCreateDatasetOperator( task_id="create_dataset_task", dataset=DATASET, location=GCP_AUTOML_LOCATION, project_id=GCP_PROJECT_ID, ) dataset_id = ( "{{ task_instance.xcom_pull('create_dataset_task', key='dataset_id') }}" ) # [END howto_operator_automl_create_dataset] MODEL["dataset_id"] = dataset_id # [START howto_operator_automl_import_data] import_dataset_task = AutoMLImportDataOperator( task_id="import_dataset_task", dataset_id=dataset_id, location=GCP_AUTOML_LOCATION,