<s> import mock <EOL> from ec2api . tests . unit import base <EOL> from ec2api . tests . unit import fakes <EOL> from ec2api . tests . unit import matchers <EOL> from ec2api . tests . unit import tools <EOL> class CustomerGatewayTestCase ( base . ApiTestCase ) : <EOL> def test_create_customer_gateway ( self ) : <EOL> self . db_api . add_item . side_effect = ( <EOL> tools . get_db_api_add_item ( fakes . ID_EC2_CUSTOMER_GATEWAY_2 ) ) <EOL> resp = self . execute ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . IP_CUSTOMER_GATEWAY_ADDRESS_2 , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( { '<STR_LIT>' : fakes . EC2_CUSTOMER_GATEWAY_2 } , <EOL> resp ) <EOL> self . db_api . add_item . assert_called_once_with ( <EOL> mock . ANY , '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . IP_CUSTOMER_GATEWAY_ADDRESS_2 } ) <EOL> resp = self . execute ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . IP_CUSTOMER_GATEWAY_ADDRESS_2 , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( { '<STR_LIT>' : fakes . EC2_CUSTOMER_GATEWAY_2 } , <EOL> resp ) <EOL> def test_create_customer_gateway_idempotent ( self ) : <EOL> self . set_mock_db_items ( fakes . DB_CUSTOMER_GATEWAY_1 ) <EOL> resp = self . execute ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . IP_CUSTOMER_GATEWAY_ADDRESS_1 , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( { '<STR_LIT>' : fakes . EC2_CUSTOMER_GATEWAY_1 } , <EOL> resp ) <EOL> self . assertFalse ( self . db_api . add_item . called ) <EOL> resp = self . execute ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . IP_CUSTOMER_GATEWAY_ADDRESS_1 , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( { '<STR_LIT>' : fakes . EC2_CUSTOMER_GATEWAY_1 } , <EOL> resp ) <EOL> self . assertFalse ( self . db_api . add_item . called ) <EOL> def test_create_customer_gateway_invalid_parameters ( self ) : <EOL> self . assert_execution_error ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . IP_CUSTOMER_GATEWAY_ADDRESS_1 , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_delete_customer_gateway ( self ) : <EOL> self . set_mock_db_items ( fakes . DB_CUSTOMER_GATEWAY_2 ) <EOL> resp = self . execute ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . ID_EC2_CUSTOMER_GATEWAY_2 } ) <EOL> self . assertEqual ( { '<STR_LIT>' : True } , resp ) <EOL> self . db_api . delete_item . assert_called_once_with ( <EOL> mock . ANY , fakes . ID_EC2_CUSTOMER_GATEWAY_2 ) <EOL> def test_delete_customer_gateway_invalid_parameters ( self ) : <EOL> self . set_mock_db_items ( ) <EOL> self . assert_execution_error ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . ID_EC2_CUSTOMER_GATEWAY_2 } ) <EOL> self . assertFalse ( self . db_api . delete_item . called ) <EOL> self . set_mock_db_items ( fakes . DB_CUSTOMER_GATEWAY_1 , <EOL> fakes . DB_VPN_CONNECTION_1 ) <EOL> self . assert_execution_error ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . ID_EC2_CUSTOMER_GATEWAY_1 } ) <EOL> self . assertFalse ( self . db_api . delete_item . called ) <EOL> def test_describe_customer_gateways ( self ) : <EOL> self . set_mock_db_items ( fakes . DB_CUSTOMER_GATEWAY_1 , <EOL> fakes . DB_CUSTOMER_GATEWAY_2 ) <EOL> resp = self . execute ( '<STR_LIT>' , { } ) <EOL> self . assertThat ( resp [ '<STR_LIT>' ] , <EOL> matchers . ListMatches ( [ fakes . EC2_CUSTOMER_GATEWAY_1 , <EOL> fakes . EC2_CUSTOMER_GATEWAY_2 ] ) ) <EOL> resp = self . execute ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . ID_EC2_CUSTOMER_GATEWAY_2 } ) <EOL> self . assertThat ( <EOL> resp [ '<STR_LIT>' ] , <EOL> matchers . ListMatches ( [ fakes . EC2_CUSTOMER_GATEWAY_2 ] ) ) <EOL> self . db_api . get_items_by_ids . assert_called_once_with ( <EOL> mock . ANY , set ( [ fakes . ID_EC2_CUSTOMER_GATEWAY_2 ] ) ) <EOL> self . check_filtering ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , fakes . ID_EC2_CUSTOMER_GATEWAY_2 ) , <EOL> ( '<STR_LIT>' , fakes . IP_CUSTOMER_GATEWAY_ADDRESS_2 ) , <EOL> ( '<STR_LIT:state>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:type>' , '<STR_LIT>' ) ] ) <EOL> self . check_tag_support ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> fakes . ID_EC2_CUSTOMER_GATEWAY_2 , '<STR_LIT>' ) </s>
