1- # Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+ # Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22#
33# Licensed under the Apache License, Version 2.0 (the "License"). You
44# may not use this file except in compliance with the License. A copy of
3131SAMPLE_PARAM_RANGES = [{"Name" : "mini_batch_size" , "MinValue" : "10" , "MaxValue" : "100" }]
3232
3333REGION = "us-west-2"
34+ STS_ENDPOINT = "sts.us-west-2.amazonaws.com"
3435
3536
3637@pytest .fixture ()
@@ -88,7 +89,9 @@ def test_get_execution_role_throws_exception_if_arn_is_not_role_with_role_in_nam
8889def test_get_caller_identity_arn_from_an_user (boto_session ):
8990 sess = Session (boto_session )
9091 arn = "arn:aws:iam::369233609183:user/mia"
91- sess .boto_session .client ("sts" ).get_caller_identity .return_value = {"Arn" : arn }
92+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
93+ "Arn" : arn
94+ }
9295 sess .boto_session .client ("iam" ).get_role .return_value = {"Role" : {"Arn" : arn }}
9396
9497 actual = sess .get_caller_identity_arn ()
@@ -98,7 +101,9 @@ def test_get_caller_identity_arn_from_an_user(boto_session):
98101def test_get_caller_identity_arn_from_an_user_without_permissions (boto_session ):
99102 sess = Session (boto_session )
100103 arn = "arn:aws:iam::369233609183:user/mia"
101- sess .boto_session .client ("sts" ).get_caller_identity .return_value = {"Arn" : arn }
104+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
105+ "Arn" : arn
106+ }
102107 sess .boto_session .client ("iam" ).get_role .side_effect = ClientError ({}, {})
103108
104109 with patch ("logging.Logger.warning" ) as mock_logger :
@@ -112,7 +117,9 @@ def test_get_caller_identity_arn_from_a_role(boto_session):
112117 arn = (
113118 "arn:aws:sts::369233609183:assumed-role/SageMakerRole/6d009ef3-5306-49d5-8efc-78db644d8122"
114119 )
115- sess .boto_session .client ("sts" ).get_caller_identity .return_value = {"Arn" : arn }
120+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
121+ "Arn" : arn
122+ }
116123
117124 expected_role = "arn:aws:iam::369233609183:role/SageMakerRole"
118125 sess .boto_session .client ("iam" ).get_role .return_value = {"Role" : {"Arn" : expected_role }}
@@ -124,7 +131,9 @@ def test_get_caller_identity_arn_from_a_role(boto_session):
124131def test_get_caller_identity_arn_from_a_execution_role (boto_session ):
125132 sess = Session (boto_session )
126133 arn = "arn:aws:sts::369233609183:assumed-role/AmazonSageMaker-ExecutionRole-20171129T072388/SageMaker"
127- sess .boto_session .client ("sts" ).get_caller_identity .return_value = {"Arn" : arn }
134+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
135+ "Arn" : arn
136+ }
128137 sess .boto_session .client ("iam" ).get_role .return_value = {"Role" : {"Arn" : arn }}
129138
130139 actual = sess .get_caller_identity_arn ()
@@ -138,7 +147,7 @@ def test_get_caller_identity_arn_from_role_with_path(boto_session):
138147 sess = Session (boto_session )
139148 arn_prefix = "arn:aws:iam::369233609183:role"
140149 role_name = "name"
141- sess .boto_session .client ("sts" ).get_caller_identity .return_value = {
150+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
142151 "Arn" : "/" .join ([arn_prefix , role_name ])
143152 }
144153
@@ -344,7 +353,9 @@ def test_s3_input_all_arguments():
344353@pytest .fixture ()
345354def sagemaker_session ():
346355 boto_mock = Mock (name = "boto_session" )
347- boto_mock .client ("sts" ).get_caller_identity .return_value = {"Account" : "123" }
356+ boto_mock .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
357+ "Account" : "123"
358+ }
348359 ims = sagemaker .Session (boto_session = boto_mock , sagemaker_client = Mock ())
349360 ims .expand_role = Mock (return_value = EXPANDED_ROLE )
350361 return ims
0 commit comments