Skip to content
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

User agent for Python (and formerly Ruby, already merged) #5696

Merged
merged 2 commits into from
Mar 29, 2018

Conversation

sah
Copy link
Contributor

@sah sah commented Mar 28, 2018

Addresses #5657 for Python and Ruby

@p0deje
Copy link
Member

p0deje commented Mar 28, 2018

Can you explain why you need these changes?

@sah
Copy link
Contributor Author

sah commented Mar 28, 2018

Explanation is in the issue referenced in the description, but basically this is useful for error diagnosis in cloud services and grids. Similar changes have already been introduced for Java and .NET, so this is just rolling the feature out to more languages.

@p0deje
Copy link
Member

p0deje commented Mar 28, 2018

Thank you, I've merged Ruby part in 429af62!

N.B. I also did a bit of refactoring in 508a8b6.

@p0deje p0deje removed the C-rb label Mar 28, 2018
@sah
Copy link
Contributor Author

sah commented Mar 28, 2018

Updated this PR to reflect just the Python change now that the Ruby change has been merged.

@sah sah changed the title User agents for Python and Ruby User agent for Python (formerly included a Ruby version, already merged) Mar 28, 2018
@sah sah changed the title User agent for Python (formerly included a Ruby version, already merged) User agent for Python (and formerly Ruby, already merged) Mar 28, 2018
Copy link
Member

@lmtierney lmtierney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer if the test explicitly checked the platform

headers = {
'Accept': 'application/json',
'Content-Type': 'application/json;charset=UTF-8',
'User-Agent': 'Python http auth'
'User-Agent': 'selenium/%s (python %s)' % (__version__, system)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer str.format for String Interpolation in the future

@@ -33,7 +34,8 @@ def test_get_remote_connection_headers_defaults():
assert 'Connection' not in headers.keys()
assert headers.get('Accept') == 'application/json'
assert headers.get('Content-Type') == 'application/json;charset=UTF-8'
assert headers.get('User-Agent') == 'Python http auth'
assert headers.get('User-Agent').startswith("selenium/%s (python " % __version__)
assert headers.get('User-Agent').split(' ')[-1] in {'windows)', 'mac)', 'linux)'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you aren't just asserting the entire User-Agent? The second assertion could allow false positives if the wrong platform sent

Copy link
Contributor Author

@sah sah Mar 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning was that asserting the whole thing requires duplicating the code to calculate the platform name, which proves nothing except that that code does whatever it does. This way if on OS X it returns "darwin" or on Windows it returns "win32", that issue will be caught when these tests are run on those platforms. I don't feel strongly about it though, happy to go a different route here if you prefer.

@lmtierney lmtierney merged commit 9aa6642 into SeleniumHQ:master Mar 29, 2018
@lmtierney
Copy link
Member

Merged, thanks!

@sah sah deleted the user-agents branch March 29, 2018 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants