How to use the slackclient.slackrequest.SlackRequest function in slackclient

To help you get started, we’ve selected a few slackclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github slackapi / python-slackclient / tests / test_slackrequest.py View on Github external
def test_http_headers(mocker):
    requests = mocker.patch('slackclient.slackrequest.requests')
    request = SlackRequest()

    request.do('xoxb-123', 'chat.postMessage', {'text': 'test', 'channel': '#general'})
    args, kwargs = requests.post.call_args

    assert kwargs['headers']['user-agent'] is not None
github slackapi / python-slackclient / tests / test_slackrequest.py View on Github external
def test_post_attachements(mocker):
    requests = mocker.patch('slackclient.slackrequest.requests')
    request = SlackRequest()

    request.do('xoxb-123',
               'chat.postMessage',
               {'attachments': [{'title': 'hello'}]})
    args, kwargs = requests.post.call_args

    assert requests.post.call_count == 1
    assert 'https://slack.com/api/chat.postMessage' == args[0]
    assert isinstance(kwargs["data"]["attachments"], str)
github slackapi / python-slackclient / tests / test_slackrequest.py View on Github external
def test_post_file(mocker):
    requests = mocker.patch('slackclient.slackrequest.requests')
    request = SlackRequest()

    request.do('xoxb-123',
               'files.upload',
               {'file': open(os.path.join('.', 'tests', 'data', 'slack_logo.png'), 'rb'),
                'filename': 'slack_logo.png'})
    args, kwargs = requests.post.call_args

    assert requests.post.call_count == 1
    assert 'https://slack.com/api/files.upload' == args[0]
    assert {'filename': 'slack_logo.png'} == kwargs['data']
    assert kwargs['files'] is not None
github slackapi / python-slackclient / tests / test_slackrequest.py View on Github external
def test_auth_header(mocker):
    requests = mocker.patch('slackclient.slackrequest.requests')
    request = SlackRequest()

    request.do('xoxb-123', 'chat.postMessage', {'text': 'test', 'channel': '#general'})
    args, kwargs = requests.post.call_args

    assert "Bearer xoxb-123" in kwargs['headers']['Authorization']
github slackapi / python-slackclient / tests / test_slackrequest.py View on Github external
def test_custom_user_agent(mocker):
    requests = mocker.patch('slackclient.slackrequest.requests')
    request = SlackRequest()

    request.append_user_agent("fooagent1", "0.1")
    request.append_user_agent("baragent/2", "0.2")

    request.do('xoxb-123', 'chat.postMessage', {'text': 'test', 'channel': '#general'})
    args, kwargs = requests.post.call_args

    # Verify user-agent includes both default and custom agent info
    assert "slackclient/{}".format(__version__) in kwargs['headers']['user-agent']
    assert "fooagent1/0.1" in kwargs['headers']['user-agent']

    # verify escaping of slashes in custom agent name
    assert "baragent:2/0.2" in kwargs['headers']['user-agent']
github slackapi / python-slackclient / tests / test_slackrequest.py View on Github external
def test_token_override(mocker):
    requests = mocker.patch('slackclient.slackrequest.requests')
    request = SlackRequest()

    request.do('xoxb-123', 'chat.postMessage',
               {
                   'token': "newtoken",
                   'text': 'test',
                   'channel': '#general'
                })
    args, kwargs = requests.post.call_args

    assert "Bearer newtoken" in kwargs['headers']['Authorization']
github slackapi / python-slackclient / tests / test_slackrequest.py View on Github external
def test_plural_field(mocker):
    requests = mocker.patch('slackclient.slackrequest.requests')
    request = SlackRequest()

    request.do('xoxb-123', 'conversations.open', {'users': ['U123', 'U234', 'U345']})
    args, kwargs = requests.post.call_args

    assert kwargs['data'] == {'users': 'U123,U234,U345'}

    request.do('xoxb-123', 'conversations.open', {'users': "U123,U234,U345"})
    args2, kwargs2 = requests.post.call_args

    assert kwargs2['data'] == {'users': 'U123,U234,U345'}
github slackapi / python-slackclient / tests / test_slackrequest.py View on Github external
def test_get_file(mocker):
    requests = mocker.patch('slackclient.slackrequest.requests')
    request = SlackRequest()

    request.do('xoxb-123', 'files.info', {'file': 'myFavoriteFileID'})
    args, kwargs = requests.post.call_args

    assert requests.post.call_count == 1
    assert 'https://slack.com/api/files.info' == args[0]
    assert {'file': "myFavoriteFileID"} == kwargs['data']
    assert kwargs['files'] is None
github slackapi / python-slackclient / slackclient / server.py View on Github external
def __init__(self, token, connect=True, proxies=None):
        self.token = token
        self.username = None
        self.domain = None
        self.login_data = None
        self.websocket = None
        self.users = SearchDict()
        self.channels = SearchList()
        self.connected = False
        self.ws_url = None
        self.proxies = proxies
        self.api_requester = SlackRequest(proxies=proxies)

        if connect:
            self.rtm_connect()
github slackapi / python-slackclient / slackclient / server.py View on Github external
def __init__(self, token=None, connect=True, proxies=None, **kwargs):
        # Slack app configs
        self.token = token

        # api configs
        self.proxies = proxies

        # HTTP Request handler
        self.api_requester = SlackRequest(proxies=proxies)

        # Workspace metadata
        self.username = None
        self.domain = None
        self.login_data = None
        self.users = SearchDict()
        self.channels = SearchList()

        # RTM configs
        self.websocket = None
        self.ws_url = None
        self.connected = False
        self.auto_reconnect = False
        self.last_connected_at = 0
        self.reconnect_count = 0
        self.rtm_connect_retries = 0