Example #1
0
 def execute(self, **kwargs):
     """
     SlackAPIOperator calls will not fail even if the call is not unsuccessful.
     It should not prevent a DAG from completing in success
     """
     if not self.api_params:
         self.construct_api_call_params()
     slack = SlackHook(token=self.token, slack_conn_id=self.slack_conn_id)
     slack.call(self.method, self.api_params)
 def execute(self, **kwargs):
     """
     SlackAPIOperator calls will not fail even if the call is not unsuccessful.
     It should not prevent a DAG from completing in success
     """
     if not self.api_params:
         self.construct_api_call_params()
     slack = SlackHook(token=self.token, slack_conn_id=self.slack_conn_id)
     slack.call(self.method, self.api_params)
Example #3
0
    def test_call_with_success(self, slack_client_class_mock):
        slack_client_mock = mock.Mock()
        slack_client_class_mock.return_value = slack_client_mock
        slack_client_mock.api_call.return_value = {'ok': True}

        test_token = 'test_token'
        test_slack_conn_id = 'test_slack_conn_id'
        slack_hook = SlackHook(token=test_token, slack_conn_id=test_slack_conn_id)
        test_method = 'test_method'
        test_api_params = {'key1': 'value1', 'key2': 'value2'}

        slack_hook.call(test_method, test_api_params)

        slack_client_class_mock.assert_called_once_with(test_token)
        slack_client_mock.api_call.assert_called_once_with(test_method, **test_api_params)
    def test_call_with_success(self, slack_client_class_mock):
        slack_client_mock = mock.Mock()
        slack_client_class_mock.return_value = slack_client_mock
        slack_client_mock.api_call.return_value = {'ok': True}

        test_token = 'test_token'
        test_slack_conn_id = 'test_slack_conn_id'
        slack_hook = SlackHook(token=test_token, slack_conn_id=test_slack_conn_id)
        test_method = 'test_method'
        test_api_params = {'key1': 'value1', 'key2': 'value2'}

        slack_hook.call(test_method, test_api_params)

        slack_client_class_mock.assert_called_with(test_token)
        slack_client_mock.api_call.assert_called_with(test_method, **test_api_params)
    def test_init_with_token_and_slack_conn_id(self):
        test_token = 'test_token'
        test_slack_conn_id = 'test_slack_conn_id'
        slack_hook = SlackHook(token=test_token,
                               slack_conn_id=test_slack_conn_id)

        self.assertEqual(slack_hook.token, test_token)
    def execute(self, context):

        data = context['task_instance'].xcom_pull(task_ids='get_data_from_bq')
        self.log.info('Context is ' + str(data))
        aaa = ','.join( [str(v[0]) for v in data])
        if not self.api_params:
            self.construct_api_call_params()

        self.api_params = {}
        self.api_params['text'] = 'Amin says: ' + 'Daniel please change your user name its too long'
        self.api_params['icon_url'] = "https://cdn3.iconfinder.com/data/icons/essentials-pack-part-1/128/Essentials_Pack-96-512.png"
        self.api_params['username'] = "******"
        self.api_params['channel'] = 'general'
        slack = SlackHook(token=self.token, slack_conn_id=self.slack_conn_id)
        self.method = 'chat.postMessage'
        slack.call(self.method, self.api_params)
    def test_init_with_valid_slack_conn_id_only(self, get_connection_mock):
        test_password = '******'
        get_connection_mock.return_value = mock.Mock(password=test_password)

        test_slack_conn_id = 'test_slack_conn_id'
        slack_hook = SlackHook(token=None, slack_conn_id=test_slack_conn_id)

        get_connection_mock.assert_called_once_with(test_slack_conn_id)
        self.assertEqual(slack_hook.token, test_password)
Example #8
0
    def test_call_with_failure(self, slack_client_class_mock):
        slack_client_mock = mock.Mock()
        slack_client_class_mock.return_value = slack_client_mock
        slack_client_mock.api_call.return_value = {'ok': False, 'error': 'test_error'}

        test_token = 'test_token'
        test_slack_conn_id = 'test_slack_conn_id'
        slack_hook = SlackHook(token=test_token, slack_conn_id=test_slack_conn_id)
        test_method = 'test_method'
        test_api_params = {'key1': 'value1', 'key2': 'value2'}

        self.assertRaises(AirflowException, slack_hook.call, test_method, test_api_params)
    def test_init_with_token_only(self):
        test_token = 'test_token'
        slack_hook = SlackHook(token=test_token, slack_conn_id=None)

        self.assertEqual(slack_hook.token, test_token)