kaxil commented on a change in pull request #5519:
URL: https://github.com/apache/airflow/pull/5519#discussion_r421892844
##########
File path: tests/providers/slack/hooks/test_slack.py
##########
@@ -19,82 +19,154 @@
import unittest
import mock
+from slack.errors import SlackApiError
from airflow.exceptions import AirflowException
from airflow.providers.slack.hooks.slack import SlackHook
class TestSlackHook(unittest.TestCase):
- def test_init_with_token_only(self):
+
+ def test___get_token_with_token_only(self):
+ """ tests `__get_token` method when only token is provided """
+ # Given
test_token = 'test_token'
- slack_hook = SlackHook(token=test_token, slack_conn_id=None)
+ test_conn_id = None
+
+ # Creating a dummy subclass is the easiest way to avoid running init
+ # which is actually using the method we are testing
+ class DummySlackHook(SlackHook):
+ def __init__(self, *args, **kwargs): # pylint: disable=W0231
+ pass
- self.assertEqual(slack_hook.token, test_token)
+ # Run
+ hook = DummySlackHook()
+
+ # Assert
+ output = hook._SlackHook__get_token(test_token, test_conn_id) #
pylint: disable=E1101
+ expected = test_token
+ self.assertEqual(output, expected)
@mock.patch('airflow.providers.slack.hooks.slack.SlackHook.get_connection')
- def test_init_with_valid_slack_conn_id_only(self, get_connection_mock):
+ def test___get_token_with_valid_slack_conn_id_only(self,
get_connection_mock):
+ """ tests `__get_token` method when only connection is provided """
+ # Given
+ test_token = None
+ test_conn_id = 'x'
test_password = 'test_password'
+
+ # Mock
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)
+ # Creating a dummy subclass is the easiest way to avoid running init
+ # which is actually using the method we are testing
+ class DummySlackHook(SlackHook):
+ def __init__(self, *args, **kwargs): # pylint: disable=W0231
+ pass
Review comment:
Pushed a commit to PR:
https://github.com/apache/airflow/pull/5519/commits/d81d6e947ba364b0dd9e730507e51ff2a0d3d3e2
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]