Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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']
def __init__(
self,
proxies=None
):
# HTTP configs
self.custom_user_agent = None
self.proxies = proxies
# Construct the user-agent header with the package info, Python version and OS version.
self.default_user_agent = {
# __name__ returns all classes, we only want the client
"client": "{0}/{1}".format(__name__.split('.')[0], __version__),
"python": "Python/{v.major}.{v.minor}.{v.micro}".format(v=sys.version_info),
"system": "{0}/{1}".format(platform.system(), platform.release())
}