<s> import mock <EOL> from awscli . testutils import BaseAWSCommandParamsTest <EOL> from awscli . customizations . configservice . subscribe import S3BucketHelper <EOL> class TestSubscribe ( BaseAWSCommandParamsTest ) : <EOL> prefix = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( TestSubscribe , self ) . setUp ( ) <EOL> self . parsed_responses = [ <EOL> { } , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { } , <EOL> { } , <EOL> { } , <EOL> { '<STR_LIT>' : { } } , <EOL> { '<STR_LIT>' : { } } <EOL> ] <EOL> def test_subscribe_when_bucket_exists_and_new_sns_topic ( self ) : <EOL> self . prefix += '<STR_LIT>' <EOL> self . prefix += '<STR_LIT>' <EOL> self . run_cmd ( self . prefix ) <EOL> self . assertEqual ( len ( self . operations_called ) , <NUM_LIT:7> ) <EOL> list_of_operation_names_called = [ ] <EOL> list_of_parameters_called = [ ] <EOL> for operation_called in self . operations_called : <EOL> list_of_operation_names_called . append ( operation_called [ <NUM_LIT:0> ] . name ) <EOL> list_of_parameters_called . append ( operation_called [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( <EOL> list_of_operation_names_called , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> ) <EOL> self . assertEqual ( <EOL> list_of_parameters_called , [ <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT:default>' , '<STR_LIT>' : '<STR_LIT>' } } , <EOL> { '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT:default>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } , <EOL> { '<STR_LIT>' : '<STR_LIT:default>' } , <EOL> { } , <EOL> { } <EOL> ] <EOL> ) <EOL> def test_subscribe_when_bucket_exists_and_sns_topic_arn_provided ( self ) : <EOL> self . parsed_responses . pop ( <NUM_LIT:1> ) <EOL> self . prefix += '<STR_LIT>' <EOL> self . prefix += '<STR_LIT>' <EOL> self . run_cmd ( self . prefix ) <EOL> self . assertEqual ( len ( self . operations_called ) , <NUM_LIT:6> ) <EOL> list_of_operation_names_called = [ ] <EOL> list_of_parameters_called = [ ] <EOL> for operation_called in self . operations_called : <EOL> list_of_operation_names_called . append ( operation_called [ <NUM_LIT:0> ] . name ) <EOL> list_of_parameters_called . append ( operation_called [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( <EOL> list_of_operation_names_called , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> ) <EOL> self . assertEqual ( <EOL> list_of_parameters_called , [ <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT:default>' , '<STR_LIT>' : '<STR_LIT>' } } , <EOL> { '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT:default>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } , <EOL> { '<STR_LIT>' : '<STR_LIT:default>' } , <EOL> { } , <EOL> { } <EOL> ] <EOL> ) <EOL> def test_subscribe_when_bucket_needs_to_be_created ( self ) : <EOL> with mock . patch ( '<STR_LIT>' ) as http_session_send_patch : <EOL> head_bucket_response = mock . Mock ( ) <EOL> head_bucket_response . status_code = <NUM_LIT> <EOL> head_bucket_response . content = b'<STR_LIT>' <EOL> head_bucket_response . headers = { } <EOL> create_bucket_response = mock . Mock ( ) <EOL> create_bucket_response . status_code = <NUM_LIT:200> <EOL> create_bucket_response . content = b'<STR_LIT>' <EOL> create_bucket_response . headers = { } <EOL> http_session_send_patch . side_effect = [ <EOL> head_bucket_response , create_bucket_response <EOL> ] <EOL> s3_client = self . driver . session . create_client ( '<STR_LIT>' ) <EOL> bucket_helper = S3BucketHelper ( s3_client ) <EOL> bucket_helper . prepare_bucket ( '<STR_LIT>' ) <EOL> send_call_list = http_session_send_patch . call_args_list <EOL> self . assertEqual ( send_call_list [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . method , '<STR_LIT>' ) <EOL> self . assertEqual ( send_call_list [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . method , '<STR_LIT>' ) </s>
