@@ -33,15 +33,15 @@ def setup_method(self):
33
33
def teardown_method (self ):
34
34
self .test_config = {}
35
35
36
+ @patch ("oci.config.validate_config" )
36
37
@patch ("oci.signer.Signer" )
37
- def test_user_agent_api_keys_using_test_profile (self , mock_signer ):
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
- )
38
+ def test_user_agent_api_keys_using_test_profile (self , mock_signer , mock_validate_config ):
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
+ )
45
45
46
46
@patch ("oci.auth.signers.get_resource_principals_signer" )
47
47
def test_user_agent_rp (self , mock_signer , monkeypatch ):
@@ -54,18 +54,18 @@ def test_user_agent_rp(self, mock_signer, monkeypatch):
54
54
== f"{ LIBRARY } /version={ ads .__version__ } #surface=WORKSTATION#api={ UNKNOWN } "
55
55
)
56
56
57
+ @patch ("oci.config.validate_config" )
57
58
@patch ("oci.signer.load_private_key_from_file" )
58
- def test_user_agent_default_signer (self , mock_load_key_file , monkeypatch ):
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
- )
59
+ def test_user_agent_default_signer (self , mock_load_key_file , mock_validate_config , monkeypatch ):
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
+ )
69
69
70
70
@pytest .mark .parametrize (
71
71
"INPUT_DATA, EXPECTED_RESULT" ,
@@ -103,48 +103,49 @@ def test_user_agent_default_signer(self, mock_load_key_file, monkeypatch):
103
103
),
104
104
],
105
105
)
106
+ @patch ("oci.config.validate_config" )
106
107
@patch ("oci.signer.load_private_key_from_file" )
107
108
def test_user_agent_default_signer_known_resources (
108
- self ,mock_load_key_file , monkeypatch , INPUT_DATA , EXPECTED_RESULT
109
+ self ,mock_load_key_file , mock_validate_config , monkeypatch , INPUT_DATA , EXPECTED_RESULT
109
110
):
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 )
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 )
131
131
132
+ @patch ("oci.config.validate_config" )
132
133
@patch ("oci.signer.Signer" )
133
134
def test_user_agent_default_singer_ociservice (
134
135
self ,
135
136
mock_signer ,
136
- monkeypatch
137
+ mock_validate_config ,
138
+ monkeypatch ,
137
139
):
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 )
140
+ monkeypatch .setenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , "1.1" )
141
+
142
+ importlib .reload (ads .config )
143
+ importlib .reload (ads .telemetry )
144
+
145
+ with patch ("oci.config.from_file" , return_value = self .test_config ):
146
+ auth_info = ads .auth .default_signer ()
147
+ assert (
148
+ auth_info ["config" ].get ("additional_user_agent" )
149
+ == f"{ LIBRARY } /version={ ads .__version__ } #surface=OCI_SERVICE#api={ UNKNOWN } "
150
+ )
151
+ monkeypatch .delenv ("OCI_RESOURCE_PRINCIPAL_VERSION" , raising = False )
0 commit comments