Exemplo n.º 1
0
 def _get_slack_hook(self) -> SlackWebhookHook:
     return SlackWebhookHook(
         http_conn_id=self.slack_conn_id,
         message=self.slack_message,
         channel=self.slack_channel,
         webhook_token=self.slack_webhook_token,
     )
Exemplo n.º 2
0
    def test_build_slack_message(self):
        # Given
        hook = SlackWebhookHook(**self._config)

        # When
        message = hook._build_slack_message()

        # Then
        self.assertEqual(self.expected_message_dict, json.loads(message))
Exemplo n.º 3
0
    def test_get_token_manual_token(self):
        # Given
        manual_token = 'manual_token_here'
        hook = SlackWebhookHook(webhook_token=manual_token)

        # When
        webhook_token = hook._get_token(manual_token, None)

        # Then
        self.assertEqual(webhook_token, manual_token)
Exemplo n.º 4
0
 def execute(self, context):
     """
     Call the SlackWebhookHook to post the provided Slack message
     """
     self.hook = SlackWebhookHook(self.http_conn_id, self.webhook_token,
                                  self.message, self.attachments,
                                  self.blocks, self.channel, self.username,
                                  self.icon_emoji, self.icon_url,
                                  self.link_names, self.proxy)
     self.hook.execute()
Exemplo n.º 5
0
 def test_url_generated_by_http_conn_id_and_endpoint(self, mock_request, mock_session):
     hook = SlackWebhookHook(http_conn_id='slack-webhook-host', webhook_token='B000/XXX')
     try:
         hook.execute()
     except MissingSchema:
         pass
     mock_request.assert_called_once_with(
         self.expected_method, self.expected_url, headers=mock.ANY, data=mock.ANY
     )
     mock_request.reset_mock()
Exemplo n.º 6
0
 def test_url_generated_by_endpoint(self, mock_request, mock_session):
     hook = SlackWebhookHook(webhook_token=self.expected_url)
     try:
         hook.execute()
     except MissingSchema:
         pass
     mock_request.assert_called_once_with(
         self.expected_method, self.expected_url, headers=mock.ANY, data=mock.ANY
     )
     mock_request.reset_mock()
Exemplo n.º 7
0
    def test_get_token_conn_id_password(self):
        # Given
        conn_id = 'slack-webhook-with-password'
        hook = SlackWebhookHook(http_conn_id=conn_id)
        expected_webhook_token = 'your_token_here'

        # When
        webhook_token = hook._get_token(None, conn_id)

        # Then
        self.assertEqual(webhook_token, expected_webhook_token)
Exemplo n.º 8
0
    def test_get_token_conn_id(self):
        # Given
        conn_id = 'slack-webhook-default'
        hook = SlackWebhookHook(http_conn_id=conn_id)
        expected_webhook_token = 'your_token_here'

        # When
        webhook_token = hook._get_token(None, conn_id)

        # Then
        assert webhook_token == expected_webhook_token