<s> from __future__ import unicode_literals <EOL> import tests . backport_assert_raises <EOL> from nose . tools import assert_raises <EOL> import re <EOL> import boto <EOL> from boto . exception import EC2ResponseError <EOL> import sure <EOL> from moto import mock_ec2 <EOL> VPC_CIDR = "<STR_LIT>" <EOL> BAD_VPC = "<STR_LIT>" <EOL> BAD_IGW = "<STR_LIT>" <EOL> @ mock_ec2 <EOL> def test_igw_create ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> conn . get_all_internet_gateways ( ) . should . have . length_of ( <NUM_LIT:0> ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> conn . get_all_internet_gateways ( ) . should . have . length_of ( <NUM_LIT:1> ) <EOL> igw . id . should . match ( r'<STR_LIT>' ) <EOL> igw = conn . get_all_internet_gateways ( ) [ <NUM_LIT:0> ] <EOL> igw . attachments . should . have . length_of ( <NUM_LIT:0> ) <EOL> @ mock_ec2 <EOL> def test_igw_attach ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> vpc = conn . create_vpc ( VPC_CIDR ) <EOL> conn . attach_internet_gateway ( igw . id , vpc . id ) <EOL> igw = conn . get_all_internet_gateways ( ) [ <NUM_LIT:0> ] <EOL> igw . attachments [ <NUM_LIT:0> ] . vpc_id . should . be . equal ( vpc . id ) <EOL> @ mock_ec2 <EOL> def test_igw_attach_bad_vpc ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> with assert_raises ( EC2ResponseError ) as cm : <EOL> conn . attach_internet_gateway ( igw . id , BAD_VPC ) <EOL> cm . exception . code . should . equal ( '<STR_LIT>' ) <EOL> cm . exception . status . should . equal ( <NUM_LIT> ) <EOL> cm . exception . request_id . should_not . be . none <EOL> @ mock_ec2 <EOL> def test_igw_attach_twice ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> vpc1 = conn . create_vpc ( VPC_CIDR ) <EOL> vpc2 = conn . create_vpc ( VPC_CIDR ) <EOL> conn . attach_internet_gateway ( igw . id , vpc1 . id ) <EOL> with assert_raises ( EC2ResponseError ) as cm : <EOL> conn . attach_internet_gateway ( igw . id , vpc2 . id ) <EOL> cm . exception . code . should . equal ( '<STR_LIT>' ) <EOL> cm . exception . status . should . equal ( <NUM_LIT> ) <EOL> cm . exception . request_id . should_not . be . none <EOL> @ mock_ec2 <EOL> def test_igw_detach ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> vpc = conn . create_vpc ( VPC_CIDR ) <EOL> conn . attach_internet_gateway ( igw . id , vpc . id ) <EOL> conn . detach_internet_gateway ( igw . id , vpc . id ) <EOL> igw = conn . get_all_internet_gateways ( ) [ <NUM_LIT:0> ] <EOL> igw . attachments . should . have . length_of ( <NUM_LIT:0> ) <EOL> @ mock_ec2 <EOL> def test_igw_detach_wrong_vpc ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> vpc1 = conn . create_vpc ( VPC_CIDR ) <EOL> vpc2 = conn . create_vpc ( VPC_CIDR ) <EOL> conn . attach_internet_gateway ( igw . id , vpc1 . id ) <EOL> with assert_raises ( EC2ResponseError ) as cm : <EOL> conn . detach_internet_gateway ( igw . id , vpc2 . id ) <EOL> cm . exception . code . should . equal ( '<STR_LIT>' ) <EOL> cm . exception . status . should . equal ( <NUM_LIT> ) <EOL> cm . exception . request_id . should_not . be . none <EOL> @ mock_ec2 <EOL> def test_igw_detach_invalid_vpc ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> vpc = conn . create_vpc ( VPC_CIDR ) <EOL> conn . attach_internet_gateway ( igw . id , vpc . id ) <EOL> with assert_raises ( EC2ResponseError ) as cm : <EOL> conn . detach_internet_gateway ( igw . id , BAD_VPC ) <EOL> cm . exception . code . should . equal ( '<STR_LIT>' ) <EOL> cm . exception . status . should . equal ( <NUM_LIT> ) <EOL> cm . exception . request_id . should_not . be . none <EOL> @ mock_ec2 <EOL> def test_igw_detach_unattached ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> vpc = conn . create_vpc ( VPC_CIDR ) <EOL> with assert_raises ( EC2ResponseError ) as cm : <EOL> conn . detach_internet_gateway ( igw . id , vpc . id ) <EOL> cm . exception . code . should . equal ( '<STR_LIT>' ) <EOL> cm . exception . status . should . equal ( <NUM_LIT> ) <EOL> cm . exception . request_id . should_not . be . none <EOL> @ mock_ec2 <EOL> def test_igw_delete ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> vpc = conn . create_vpc ( VPC_CIDR ) <EOL> conn . get_all_internet_gateways ( ) . should . have . length_of ( <NUM_LIT:0> ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> conn . get_all_internet_gateways ( ) . should . have . length_of ( <NUM_LIT:1> ) <EOL> conn . delete_internet_gateway ( igw . id ) <EOL> conn . get_all_internet_gateways ( ) . should . have . length_of ( <NUM_LIT:0> ) <EOL> @ mock_ec2 <EOL> def test_igw_delete_attached ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> vpc = conn . create_vpc ( VPC_CIDR ) <EOL> conn . attach_internet_gateway ( igw . id , vpc . id ) <EOL> with assert_raises ( EC2ResponseError ) as cm : <EOL> conn . delete_internet_gateway ( igw . id ) <EOL> cm . exception . code . should . equal ( '<STR_LIT>' ) <EOL> cm . exception . status . should . equal ( <NUM_LIT> ) <EOL> cm . exception . request_id . should_not . be . none <EOL> @ mock_ec2 <EOL> def test_igw_desribe ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw = conn . create_internet_gateway ( ) <EOL> igw_by_search = conn . get_all_internet_gateways ( [ igw . id ] ) [ <NUM_LIT:0> ] <EOL> igw . id . should . equal ( igw_by_search . id ) <EOL> @ mock_ec2 <EOL> def test_igw_desribe_bad_id ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> with assert_raises ( EC2ResponseError ) as cm : <EOL> conn . get_all_internet_gateways ( [ BAD_IGW ] ) <EOL> cm . exception . code . should . equal ( '<STR_LIT>' ) <EOL> cm . exception . status . should . equal ( <NUM_LIT> ) <EOL> cm . exception . request_id . should_not . be . none <EOL> @ mock_ec2 <EOL> def test_igw_filter_by_vpc_id ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw1 = conn . create_internet_gateway ( ) <EOL> igw2 = conn . create_internet_gateway ( ) <EOL> vpc = conn . create_vpc ( VPC_CIDR ) <EOL> conn . attach_internet_gateway ( igw1 . id , vpc . id ) <EOL> result = conn . get_all_internet_gateways ( filters = { "<STR_LIT>" : vpc . id } ) <EOL> result . should . have . length_of ( <NUM_LIT:1> ) <EOL> result [ <NUM_LIT:0> ] . id . should . equal ( igw1 . id ) <EOL> @ mock_ec2 <EOL> def test_igw_filter_by_tags ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw1 = conn . create_internet_gateway ( ) <EOL> igw2 = conn . create_internet_gateway ( ) <EOL> igw1 . add_tag ( "<STR_LIT>" , "<STR_LIT:yes>" ) <EOL> result = conn . get_all_internet_gateways ( filters = { "<STR_LIT>" : "<STR_LIT:yes>" } ) <EOL> result . should . have . length_of ( <NUM_LIT:1> ) <EOL> result [ <NUM_LIT:0> ] . id . should . equal ( igw1 . id ) <EOL> @ mock_ec2 <EOL> def test_igw_filter_by_internet_gateway_id ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw1 = conn . create_internet_gateway ( ) <EOL> igw2 = conn . create_internet_gateway ( ) <EOL> result = conn . get_all_internet_gateways ( filters = { "<STR_LIT>" : igw1 . id } ) <EOL> result . should . have . length_of ( <NUM_LIT:1> ) <EOL> result [ <NUM_LIT:0> ] . id . should . equal ( igw1 . id ) <EOL> @ mock_ec2 <EOL> def test_igw_filter_by_attachment_state ( ) : <EOL> """<STR_LIT>""" <EOL> conn = boto . connect_vpc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> igw1 = conn . create_internet_gateway ( ) <EOL> igw2 = conn . create_internet_gateway ( ) <EOL> vpc = conn . create_vpc ( VPC_CIDR ) <EOL> conn . attach_internet_gateway ( igw1 . id , vpc . id ) <EOL> result = conn . get_all_internet_gateways ( filters = { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> result . should . have . length_of ( <NUM_LIT:1> ) <EOL> result [ <NUM_LIT:0> ] . id . should . equal ( igw1 . id ) </s>
