@@ -41,7 +41,7 @@ def test_get_execution_role():
41
41
assert actual == 'arn:aws:iam::369233609183:role/SageMakerRole'
42
42
43
43
44
- def test_get_execution_role_works_with_servie_role ():
44
+ def test_get_execution_role_works_with_service_role ():
45
45
session = Mock ()
46
46
session .get_caller_identity_arn .return_value = \
47
47
'arn:aws:iam::369233609183:role/service-role/AmazonSageMaker-ExecutionRole-20171129T072388'
@@ -61,7 +61,9 @@ def test_get_execution_role_throws_exception_if_arn_is_not_role():
61
61
62
62
def test_get_caller_identity_arn_from_an_user (boto_session ):
63
63
sess = Session (boto_session )
64
- sess .boto_session .client ('sts' ).get_caller_identity .return_value = {'Arn' : 'arn:aws:iam::369233609183:user/mia' }
64
+ arn = 'arn:aws:iam::369233609183:user/mia'
65
+ sess .boto_session .client ('sts' ).get_caller_identity .return_value = {'Arn' : arn }
66
+ sess .boto_session .client ('iam' ).get_role .return_value = {'Role' : {'Arn' : arn }}
65
67
66
68
actual = sess .get_caller_identity_arn ()
67
69
assert actual == 'arn:aws:iam::369233609183:user/mia'
@@ -72,19 +74,37 @@ def test_get_caller_identity_arn_from_a_role(boto_session):
72
74
arn = 'arn:aws:sts::369233609183:assumed-role/SageMakerRole/6d009ef3-5306-49d5-8efc-78db644d8122'
73
75
sess .boto_session .client ('sts' ).get_caller_identity .return_value = {'Arn' : arn }
74
76
77
+ expected_role = 'arn:aws:iam::369233609183:role/SageMakerRole'
78
+ sess .boto_session .client ('iam' ).get_role .return_value = {'Role' : {'Arn' : expected_role }}
79
+
75
80
actual = sess .get_caller_identity_arn ()
76
- assert actual == 'arn:aws:iam::369233609183:role/SageMakerRole'
81
+ assert actual == expected_role
77
82
78
83
79
84
def test_get_caller_identity_arn_from_a_execution_role (boto_session ):
80
85
sess = Session (boto_session )
81
86
arn = 'arn:aws:sts::369233609183:assumed-role/AmazonSageMaker-ExecutionRole-20171129T072388/SageMaker'
82
87
sess .boto_session .client ('sts' ).get_caller_identity .return_value = {'Arn' : arn }
88
+ sess .boto_session .client ('iam' ).get_role .return_value = {'Role' : {'Arn' : arn }}
83
89
84
90
actual = sess .get_caller_identity_arn ()
85
91
assert actual == 'arn:aws:iam::369233609183:role/service-role/AmazonSageMaker-ExecutionRole-20171129T072388'
86
92
87
93
94
+ def test_get_caller_identity_arn_from_role_with_path (boto_session ):
95
+ sess = Session (boto_session )
96
+ arn_prefix = 'arn:aws:iam::369233609183:role'
97
+ role_name = 'name'
98
+ sess .boto_session .client ('sts' ).get_caller_identity .return_value = {'Arn' : '/' .join ([arn_prefix , role_name ])}
99
+
100
+ role_path = 'path'
101
+ role_with_path = '/' .join ([arn_prefix , role_path , role_name ])
102
+ sess .boto_session .client ('iam' ).get_role .return_value = {'Role' : {'Arn' : role_with_path }}
103
+
104
+ actual = sess .get_caller_identity_arn ()
105
+ assert actual == role_with_path
106
+
107
+
88
108
def test_delete_endpoint (boto_session ):
89
109
sess = Session (boto_session )
90
110
sess .delete_endpoint ('my_endpoint' )
@@ -95,15 +115,15 @@ def test_delete_endpoint(boto_session):
95
115
def test_s3_input_all_defaults ():
96
116
prefix = 'pre'
97
117
actual = s3_input (s3_data = prefix )
98
- expected = \
99
- { 'DataSource' : {
118
+ expected = {
119
+ 'DataSource' : {
100
120
'S3DataSource' : {
101
121
'S3DataDistributionType' : 'FullyReplicated' ,
102
122
'S3DataType' : 'S3Prefix' ,
103
123
'S3Uri' : prefix
104
124
}
105
125
}
106
- }
126
+ }
107
127
assert actual .config == expected
108
128
109
129
0 commit comments