Skip to content

Commit 313d739

Browse files
committed
fix: complete missing testing
1 parent ad9ccdd commit 313d739

3 files changed

Lines changed: 55 additions & 3 deletions

File tree

runpod/user_agent.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88

99
def construct_user_agent():
10-
""" Constructs the User-Agent string for the RunPod-Python-SDK """
10+
""" Constructs the User-Agent string for the RunPod-Python-SDK
11+
12+
Example:
13+
RunPod-Python-SDK/0.1.0 (Linux 5.4.0-54-generic; x86_64) Language/Python 3.8.5
14+
"""
1115
os_info = f"{platform.system()} {platform.release()}; {platform.machine()}"
1216
python_version = platform.python_version()
1317
integration_method = os.getenv('RUNPOD_UA_INTEGRATION')

tests/test_serverless/test_worker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ def test_get_auth_header(self):
3939
os_info = f"{platform.system()} {platform.release()}; {platform.machine()}"
4040
with patch("runpod.serverless.worker.os") as mock_os:
4141
mock_os.environ.get.return_value = "test"
42-
mock_os.getenv.return_value = "test"
4342
assert runpod.serverless.worker._get_auth_header(
4443
) == {
4544
'Authorization': 'test',
46-
'User-Agent': f'RunPod-Python-SDK/{runpod_version} ({os_info}) Language/Python {platform.python_version()} Integration/test' # pylint: disable=line-too-long
45+
'User-Agent': f'RunPod-Python-SDK/{runpod_version} ({os_info}) Language/Python {platform.python_version()}' # pylint: disable=line-too-long
4746
}
4847

4948
def test_is_local(self):

tests/test_user_agent.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
""" Tests for the user_agent module. """
2+
3+
import unittest
4+
from unittest.mock import patch
5+
import os
6+
7+
from runpod.user_agent import construct_user_agent
8+
9+
10+
class TestConstructUserAgent(unittest.TestCase):
11+
"""Test the construct_user_agent function."""
12+
13+
@patch('runpod.user_agent.platform.system', return_value='Windows')
14+
@patch('runpod.user_agent.platform.release', return_value='10')
15+
@patch('runpod.user_agent.platform.machine', return_value='AMD64')
16+
@patch('runpod.user_agent.platform.python_version', return_value='3.8.10')
17+
def test_user_agent_without_integration(
18+
self, mock_python_version, mock_machine, mock_release, mock_system):
19+
"""Test the User-Agent string without specifying an integration method."""
20+
if 'RUNPOD_UA_INTEGRATION' in os.environ:
21+
del os.environ['RUNPOD_UA_INTEGRATION']
22+
23+
expected_ua = "RunPod-Python-SDK/0.1.0 (Windows 10; AMD64) Language/Python 3.8.10"
24+
self.assertEqual(construct_user_agent(), expected_ua)
25+
26+
assert mock_python_version.called
27+
assert mock_machine.called
28+
assert mock_release.called
29+
assert mock_system.called
30+
31+
@patch('runpod.user_agent.platform.system', return_value='Linux')
32+
@patch('runpod.user_agent.platform.release', return_value='5.4')
33+
@patch('runpod.user_agent.platform.machine', return_value='x86_64')
34+
@patch('runpod.user_agent.platform.python_version', return_value='3.9.5')
35+
@patch.dict(os.environ, {'RUNPOD_UA_INTEGRATION': 'SkyPilot'})
36+
def test_user_agent_with_integration(
37+
self, mock_python_version, mock_machine, mock_release, mock_system):
38+
"""Test the User-Agent string with an integration method specified."""
39+
expected_ua = "RunPod-Python-SDK/0.1.0 (Linux 5.4; x86_64) Language/Python 3.9.5 Integration/SkyPilot" # pylint: disable=line-too-long
40+
self.assertEqual(construct_user_agent(), expected_ua)
41+
42+
assert mock_python_version.called
43+
assert mock_machine.called
44+
assert mock_release.called
45+
assert mock_system.called
46+
47+
48+
if __name__ == '__main__':
49+
unittest.main()

0 commit comments

Comments
 (0)