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 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_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 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)