Skip to content

for #25762: Add platform and python version info to user-agent #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ def __init__(self,
self.config.api_path = urlparse.urljoin(urlparse.urljoin(
api_base or "/", self.config.api_ver + "/"), "json")

self.reset_user_agent()

# if the service contains user information strip it out
# copied from the xmlrpclib which turned the user:password into
Expand Down Expand Up @@ -359,9 +358,12 @@ def __init__(self,
self._json_loads = self._json_loads_ascii

self.client_caps = ClientCapabilities()
# this relies on self.client_caps being set first
self.reset_user_agent()

self._server_caps = None
#test to ensure the the server supports the json API
#call to server will only be made once and will raise error
# test to ensure the the server supports the json API
# call to server will only be made once and will raise error
if connect:
self.server_caps

Expand Down Expand Up @@ -1065,8 +1067,14 @@ def add_user_agent(self, agent):

def reset_user_agent(self):
"""Reset user agent to the default

Eg. shotgun-json (3.0.17); Python 2.6 (Mac)
"""
self._user_agents = ["shotgun-json (%s)" % __version__]
ua_platform = "Unknown"
if self.client_caps.platform is not None:
ua_platform = self.client_caps.platform.capitalize()
self._user_agents = ["shotgun-json (%s)" % __version__,
"Python %s (%s)" % (self.client_caps.py_version, ua_platform)]

def set_session_uuid(self, session_uuid):
"""Sets the browser session_uuid for this API session.
Expand Down
17 changes: 14 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,36 @@ def test_user_agent(self):
"""User-Agent passed to server"""
# test default user agent
self.sg.info()
client_caps = self.sg.client_caps
args, _ = self.sg._http_request.call_args
(_, _, _, headers) = args
expected = "shotgun-json (%s)" % api.__version__
expected = "shotgun-json (%s); Python %s (%s)" % (api.__version__,
client_caps.py_version,
client_caps.platform.capitalize()
)
self.assertEqual(expected, headers.get("user-agent"))

# test adding to user agent
self.sg.add_user_agent("test-agent")
self.sg.info()
args, _ = self.sg._http_request.call_args
(_, _, _, headers) = args
expected = "shotgun-json (%s); test-agent" % api.__version__
expected = "shotgun-json (%s); Python %s (%s); test-agent" % (
api.__version__,
client_caps.py_version,
client_caps.platform.capitalize()
)
self.assertEqual(expected, headers.get("user-agent"))

# test resetting user agent
self.sg.reset_user_agent()
self.sg.info()
args, _ = self.sg._http_request.call_args
(_, _, _, headers) = args
expected = "shotgun-json (%s)" % api.__version__
expected = "shotgun-json (%s); Python %s (%s)" % (api.__version__,
client_caps.py_version,
client_caps.platform.capitalize(),
)
self.assertEqual(expected, headers.get("user-agent"))

def test_connect_close(self):
Expand Down