Example #1
0
    def test_api_call_params_with_default_args(self, mock_hook):
        test_slack_conn_id = 'test_slack_conn_id'

        slack_api_post_operator = SlackAPIFileOperator(
            task_id='slack',
            slack_conn_id=test_slack_conn_id,
        )

        slack_api_post_operator.execute()

        expected_api_params = {
            'channels': '#general',
            'initial_comment': 'No message has been set!',
            'filename': 'default_name.csv',
            'filetype': 'csv',
            'content': 'default,content,csv,file',
        }
        assert expected_api_params == slack_api_post_operator.api_params
Example #2
0
 def __construct_operator(self,
                          test_token,
                          test_slack_conn_id,
                          test_api_params=None):
     return SlackAPIFileOperator(
         task_id='slack',
         token=test_token,
         slack_conn_id=test_slack_conn_id,
         channel=self.test_channel,
         initial_comment=self.test_initial_comment,
         filename=self.test_filename,
         filetype=self.test_filetype,
         content=self.test_content,
         api_params=test_api_params,
     )
Example #3
0
from airflow.utils.dates import days_ago

with DAG(
    dag_id='slack_example_dag',
    schedule_interval=None,
    start_date=days_ago(2),
    max_active_runs=1,
    tags=['example'],
) as dag:
    # [START slack_operator_howto_guide_send_file]
    # Send file with filename and filetype
    slack_operator_file = SlackAPIFileOperator(
        task_id="slack_file_upload_1",
        dag=dag,
        slack_conn_id="slack",
        channel="#general",
        initial_comment="Hello World!",
        filename="/files/dags/test.txt",
        filetype="txt",
    )
    # [END slack_operator_howto_guide_send_file]

    # [START slack_operator_howto_guide_send_file_content]
    # Send file content
    slack_operator_file_content = SlackAPIFileOperator(
        task_id="slack_file_upload_2",
        dag=dag,
        slack_conn_id="slack",
        channel="#general",
        initial_comment="Hello World!",
        content="file content in txt",
Example #4
0
with DAG(
        dag_id='slack_example_dag',
        schedule_interval=None,
        start_date=datetime(2021, 1, 1),
        default_args={
            'slack_conn_id': 'slack',
            'channel': '#general',
            'initial_comment': 'Hello World!'
        },
        max_active_runs=1,
        tags=['example'],
) as dag:
    # [START slack_operator_howto_guide_send_file]
    # Send file with filename and filetype
    slack_operator_file = SlackAPIFileOperator(
        task_id="slack_file_upload_1",
        filename="/files/dags/test.txt",
        filetype="txt",
    )
    # [END slack_operator_howto_guide_send_file]

    # [START slack_operator_howto_guide_send_file_content]
    # Send file content
    slack_operator_file_content = SlackAPIFileOperator(
        task_id="slack_file_upload_2",
        content="file content in txt",
    )
    # [END slack_operator_howto_guide_send_file_content]

    slack_operator_file >> slack_operator_file_content