4
4
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5
5
6
6
import importlib
7
+ import oci
7
8
from unittest .mock import patch
8
9
9
10
import pytest
@@ -34,12 +35,13 @@ def teardown_method(self):
34
35
35
36
@patch ("oci.signer.Signer" )
36
37
def test_user_agent_api_keys_using_test_profile (self , mock_signer ):
37
- with patch ("oci.config.from_file" , return_value = self .test_config ):
38
- auth_info = ads .auth .api_keys ("test_path" , "TEST_PROFILE" )
39
- assert (
40
- auth_info ["config" ].get ("additional_user_agent" )
41
- == f"{ LIBRARY } /version={ ads .__version__ } #surface=WORKSTATION#api={ UNKNOWN } "
42
- )
38
+ with pytest .raises (oci .exceptions .InvalidConfig ):
39
+ with patch ("oci.config.from_file" , return_value = self .test_config ):
40
+ auth_info = ads .auth .api_keys ("test_path" , "TEST_PROFILE" )
41
+ assert (
42
+ auth_info ["config" ].get ("additional_user_agent" )
43
+ == f"{ LIBRARY } /version={ ads .__version__ } #surface=WORKSTATION#api={ UNKNOWN } "
44
+ )
43
45
44
46
@patch ("oci.auth.signers.get_resource_principals_signer" )
45
47
def test_user_agent_rp (self , mock_signer , monkeypatch ):
@@ -54,15 +56,16 @@ def test_user_agent_rp(self, mock_signer, monkeypatch):
54
56
55
57
@patch ("oci.signer.load_private_key_from_file" )
56
58
def test_user_agent_default_signer (self , mock_load_key_file , monkeypatch ):
57
- # monkeypatch = MonkeyPatch()
58
- monkeypatch .delenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , raising = False )
59
- importlib .reload (ads .config )
60
- with patch ("oci.config.from_file" , return_value = self .test_config ):
61
- auth_info = ads .auth .default_signer ()
62
- assert (
63
- auth_info ["config" ].get ("additional_user_agent" )
64
- == f"{ LIBRARY } /version={ ads .__version__ } #surface=WORKSTATION#api={ UNKNOWN } "
65
- )
59
+ with pytest .raises (oci .exceptions .InvalidConfig ):
60
+ # monkeypatch = MonkeyPatch()
61
+ monkeypatch .delenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , raising = False )
62
+ importlib .reload (ads .config )
63
+ with patch ("oci.config.from_file" , return_value = self .test_config ):
64
+ auth_info = ads .auth .default_signer ()
65
+ assert (
66
+ auth_info ["config" ].get ("additional_user_agent" )
67
+ == f"{ LIBRARY } /version={ ads .__version__ } #surface=WORKSTATION#api={ UNKNOWN } "
68
+ )
66
69
67
70
@pytest .mark .parametrize (
68
71
"INPUT_DATA, EXPECTED_RESULT" ,
@@ -104,42 +107,44 @@ def test_user_agent_default_signer(self, mock_load_key_file, monkeypatch):
104
107
def test_user_agent_default_signer_known_resources (
105
108
self ,mock_load_key_file , monkeypatch , INPUT_DATA , EXPECTED_RESULT
106
109
):
107
- # monkeypatch = MonkeyPatch()
108
- monkeypatch .setenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , "1.1" )
109
- monkeypatch .setenv (INPUT_DATA ["RESOURCE_KEY" ], "1234" )
110
- if INPUT_DATA [EXTRA_USER_AGENT_INFO ] is not None :
111
- monkeypatch .setenv (EXTRA_USER_AGENT_INFO , INPUT_DATA [EXTRA_USER_AGENT_INFO ])
112
-
113
- importlib .reload (ads .config )
114
- importlib .reload (ads )
115
- importlib .reload (ads .auth )
116
- importlib .reload (ads .telemetry )
117
-
118
- with patch ("oci.config.from_file" , return_value = self .test_config ):
119
- auth_info = ads .auth .default_signer ()
120
- assert (
121
- auth_info ["config" ].get ("additional_user_agent" )
122
- == f"{ LIBRARY } /version={ ads .__version__ } #surface={ EXPECTED_RESULT ['USER_AGENT_VALUE' ]} #api={ EXPECTED_RESULT [EXTRA_USER_AGENT_INFO ]} "
123
- )
124
- monkeypatch .delenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , raising = False )
125
- monkeypatch .delenv (INPUT_DATA ["RESOURCE_KEY" ], raising = False )
126
- monkeypatch .delenv (EXTRA_USER_AGENT_INFO , raising = False )
110
+ with pytest .raises (oci .exceptions .InvalidConfig ):
111
+ # monkeypatch = MonkeyPatch()
112
+ monkeypatch .setenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , "1.1" )
113
+ monkeypatch .setenv (INPUT_DATA ["RESOURCE_KEY" ], "1234" )
114
+ if INPUT_DATA [EXTRA_USER_AGENT_INFO ] is not None :
115
+ monkeypatch .setenv (EXTRA_USER_AGENT_INFO , INPUT_DATA [EXTRA_USER_AGENT_INFO ])
116
+
117
+ importlib .reload (ads .config )
118
+ importlib .reload (ads )
119
+ importlib .reload (ads .auth )
120
+ importlib .reload (ads .telemetry )
121
+
122
+ with patch ("oci.config.from_file" , return_value = self .test_config ):
123
+ auth_info = ads .auth .default_signer ()
124
+ assert (
125
+ auth_info ["config" ].get ("additional_user_agent" )
126
+ == f"{ LIBRARY } /version={ ads .__version__ } #surface={ EXPECTED_RESULT ['USER_AGENT_VALUE' ]} #api={ EXPECTED_RESULT [EXTRA_USER_AGENT_INFO ]} "
127
+ )
128
+ monkeypatch .delenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , raising = False )
129
+ monkeypatch .delenv (INPUT_DATA ["RESOURCE_KEY" ], raising = False )
130
+ monkeypatch .delenv (EXTRA_USER_AGENT_INFO , raising = False )
127
131
128
132
@patch ("oci.signer.Signer" )
129
133
def test_user_agent_default_singer_ociservice (
130
134
self ,
131
135
mock_signer ,
132
136
monkeypatch
133
137
):
134
- monkeypatch .setenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , "1.1" )
135
-
136
- importlib .reload (ads .config )
137
- importlib .reload (ads .telemetry )
138
-
139
- with patch ("oci.config.from_file" , return_value = self .test_config ):
140
- auth_info = ads .auth .default_signer ()
141
- assert (
142
- auth_info ["config" ].get ("additional_user_agent" )
143
- == f"{ LIBRARY } /version={ ads .__version__ } #surface=OCI_SERVICE#api={ UNKNOWN } "
144
- )
145
- monkeypatch .delenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , raising = False )
138
+ with pytest .raises (oci .exceptions .InvalidConfig ):
139
+ monkeypatch .setenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , "1.1" )
140
+
141
+ importlib .reload (ads .config )
142
+ importlib .reload (ads .telemetry )
143
+
144
+ with patch ("oci.config.from_file" , return_value = self .test_config ):
145
+ auth_info = ads .auth .default_signer ()
146
+ assert (
147
+ auth_info ["config" ].get ("additional_user_agent" )
148
+ == f"{ LIBRARY } /version={ ads .__version__ } #surface=OCI_SERVICE#api={ UNKNOWN } "
149
+ )
150
+ monkeypatch .delenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , raising = False )
0 commit comments