4242 "fingerprint" : "test_fingerprint" ,
4343 "tenancy" : "test_tenancy" ,
4444 "region" : "us-ashburn-1" ,
45- "key_file" : "test_key_file"
45+ "key_file" : "test_key_file" ,
4646}
4747
4848
@@ -52,7 +52,11 @@ class TestEDAMixin(TestCase):
5252 @mock .patch ("os.path.exists" )
5353 @mock .patch ("oci.signer.load_private_key_from_file" )
5454 def test_set_auth_overwrite_profile (
55- self , mock_load_key_file , mock_path_exists , mock_config_from_file , mock_validate_config
55+ self ,
56+ mock_load_key_file ,
57+ mock_path_exists ,
58+ mock_config_from_file ,
59+ mock_validate_config ,
5660 ):
5761 mock_config_from_file .return_value = MOCK_CONFIG_FROM_FILE
5862 set_auth (profile = "TEST" )
@@ -65,7 +69,11 @@ def test_set_auth_overwrite_profile(
6569 @mock .patch ("os.path.exists" )
6670 @mock .patch ("oci.signer.load_private_key_from_file" )
6771 def test_set_auth_overwrite_config_location (
68- self , mock_load_key_file , mock_path_exists , mock_config_from_file , mock_validate_config
72+ self ,
73+ mock_load_key_file ,
74+ mock_path_exists ,
75+ mock_config_from_file ,
76+ mock_validate_config ,
6977 ):
7078 mock_config_from_file .return_value = MOCK_CONFIG_FROM_FILE
7179 mock_path_exists .return_value = True
@@ -77,14 +85,18 @@ def test_set_auth_overwrite_config_location(
7785 @mock .patch ("oci.config.validate_config" )
7886 @mock .patch ("oci.config.from_file" )
7987 @mock .patch ("oci.signer.Signer" )
80- def test_api_keys_using_test_profile (self , mock_signer , mock_config_from_file , mock_validate_config ):
88+ def test_api_keys_using_test_profile (
89+ self , mock_signer , mock_config_from_file , mock_validate_config
90+ ):
8191 api_keys ("test_path" , "TEST_PROFILE" )
8292 mock_config_from_file .assert_called_with ("test_path" , "TEST_PROFILE" )
8393
8494 @mock .patch ("oci.config.validate_config" )
8595 @mock .patch ("oci.config.from_file" )
8696 @mock .patch ("oci.signer.Signer" )
87- def test_api_keys_using_default_profile (self , mock_signer , mock_config_from_file , mock_validate_config ):
97+ def test_api_keys_using_default_profile (
98+ self , mock_signer , mock_config_from_file , mock_validate_config
99+ ):
88100 api_keys ("test_path" )
89101 mock_config_from_file .assert_called_with ("test_path" , "DEFAULT" )
90102
@@ -108,14 +120,16 @@ def test_resource_principal(self, mock_rp_signer):
108120
109121 @mock .patch ("oci.config.validate_config" )
110122 @mock .patch ("oci.signer.load_private_key" )
111- def test_set_auth_with_key_content (self , mock_load_private_key , mock_validate_config ):
123+ def test_set_auth_with_key_content (
124+ self , mock_load_private_key , mock_validate_config
125+ ):
112126 set_auth (
113127 config = {
114128 "user" : "test_user" ,
115129 "fingerprint" : "test_fingerprint" ,
116130 "tenancy" : "test_tenancy" ,
117131 "region" : "us-ashburn-1" ,
118- "key_content" : "test_key_content"
132+ "key_content" : "test_key_content" ,
119133 }
120134 )
121135 signer = default_signer ()
@@ -141,7 +155,12 @@ def tearDown(self) -> None:
141155 @mock .patch ("oci.signer.Signer" )
142156 @mock .patch ("oci.logging.LoggingManagementClient" )
143157 def test_api_key_auth_with_logging (
144- self , client , mock_signer , mock_path_exists , mock_config_from_file , mock_validate_config
158+ self ,
159+ client ,
160+ mock_signer ,
161+ mock_path_exists ,
162+ mock_config_from_file ,
163+ mock_validate_config ,
145164 ):
146165 """Tests initializing OCIMixin with default auth.
147166 Without any explicit config, the client should be initialized from DEFAULT OCI API key config.
@@ -264,9 +283,9 @@ def test_set_auth_value_errors(self):
264283 with pytest .raises (ValueError ):
265284 AuthFactory ().signerGenerator ("not_existing_iam_type" )
266285
267- def test_register_singer (self ):
268- AuthFactory ().register ("new_singer_type " , "signer_class" )
269- assert "new_singer_type " in AuthFactory .classes .keys ()
286+ def test_register_signer (self ):
287+ AuthFactory ().register ("new_signer_type " , "signer_class" )
288+ assert "new_signer_type " in AuthFactory .classes .keys ()
270289
271290 @mock .patch ("os.path.exists" )
272291 @mock .patch (
@@ -281,7 +300,11 @@ def test_register_singer(self):
281300 @mock .patch ("oci.config.validate_config" )
282301 @mock .patch ("oci.signer.load_private_key_from_file" )
283302 def test_api_key_create_signer (
284- self , mock_load_key_file , mock_config_from_file , mock_path_exists , mock_validate_config
303+ self ,
304+ mock_load_key_file ,
305+ mock_config_from_file ,
306+ mock_path_exists ,
307+ mock_validate_config ,
285308 ):
286309 """
287310 Testing api key setup with set_auth() and getting it with default_signer()
@@ -358,7 +381,6 @@ def test_instance_principal_create_signer(self, mock_ip_signer):
358381 @mock .patch ("ads.common.auth.AuthFactory" )
359382 @mock .patch ("oci.auth.signers.InstancePrincipalsSecurityTokenSigner" )
360383 def test_create_signer (self , mock_ip_signer , mock_signer_generator ):
361-
362384 auth = create_signer (signer = "test" )
363385 assert auth ["signer" ] == "test"
364386
@@ -389,7 +411,7 @@ def test_set_auth_multiple_times_with(
389411 mock_config_from_file ,
390412 mock_rp_signer ,
391413 mock_ip_signer ,
392- mock_validate_config
414+ mock_validate_config ,
393415 ):
394416 """
395417 Testing behaviour when multiple times invoked set_auth() with different parameters and validate,
@@ -537,41 +559,39 @@ def test_with_set_auth_returns_error(self):
537559
538560
539561class TestSecurityToken (TestCase ):
540-
541562 @mock .patch ("oci.auth.signers.SecurityTokenSigner.__init__" )
542563 @mock .patch ("oci.signer.load_private_key_from_file" )
543564 @mock .patch ("ads.common.auth.SecurityToken._read_security_token_file" )
544565 @mock .patch ("ads.common.auth.SecurityToken._validate_and_refresh_token" )
545566 def test_security_token (
546567 self ,
547- mock_validate_and_refresh_token ,
568+ mock_validate_and_refresh_token ,
548569 mock_read_security_token_file ,
549570 mock_load_private_key_from_file ,
550- mock_security_token_signer
571+ mock_security_token_signer ,
551572 ):
552573 config = {
553574 "fingerprint" : "test_fingerprint" ,
554575 "tenancy" : "test_tenancy" ,
555576 "region" : "us-ashburn-1" ,
556577 "key_file" : "test_key_file" ,
557- "generic_headers" : [1 ,2 , 3 ],
558- "body_headers" : [4 ,5 , 6 ]
578+ "generic_headers" : [1 , 2 , 3 ],
579+ "body_headers" : [4 , 5 , 6 ],
559580 }
560581
561582 with pytest .raises (
562583 ValueError ,
563- match = "Parameter `security_token_file` must be provided for using `security_token` authentication."
584+ match = "Parameter `security_token_file` must be provided for using `security_token` authentication." ,
564585 ):
565586 signer = security_token (
566587 oci_config = config ,
567- client_kwargs = {"test_client_key" :"test_client_value" }
588+ client_kwargs = {"test_client_key" : "test_client_value" },
568589 )
569590
570591 config ["security_token_file" ] = "test_security_token"
571592 mock_security_token_signer .return_value = None
572593 signer = security_token (
573- oci_config = config ,
574- client_kwargs = {"test_client_key" :"test_client_value" }
594+ oci_config = config , client_kwargs = {"test_client_key" : "test_client_value" }
575595 )
576596
577597 mock_validate_and_refresh_token .assert_called_with (config )
@@ -593,50 +613,52 @@ def test_security_token(
593613 @mock .patch ("oci.auth.security_token_container.SecurityTokenContainer.__init__" )
594614 @mock .patch ("ads.common.auth.SecurityToken._read_security_token_file" )
595615 def test_validate_and_refresh_token (
596- self ,
597- mock_read_security_token_file ,
616+ self ,
617+ mock_read_security_token_file ,
598618 mock_security_token_container ,
599619 mock_valid ,
600620 mock_time ,
601621 mock_get_jwt ,
602- mock_system
622+ mock_system ,
603623 ):
604624 security_token = SecurityToken (
605625 args = {
606626 "oci_config_location" : DEFAULT_LOCATION ,
607- "oci_key_profile" : "test_profile"
627+ "oci_key_profile" : "test_profile" ,
608628 }
609629 )
610630 mock_security_token_container .return_value = None
611-
631+
612632 mock_valid .return_value = False
613633 configuration = {
614634 "fingerprint" : "test_fingerprint" ,
615635 "tenancy" : "test_tenancy" ,
616636 "region" : "us-ashburn-1" ,
617637 "key_file" : "test_key_file" ,
618638 "security_token_file" : "test_security_token" ,
619- "generic_headers" : [1 ,2 , 3 ],
620- "body_headers" : [4 ,5 , 6 ]
639+ "generic_headers" : [1 , 2 , 3 ],
640+ "body_headers" : [4 , 5 , 6 ],
621641 }
622642 with pytest .raises (
623643 SecurityTokenError ,
624- match = "Security token has expired. Call `oci session authenticate` to generate new session."
644+ match = "Security token has expired. Call `oci session authenticate` to generate new session." ,
625645 ):
626646 security_token ._validate_and_refresh_token (configuration )
627-
647+
628648 mock_valid .return_value = True
629649 mock_time .return_value = 1
630- mock_get_jwt .return_value = {"exp" : 1 }
650+ mock_get_jwt .return_value = {"exp" : 1 }
631651 mock_system .return_value = 1
632-
652+
633653 security_token ._validate_and_refresh_token (configuration )
634-
654+
635655 mock_read_security_token_file .assert_called_with ("test_security_token" )
636656 mock_security_token_container .assert_called ()
637657 mock_time .assert_called ()
638658 mock_get_jwt .assert_called ()
639- mock_system .assert_called_with (f"oci session refresh --config-file { DEFAULT_LOCATION } --profile test_profile" )
659+ mock_system .assert_called_with (
660+ f"oci session refresh --config-file { DEFAULT_LOCATION } --profile test_profile"
661+ )
640662
641663 @mock .patch ("builtins.open" )
642664 @mock .patch ("os.path.isfile" )
@@ -645,8 +667,7 @@ def test_read_security_token_file(self, mock_isfile, mock_open):
645667
646668 mock_isfile .return_value = False
647669 with pytest .raises (
648- ValueError ,
649- match = "Invalid `security_token_file`. Specify a valid path."
670+ ValueError , match = "Invalid `security_token_file`. Specify a valid path."
650671 ):
651672 security_token ._read_security_token_file ("test_security_token" )
652673
0 commit comments