generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 24
User agent #387
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
User agent #387
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
cb47f65
WIP - add user agent interceptor/plugin
alextwoods 91e8208
Working implementation with basic user agent
alextwoods d3b1d15
Fix pyright errors
alextwoods 2031933
Use short form license
alextwoods d5473b5
Run pyupgrade
alextwoods 83a0a8f
Cleanups from PR (still todo: seperate into generic user agent and aw…
alextwoods b7e15d1
Add Config/HttpConfig Protocols + generate __version__
alextwoods 8afb134
Add __version__ to smithy and aws core
alextwoods a7475d7
WIP - generic useragent refactoring.
alextwoods 296811b
Remove explicit Config protocol
alextwoods f449114
Major refactor - generic and aws specific user agent. Codegen userage…
alextwoods 7b7573d
Merge branch 'develop' into user_agent
alextwoods 6a49728
Use aws-sdk-python as sdk name + correctly use sdkId for serviceId
alextwoods b727753
Merge branch 'develop' into user_agent
alextwoods b88dfc2
Use aws core version as the "main" sdk version. client library versio…
alextwoods 6c6458b
User agent tests
alextwoods 7aac81c
Add user_agent interceptor test
alextwoods 86e461c
Update packages/smithy-http/src/smithy_http/interceptors/user_agent.py
alextwoods 0013139
Update packages/smithy-http/tests/unit/interceptors/test_user_agent.py
alextwoods 00ce11f
PR cleanups
alextwoods 8ea3bf2
PR updates
alextwoods a35f607
Merge branch 'develop' into user_agent
alextwoods 5f128d4
Merge branch 'smithy-lang:develop' into user_agent
alextwoods 20b97ed
PR Cleanups
alextwoods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/smithy-http/tests/unit/interceptors/test_user_agent.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import platform | ||
|
|
||
| import smithy_core | ||
| from smithy_http.interceptors.user_agent import UserAgentBuilder | ||
|
|
||
|
|
||
| def test_from_environment(monkeypatch): # type: ignore | ||
| monkeypatch.setattr(platform, "system", lambda: "Linux") # type: ignore | ||
| monkeypatch.setattr(platform, "release", lambda: "5.4.228-131.415.AMZN2.X86_64") # type: ignore | ||
| monkeypatch.setattr(platform, "python_version", lambda: "4.3.2") # type: ignore | ||
| monkeypatch.setattr(platform, "python_implementation", lambda: "Cpython") # type: ignore | ||
alextwoods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| monkeypatch.setattr(smithy_core, "__version__", "1.2.3") # type: ignore | ||
|
|
||
| user_agent = str(UserAgentBuilder.from_environment().build()) | ||
| assert "python/1.2.3" in user_agent | ||
| assert "os/linux#5.4.228-131.415.AMZN2.X86_64" in user_agent | ||
| assert "md/arch#arm64" in user_agent | ||
| assert "lang/python#4.3.2" in user_agent | ||
| assert "md/pyimpl#Cpython" in user_agent | ||
|
|
||
|
|
||
| def test_build_adds_sdk_metadata(): | ||
| user_agent = UserAgentBuilder(sdk_version="1.2.3").build() | ||
| assert "python/1.2.3" in str(user_agent) | ||
|
|
||
|
|
||
| def test_build_adds_ua_metadata(): | ||
| user_agent = UserAgentBuilder().build() | ||
| assert "ua/2.1" in str(user_agent) | ||
|
|
||
|
|
||
| def test_build_os_defaults_to_other(): | ||
| user_agent = UserAgentBuilder().build() | ||
| assert "os/other" in str(user_agent) | ||
|
|
||
|
|
||
| def test_build_os_lowercases_platform(): | ||
| user_agent = UserAgentBuilder(platform_name="LINUX").build() | ||
| assert "os/linux" in str(user_agent) | ||
|
|
||
|
|
||
| def test_build_os_maps_platform_names(): | ||
| user_agent = UserAgentBuilder(platform_name="darwin").build() | ||
| assert "os/macos" in str(user_agent) | ||
|
|
||
|
|
||
| def test_build_os_includes_version(): | ||
| user_agent = UserAgentBuilder(platform_name="linux", platform_version="5.4").build() | ||
| assert "os/linux#5.4" in str(user_agent) | ||
|
|
||
|
|
||
| def test_build_os_other_platform(): | ||
| user_agent = UserAgentBuilder( | ||
| platform_name="myos", platform_version="0.0.1" | ||
| ).build() | ||
| assert "os/other md/myos#0.0.1" in str(user_agent) | ||
|
|
||
|
|
||
| def test_build_arch_adds_md(): | ||
| user_agent = UserAgentBuilder(platform_machine="x86_64").build() | ||
| assert "md/arch#x86_64" in str(user_agent) | ||
|
|
||
|
|
||
| def test_build_language_version(): | ||
| user_agent = UserAgentBuilder(python_version="3.12").build() | ||
| assert "lang/python#3.12" in str(user_agent) | ||
|
|
||
|
|
||
| def test_build_language_implementation(): | ||
| user_agent = UserAgentBuilder(python_implementation="CPython").build() | ||
| assert "md/pyimpl#CPython" in str(user_agent) | ||
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.