|
| 1 | +""" |
| 2 | +Copyright 2025 Google LLC |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +""" |
| 16 | + |
| 17 | +from .user_agent import get_user_agent |
| 18 | + |
| 19 | + |
| 20 | +def test_get_user_agent_returns_correct_value_for_windows(mocker): |
| 21 | + mocker.patch('xpk.utils.user_agent.xpk_version', 'v1.0.0') |
| 22 | + mocker.patch('platform.system', return_value='Windows') |
| 23 | + mocker.patch('platform.version', return_value='10.0') |
| 24 | + assert get_user_agent() == 'XPK/v1.0.0 (Windows NT 10.0)' |
| 25 | + |
| 26 | + |
| 27 | +def test_get_user_agent_returns_correct_value_for_linux(mocker): |
| 28 | + mocker.patch('xpk.utils.user_agent.xpk_version', 'v1.0.0') |
| 29 | + mocker.patch('platform.system', return_value='Linux') |
| 30 | + mocker.patch('platform.machine', return_value='x86_64') |
| 31 | + assert get_user_agent() == 'XPK/v1.0.0 (Linux; x86_64)' |
| 32 | + |
| 33 | + |
| 34 | +def test_get_user_agent_returns_correct_value_for_darwin(mocker): |
| 35 | + mocker.patch('xpk.utils.user_agent.xpk_version', 'v1.0.0') |
| 36 | + mocker.patch('platform.system', return_value='Darwin') |
| 37 | + mocker.patch('platform.mac_ver', return_value=('10.15', '', 'x86_64')) |
| 38 | + assert get_user_agent() == 'XPK/v1.0.0 (Macintosh; x86_64 Mac OS X 10.15)' |
| 39 | + |
| 40 | + |
| 41 | +def test_get_user_agent_returns_correct_value_for_unknown(mocker): |
| 42 | + mocker.patch('xpk.utils.user_agent.xpk_version', 'v1.0.0') |
| 43 | + mocker.patch('platform.system', return_value='Unknown') |
| 44 | + assert get_user_agent() == 'XPK/v1.0.0 ()' |
0 commit comments