def test_database_update_ex_if_database_not_exist(self, mock_hook):
     mock_hook.return_value.get_database.return_value = None
     with self.assertRaises(AirflowException) as cm:
         op = CloudSpannerInstanceDatabaseUpdateOperator(
             project_id=PROJECT_ID,
             instance_id=INSTANCE_ID,
             database_id=DB_ID,
             ddl_statements=DDL_STATEMENTS,
             task_id="id")
         op.execute(None)
     err = cm.exception
     self.assertIn(
         "The Cloud Spanner database 'db1' in project 'project-id' and "
         "instance 'instance-id' is missing", str(err))
     mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default")
Ejemplo n.º 2
0
 def test_database_update_missing_project_id(self, mock_hook):
     mock_hook.return_value.get_database.return_value = {"name": DB_ID}
     op = CloudSpannerInstanceDatabaseUpdateOperator(
         instance_id=INSTANCE_ID,
         database_id=DB_ID,
         ddl_statements=DDL_STATEMENTS,
         task_id="id"
     )
     result = op.execute(None)
     mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default")
     mock_hook.return_value.update_database.assert_called_once_with(
         project_id=None, instance_id=INSTANCE_ID, database_id=DB_ID,
         ddl_statements=DDL_STATEMENTS, operation_id=None
     )
     self.assertTrue(result)
 def test_database_update_ex_if_param_missing(self, project_id, instance_id,
                                              database_id, ddl_statements,
                                              exp_msg, mock_hook):
     with self.assertRaises(AirflowException) as cm:
         CloudSpannerInstanceDatabaseUpdateOperator(
             project_id=project_id,
             instance_id=instance_id,
             database_id=database_id,
             ddl_statements=ddl_statements,
             task_id="id")
     err = cm.exception
     self.assertIn("The required parameter '{}' is empty".format(exp_msg),
                   str(err))
     mock_hook.assert_not_called()
Ejemplo n.º 4
0
        task_id='spanner_database_deploy_task')
    spanner_database_deploy_task2 = CloudSpannerInstanceDatabaseDeployOperator(
        instance_id=GCP_SPANNER_INSTANCE_ID,
        database_id=GCP_SPANNER_DATABASE_ID,
        ddl_statements=[
            "CREATE TABLE my_table1 (id INT64, name STRING(MAX)) PRIMARY KEY (id)",
            "CREATE TABLE my_table2 (id INT64, name STRING(MAX)) PRIMARY KEY (id)",
        ],
        task_id='spanner_database_deploy_task2')
    # [END howto_operator_spanner_database_deploy]

    # [START howto_operator_spanner_database_update]
    spanner_database_update_task = CloudSpannerInstanceDatabaseUpdateOperator(
        project_id=GCP_PROJECT_ID,
        instance_id=GCP_SPANNER_INSTANCE_ID,
        database_id=GCP_SPANNER_DATABASE_ID,
        ddl_statements=[
            "CREATE TABLE my_table3 (id INT64, name STRING(MAX)) PRIMARY KEY (id)",
        ],
        task_id='spanner_database_update_task')
    # [END howto_operator_spanner_database_update]

    # [START howto_operator_spanner_database_update_idempotent]
    spanner_database_update_idempotent1_task = CloudSpannerInstanceDatabaseUpdateOperator(
        project_id=GCP_PROJECT_ID,
        instance_id=GCP_SPANNER_INSTANCE_ID,
        database_id=GCP_SPANNER_DATABASE_ID,
        operation_id=OPERATION_ID,
        ddl_statements=[
            "CREATE TABLE my_table_unique (id INT64, name STRING(MAX)) PRIMARY KEY (id)",
        ],
        task_id='spanner_database_update_idempotent1_task')