Exemple #1
0
 def test_instance_db_patch_should_throw_ex_when_empty_database(
         self, mock_hook):
     with self.assertRaises(AirflowException) as cm:
         op = CloudSqlInstanceDatabasePatchOperator(
             project_id=PROJECT_ID,
             instance=INSTANCE_NAME,
             database="",
             body=DATABASE_INSERT_BODY,
             task_id="id")
         op.execute(None)
     err = cm.exception
     self.assertIn("The required parameter 'database' is empty", str(err))
     mock_hook.assert_not_called()
     mock_hook.return_value.patch_database.assert_not_called()
Exemple #2
0
 def test_instance_db_patch_missing_project_id(self, mock_hook,
                                               _check_if_db_exists):
     _check_if_db_exists.return_value = True
     op = CloudSqlInstanceDatabasePatchOperator(instance=INSTANCE_NAME,
                                                database=DB_NAME,
                                                body=DATABASE_PATCH_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.patch_database.assert_called_once_with(
         project_id=None,
         instance=INSTANCE_NAME,
         database=DB_NAME,
         body=DATABASE_PATCH_BODY)
     self.assertTrue(result)
Exemple #3
0
 def test_instance_db_patch_should_throw_ex_if_not_exists(
         self, mock_hook, _check_if_db_exists):
     _check_if_db_exists.return_value = False
     with self.assertRaises(AirflowException) as cm:
         op = CloudSqlInstanceDatabasePatchOperator(
             project_id=PROJECT_ID,
             instance=INSTANCE_NAME,
             database=DB_NAME,
             body=DATABASE_PATCH_BODY,
             task_id="id")
         op.execute(None)
     err = cm.exception
     self.assertIn("Cloud SQL instance with ID", str(err))
     self.assertIn("does not contain database", str(err))
     mock_hook.assert_called_once_with(api_version="v1beta4",
                                       gcp_conn_id="google_cloud_default")
     mock_hook.return_value.patch_database.assert_not_called()
        body=db_create_body,
        instance=INSTANCE_NAME,
        task_id='sql_db_create_task'
    )
    sql_db_create_task2 = CloudSqlInstanceDatabaseCreateOperator(
        body=db_create_body,
        instance=INSTANCE_NAME,
        task_id='sql_db_create_task2'
    )
    # [END howto_operator_cloudsql_db_create]

    # [START howto_operator_cloudsql_db_patch]
    sql_db_patch_task = CloudSqlInstanceDatabasePatchOperator(
        project_id=GCP_PROJECT_ID,
        body=db_patch_body,
        instance=INSTANCE_NAME,
        database=DB_NAME,
        task_id='sql_db_patch_task'
    )
    sql_db_patch_task2 = CloudSqlInstanceDatabasePatchOperator(
        body=db_patch_body,
        instance=INSTANCE_NAME,
        database=DB_NAME,
        task_id='sql_db_patch_task2'
    )
    # [END howto_operator_cloudsql_db_patch]

    # ############################################## #
    # ### EXPORTING SQL FROM INSTANCE 1 ############ #
    # ############################################## #
    export_url_split = urlsplit(EXPORT_URI)