예제 #1
0
 def test_database_delete_missing_project_id(self, mock_hook):
     mock_hook.return_value.get_database.return_value = {"name": DB_ID}
     op = SpannerDeleteDatabaseInstanceOperator(instance_id=INSTANCE_ID,
                                                database_id=DB_ID,
                                                task_id="id")
     result = op.execute(None)
     mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default")
     mock_hook.return_value.delete_database.assert_called_once_with(
         project_id=None, instance_id=INSTANCE_ID, database_id=DB_ID)
     self.assertTrue(result)
예제 #2
0
 def test_database_delete_exits_and_succeeds_if_database_does_not_exist(
         self, mock_hook):
     mock_hook.return_value.get_database.return_value = None
     op = SpannerDeleteDatabaseInstanceOperator(project_id=PROJECT_ID,
                                                instance_id=INSTANCE_ID,
                                                database_id=DB_ID,
                                                task_id="id")
     result = op.execute(None)
     mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default")
     mock_hook.return_value.delete_database.assert_not_called()
     self.assertTrue(result)
예제 #3
0
 def test_database_delete_ex_if_param_missing(self, project_id, instance_id,
                                              database_id, ddl_statements,
                                              exp_msg, mock_hook):
     with pytest.raises(AirflowException) as ctx:
         SpannerDeleteDatabaseInstanceOperator(
             project_id=project_id,
             instance_id=instance_id,
             database_id=database_id,
             ddl_statements=ddl_statements,
             task_id="id",
         )
     err = ctx.value
     assert f"The required parameter '{exp_msg}' is empty" in str(err)
     mock_hook.assert_not_called()
예제 #4
0
 def test_database_delete(self, mock_hook):
     mock_hook.return_value.get_database.return_value = {"name": DB_ID}
     op = SpannerDeleteDatabaseInstanceOperator(project_id=PROJECT_ID,
                                                instance_id=INSTANCE_ID,
                                                database_id=DB_ID,
                                                task_id="id")
     result = op.execute(None)
     mock_hook.assert_called_once_with(
         gcp_conn_id="google_cloud_default",
         impersonation_chain=None,
     )
     mock_hook.return_value.delete_database.assert_called_once_with(
         project_id=PROJECT_ID, instance_id=INSTANCE_ID, database_id=DB_ID)
     assert result
예제 #5
0
 def test_database_delete_ex_if_param_missing(self, project_id, instance_id,
                                              database_id, ddl_statements,
                                              exp_msg, mock_hook):
     with self.assertRaises(AirflowException) as cm:
         SpannerDeleteDatabaseInstanceOperator(
             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()
예제 #6
0
        project_id=GCP_PROJECT_ID,
        instance_id=GCP_SPANNER_INSTANCE_ID,
        database_id=GCP_SPANNER_DATABASE_ID,
        query=["DELETE FROM my_table2 WHERE true"],
        task_id='spanner_instance_query_task')
    spanner_instance_query_task2 = SpannerQueryDatabaseInstanceOperator(
        instance_id=GCP_SPANNER_INSTANCE_ID,
        database_id=GCP_SPANNER_DATABASE_ID,
        query=["DELETE FROM my_table2 WHERE true"],
        task_id='spanner_instance_query_task2')
    # [END howto_operator_spanner_query]

    # [START howto_operator_spanner_database_delete]
    spanner_database_delete_task = SpannerDeleteDatabaseInstanceOperator(
        project_id=GCP_PROJECT_ID,
        instance_id=GCP_SPANNER_INSTANCE_ID,
        database_id=GCP_SPANNER_DATABASE_ID,
        task_id='spanner_database_delete_task')
    spanner_database_delete_task2 = SpannerDeleteDatabaseInstanceOperator(
        instance_id=GCP_SPANNER_INSTANCE_ID,
        database_id=GCP_SPANNER_DATABASE_ID,
        task_id='spanner_database_delete_task2')
    # [END howto_operator_spanner_database_delete]

    # [START howto_operator_spanner_delete]
    spanner_instance_delete_task = SpannerDeleteInstanceOperator(
        project_id=GCP_PROJECT_ID,
        instance_id=GCP_SPANNER_INSTANCE_ID,
        task_id='spanner_instance_delete_task')
    spanner_instance_delete_task2 = SpannerDeleteInstanceOperator(
        instance_id=GCP_SPANNER_INSTANCE_ID,