Esempio n. 1
0
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']
Esempio n. 2
0
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'}

    test_plural_fields_data = {
        'users': ['U123', 'U234', 'U345'],
        'channel': 'C123,C234,C345'
    }

    request.do('xoxb-123', 'conversations.open', test_plural_fields_data)
    args2, kwargs2 = requests.post.call_args

    assert kwargs2['data'] == {
        'users': 'U123,U234,U345',
        'channel': 'C123,C234,C345'
    }