11import pytest
22import tempfile
33
4+ from mock import patch
5+
46from polyaxon import settings
57from polyaxon ._client .client import PolyaxonClient
68from polyaxon ._constants .globals import NO_AUTH
1012 ProjectsV1Api ,
1113 RunsV1Api ,
1214 UsersV1Api ,
13- VersionsV1Api ,
15+ VersionsV1Api , AgentsV1Api ,
1416)
1517from polyaxon ._utils .test_utils import BaseTestCase
18+ from polyaxon .exceptions import PolyaxonClientException
1619
1720
1821@pytest .mark .client_mark
@@ -24,6 +27,7 @@ def setUp(self):
2427 def test_client_services (self ):
2528 settings .AUTH_CONFIG .token = None
2629 client = PolyaxonClient (token = None )
30+ assert client .is_internal is False
2731 assert client .config .token is None
2832
2933 assert isinstance (client .config , ClientConfig )
@@ -34,6 +38,36 @@ def test_client_services(self):
3438 assert isinstance (client .runs_v1 , RunsV1Api )
3539 assert isinstance (client .users_v1 , UsersV1Api )
3640
41+ def test_internal_client_services (self ):
42+ client = PolyaxonClient (is_internal = True )
43+ assert client .is_internal is True
44+ assert isinstance (client .agents_v1 , AgentsV1Api )
45+
46+ def test_sync_internal_client_uses_internal_config (self ):
47+ settings .CLIENT_CONFIG .token = "token"
48+ with patch ("polyaxon._client.client.ApiClient" ) as api_client :
49+ PolyaxonClient (is_internal = True )
50+
51+ sdk_config = api_client .call_args .args [0 ]
52+ assert sdk_config .api_key_prefix ["ApiKey" ] == "InternalToken"
53+ assert (
54+ api_client .call_args .kwargs
55+ == settings .CLIENT_CONFIG .get_internal_header ()
56+ )
57+
58+ def test_async_internal_client_uses_async_internal_config (self ):
59+ settings .CLIENT_CONFIG .token = "token"
60+ with patch ("polyaxon._client.client.AsyncApiClient" ) as api_client :
61+ PolyaxonClient (is_async = True , is_internal = True )
62+
63+ sdk_config = api_client .call_args .args [0 ]
64+ assert sdk_config .api_key_prefix ["ApiKey" ] == "InternalToken"
65+ assert sdk_config .connection_pool_maxsize == 100
66+ assert (
67+ api_client .call_args .kwargs
68+ == settings .CLIENT_CONFIG .get_internal_header ()
69+ )
70+
3771 def test_from_config (self ):
3872 settings .CLIENT_CONFIG .host = "localhost"
3973 client = PolyaxonClient (config = ClientConfig ())
0 commit comments