desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Tests checking vpc existence via cidr when vpc exists'
@mock_ec2 def test_that_when_checking_if_a_vpc_exists_by_cidr_and_a_vpc_exists_the_vpc_exists_method_returns_true(self):
self._create_vpc() vpc_exists_result = boto_vpc.exists(cidr=u'10.0.0.0/24', **conn_parameters) self.assertTrue(vpc_exists_result['exists'])
'Tests checking vpc existence via cidr when vpc does not exist'
@mock_ec2 def test_that_when_checking_if_a_vpc_exists_by_cidr_and_a_vpc_does_not_exist_the_vpc_exists_method_returns_false(self):
self._create_vpc() vpc_exists_result = boto_vpc.exists(cidr=u'10.10.10.10/24', **conn_parameters) self.assertFalse(vpc_exists_result['exists'])
'Tests checking vpc existence when no filters are provided'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_that_when_checking_if_a_vpc_exists_but_providing_no_filters_the_vpc_exists_method_raises_a_salt_invocation_error(self):
with self.assertRaisesRegex(SaltInvocationError, 'At least one of the following must be provided: vpc_id, vpc_name, cidr or tags.'): boto_vpc.exists(**conn_parameters)
'Tests getting vpc id when filtering by name'
@mock_ec2 def test_get_vpc_id_method_when_filtering_by_name(self):
vpc = self._create_vpc(name='test') get_id_result = boto_vpc.get_id(name='test', **conn_parameters) self.assertEqual(vpc.id, get_id_result['id'])
'Tests getting vpc id when filtering by invalid name'
@mock_ec2 def test_get_vpc_id_method_when_filtering_by_invalid_name(self):
self._create_vpc(name='test') get_id_result = boto_vpc.get_id(name='test_fake', **conn_parameters) self.assertEqual(get_id_result['id'], None)
'Tests getting vpc id when filtering by cidr'
@mock_ec2 def test_get_vpc_id_method_when_filtering_by_cidr(self):
vpc = self._create_vpc() get_id_result = boto_vpc.get_id(cidr=u'10.0.0.0/24', **conn_parameters) self.assertEqual(vpc.id, get_id_result['id'])
'Tests getting vpc id when filtering by invalid cidr'
@mock_ec2 def test_get_vpc_id_method_when_filtering_by_invalid_cidr(self):
self._create_vpc() get_id_result = boto_vpc.get_id(cidr=u'10.10.10.10/24', **conn_parameters) self.assertEqual(get_id_result['id'], None)
'Tests getting vpc id when filtering by tags'
@mock_ec2 def test_get_vpc_id_method_when_filtering_by_tags(self):
vpc = self._create_vpc(tags={'test': 'testvalue'}) get_id_result = boto_vpc.get_id(tags={'test': 'testvalue'}, **conn_parameters) self.assertEqual(vpc.id, get_id_result['id'])
'Tests getting vpc id when filtering by invalid tags'
@mock_ec2 def test_get_vpc_id_method_when_filtering_by_invalid_tags(self):
self._create_vpc(tags={'test': 'testvalue'}) get_id_result = boto_vpc.get_id(tags={'test': 'fake-testvalue'}, **conn_parameters) self.assertEqual(get_id_result['id'], None)
'Tests getting vpc id but providing no filters'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_get_vpc_id_method_when_not_providing_filters_raises_a_salt_invocation_error(self):
with self.assertRaisesRegex(SaltInvocationError, 'At least one of the following must be provided: vpc_id, vpc_name, cidr or tags.'): boto_vpc.get_id(**conn_parameters)
'Tests getting vpc id but providing no filters'
@mock_ec2 def test_get_vpc_id_method_when_more_than_one_vpc_is_matched_raises_a_salt_command_execution_error(self):
vpc1 = self._create_vpc(name='vpc-test1') vpc2 = self._create_vpc(name='vpc-test2') with self.assertRaisesRegex(CommandExecutionError, 'Found more than one VPC matching the criteria.'): boto_vpc.get_id(cidr=u'10.0.0.0/24', **conn_parameters)
'tests True VPC created.'
@mock_ec2 def test_that_when_creating_a_vpc_succeeds_the_create_vpc_method_returns_true(self):
vpc_creation_result = boto_vpc.create(cidr_block, **conn_parameters) self.assertTrue(vpc_creation_result)
'tests True VPC created.'
@mock_ec2 def test_that_when_creating_a_vpc_and_specifying_a_vpc_name_succeeds_the_create_vpc_method_returns_true(self):
vpc_creation_result = boto_vpc.create(cidr_block, vpc_name='test', **conn_parameters) self.assertTrue(vpc_creation_result)
'tests True VPC created.'
@mock_ec2 def test_that_when_creating_a_vpc_and_specifying_tags_succeeds_the_create_vpc_method_returns_true(self):
vpc_creation_result = boto_vpc.create(cidr_block, tags={'test': 'value'}, **conn_parameters) self.assertTrue(vpc_creation_result)
'tests False VPC not created.'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_that_when_creating_a_vpc_fails_the_create_vpc_method_returns_false(self):
with patch('moto.ec2.models.VPCBackend.create_vpc', side_effect=BotoServerError(400, 'Mocked error')): vpc_creation_result = boto_vpc.create(cidr_block, **conn_parameters) self.assertFalse(vpc_creation_result['created']) self.assertTrue(('error' in vpc_creation_result))
'Tests deleting an existing vpc'
@mock_ec2 def test_that_when_deleting_an_existing_vpc_the_delete_vpc_method_returns_true(self):
vpc = self._create_vpc() vpc_deletion_result = boto_vpc.delete(vpc.id, **conn_parameters) self.assertTrue(vpc_deletion_result)
'Tests deleting a non-existent vpc'
@mock_ec2 def test_that_when_deleting_a_non_existent_vpc_the_delete_vpc_method_returns_false(self):
delete_vpc_result = boto_vpc.delete('1234', **conn_parameters) self.assertFalse(delete_vpc_result['deleted'])
'Tests describing parameters via vpc id if vpc exist'
@mock_ec2 def test_that_when_describing_vpc_by_id_it_returns_the_dict_of_properties_returns_true(self):
if (LooseVersion('0.4.25') <= _get_moto_version() < LooseVersion('0.4.31')): is_default = True else: is_default = False vpc = self._create_vpc(name='test', tags={'test': 'testvalue'}) describe_vpc = boto_vpc.describe(vpc_id=vpc.id, **conn_parameters) vpc_properties = dict(id=vpc.id, cidr_block=six.text_type(cidr_block), is_default=is_default, state=u'available', tags={u'Name': u'test', u'test': u'testvalue'}, dhcp_options_id=u'dopt-7a8b9c2d', region=u'us-east-1', instance_tenancy=u'default') self.assertEqual(describe_vpc, {'vpc': vpc_properties})
'Tests describing parameters via vpc id if vpc does not exist'
@mock_ec2 def test_that_when_describing_vpc_by_id_it_returns_the_dict_of_properties_returns_false(self):
vpc = self._create_vpc(name='test', tags={'test': 'testvalue'}) describe_vpc = boto_vpc.describe(vpc_id='vpc-fake', **conn_parameters) self.assertFalse(describe_vpc['vpc'])
'Tests describing parameters failure'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_that_when_describing_vpc_by_id_on_connection_error_it_returns_error(self):
vpc = self._create_vpc(name='test', tags={'test': 'testvalue'}) with patch('moto.ec2.models.VPCBackend.get_all_vpcs', side_effect=BotoServerError(400, 'Mocked error')): describe_result = boto_vpc.describe(vpc_id=vpc.id, **conn_parameters) self.assertTrue(('error' in describe_result))
'Tests describing vpc without vpc id'
@mock_ec2 def test_that_when_describing_vpc_but_providing_no_vpc_id_the_describe_method_raises_a_salt_invocation_error(self):
with self.assertRaisesRegex(SaltInvocationError, 'A valid vpc id or name needs to be specified.'): boto_vpc.describe(vpc_id=None, **conn_parameters)
'tests that given multiple subnet ids in the same VPC that the VPC ID is returned. The test is valuable because it uses a string as an argument to subnets as opposed to a list.'
@mock_ec2 def test_get_subnet_association_single_subnet(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) subnet_association = boto_vpc.get_subnet_association(subnets=subnet.id, **conn_parameters) self.assertEqual(vpc.id, subnet_association['vpc_id'])
'tests that given multiple subnet ids in the same VPC that the VPC ID is returned.'
@mock_ec2 def test_get_subnet_association_multiple_subnets_same_vpc(self):
vpc = self._create_vpc() subnet_a = self._create_subnet(vpc.id, '10.0.0.0/25') subnet_b = self._create_subnet(vpc.id, '10.0.0.128/25') subnet_association = boto_vpc.get_subnet_association([subnet_a.id, subnet_b.id], **conn_parameters) self.assertEqual(vpc.id, subnet_association['vpc_id'])
'tests that given multiple subnet ids in different VPCs that False is returned.'
@mock_ec2 def test_get_subnet_association_multiple_subnets_different_vpc(self):
vpc_a = self._create_vpc() vpc_b = self.conn.create_vpc(cidr_block) subnet_a = self._create_subnet(vpc_a.id, '10.0.0.0/24') subnet_b = self._create_subnet(vpc_b.id, '10.0.0.0/24') subnet_association = boto_vpc.get_subnet_association([subnet_a.id, subnet_b.id], **conn_parameters) self.assertEqual(set(subnet_association['vpc_ids']), set([vpc_a.id, vpc_b.id]))
'Tests creating a subnet successfully'
@mock_ec2 def test_that_when_creating_a_subnet_succeeds_the_create_subnet_method_returns_true(self):
vpc = self._create_vpc() subnet_creation_result = boto_vpc.create_subnet(vpc.id, '10.0.0.0/24', **conn_parameters) self.assertTrue(subnet_creation_result['created']) self.assertTrue(('id' in subnet_creation_result))
'Tests creating a subnet successfully when specifying a name'
@mock_ec2 def test_that_when_creating_a_subnet_and_specifying_a_name_succeeds_the_create_subnet_method_returns_true(self):
vpc = self._create_vpc() subnet_creation_result = boto_vpc.create_subnet(vpc.id, '10.0.0.0/24', subnet_name='test', **conn_parameters) self.assertTrue(subnet_creation_result['created'])
'Tests creating a subnet successfully when specifying a tag'
@mock_ec2 def test_that_when_creating_a_subnet_and_specifying_tags_succeeds_the_create_subnet_method_returns_true(self):
vpc = self._create_vpc() subnet_creation_result = boto_vpc.create_subnet(vpc.id, '10.0.0.0/24', tags={'test': 'testvalue'}, **conn_parameters) self.assertTrue(subnet_creation_result['created'])
'Tests creating a subnet failure'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_that_when_creating_a_subnet_fails_the_create_subnet_method_returns_error(self):
vpc = self._create_vpc() with patch('moto.ec2.models.SubnetBackend.create_subnet', side_effect=BotoServerError(400, 'Mocked error')): subnet_creation_result = boto_vpc.create_subnet(vpc.id, '10.0.0.0/24', **conn_parameters) self.assertTrue(('error' in subnet_creation_result))
'Tests deleting an existing subnet'
@mock_ec2 def test_that_when_deleting_an_existing_subnet_the_delete_subnet_method_returns_true(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) subnet_deletion_result = boto_vpc.delete_subnet(subnet_id=subnet.id, **conn_parameters) self.assertTrue(subnet_deletion_result['deleted'])
'Tests deleting a subnet that doesn\'t exist'
@mock_ec2 def test_that_when_deleting_a_non_existent_subnet_the_delete_vpc_method_returns_false(self):
delete_subnet_result = boto_vpc.delete_subnet(subnet_id='1234', **conn_parameters) self.assertTrue(('error' in delete_subnet_result))
'Tests checking if a subnet exists when it does exist'
@mock_ec2 def test_that_when_checking_if_a_subnet_exists_by_id_the_subnet_exists_method_returns_true(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) subnet_exists_result = boto_vpc.subnet_exists(subnet_id=subnet.id, **conn_parameters) self.assertTrue(subnet_exists_result['exists'])
'Tests checking if a subnet exists which doesn\'t exist'
@mock_ec2 def test_that_when_a_subnet_does_not_exist_the_subnet_exists_method_returns_false(self):
subnet_exists_result = boto_vpc.subnet_exists('fake', **conn_parameters) self.assertFalse(subnet_exists_result['exists'])
'Tests checking subnet existence by name'
@mock_ec2 def test_that_when_checking_if_a_subnet_exists_by_name_the_subnet_exists_method_returns_true(self):
vpc = self._create_vpc() self._create_subnet(vpc.id, name='test') subnet_exists_result = boto_vpc.subnet_exists(name='test', **conn_parameters) self.assertTrue(subnet_exists_result['exists'])
'Tests checking subnet existence by name when it doesn\'t exist'
@mock_ec2 def test_that_when_checking_if_a_subnet_exists_by_name_the_subnet_does_not_exist_the_subnet_method_returns_false(self):
vpc = self._create_vpc() self._create_subnet(vpc.id) subnet_exists_result = boto_vpc.subnet_exists(name='test', **conn_parameters) self.assertFalse(subnet_exists_result['exists'])
'Tests checking subnet existence by tag'
@mock_ec2 def test_that_when_checking_if_a_subnet_exists_by_tags_the_subnet_exists_method_returns_true(self):
vpc = self._create_vpc() self._create_subnet(vpc.id, tags={'test': 'testvalue'}) subnet_exists_result = boto_vpc.subnet_exists(tags={'test': 'testvalue'}, **conn_parameters) self.assertTrue(subnet_exists_result['exists'])
'Tests checking subnet existence by tag when subnet doesn\'t exist'
@mock_ec2 def test_that_when_checking_if_a_subnet_exists_by_tags_the_subnet_does_not_exist_the_subnet_method_returns_false(self):
vpc = self._create_vpc() self._create_subnet(vpc.id) subnet_exists_result = boto_vpc.subnet_exists(tags={'test': 'testvalue'}, **conn_parameters) self.assertFalse(subnet_exists_result['exists'])
'Tests checking subnet existence without any filters'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_that_when_checking_if_a_subnet_exists_but_providing_no_filters_the_subnet_exists_method_raises_a_salt_invocation_error(self):
with self.assertRaisesRegex(SaltInvocationError, 'At least one of the following must be specified: subnet id, cidr, subnet_name, tags, or zones.'): boto_vpc.subnet_exists(**conn_parameters)
'Tests describing a subnet by id.'
@skipIf(True, 'Skip these tests while investigating failures') @mock_ec2 def test_that_describe_subnet_by_id_for_existing_subnet_returns_correct_data(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) describe_subnet_results = boto_vpc.describe_subnet(region=region, key=secret_key, keyid=access_key, subnet_id=subnet.id) self.assertEqual(set(describe_subnet_results['subnet'].keys()), set(['id', 'cidr_block', 'availability_zone', 'tags']))
'Tests describing a non-existent subnet by id.'
@mock_ec2 def test_that_describe_subnet_by_id_for_non_existent_subnet_returns_none(self):
self._create_vpc() describe_subnet_results = boto_vpc.describe_subnet(region=region, key=secret_key, keyid=access_key, subnet_id='subnet-a1b2c3') self.assertEqual(describe_subnet_results['subnet'], None)
'Tests describing a subnet by name.'
@skipIf(True, 'Skip these tests while investigating failures') @mock_ec2 def test_that_describe_subnet_by_name_for_existing_subnet_returns_correct_data(self):
vpc = self._create_vpc() self._create_subnet(vpc.id, name='test') describe_subnet_results = boto_vpc.describe_subnet(region=region, key=secret_key, keyid=access_key, subnet_name='test') self.assertEqual(set(describe_subnet_results['subnet'].keys()), set(['id', 'cidr_block', 'availability_zone', 'tags']))
'Tests describing a non-existent subnet by id.'
@mock_ec2 def test_that_describe_subnet_by_name_for_non_existent_subnet_returns_none(self):
self._create_vpc() describe_subnet_results = boto_vpc.describe_subnet(region=region, key=secret_key, keyid=access_key, subnet_name='test') self.assertEqual(describe_subnet_results['subnet'], None)
'Tests describing multiple subnets by id.'
@skipIf(True, 'Skip these tests while investigating failures') @mock_ec2 def test_that_describe_subnets_by_id_for_existing_subnet_returns_correct_data(self):
vpc = self._create_vpc() subnet1 = self._create_subnet(vpc.id) subnet2 = self._create_subnet(vpc.id) describe_subnet_results = boto_vpc.describe_subnets(region=region, key=secret_key, keyid=access_key, subnet_ids=[subnet1.id, subnet2.id]) self.assertEqual(len(describe_subnet_results['subnets']), 2) self.assertEqual(set(describe_subnet_results['subnets'][0].keys()), set(['id', 'cidr_block', 'availability_zone', 'tags']))
'Tests describing multiple subnets by id.'
@skipIf(True, 'Skip these tests while investigating failures') @mock_ec2 def test_that_describe_subnets_by_name_for_existing_subnets_returns_correct_data(self):
vpc = self._create_vpc() self._create_subnet(vpc.id, name='subnet1') self._create_subnet(vpc.id, name='subnet2') describe_subnet_results = boto_vpc.describe_subnets(region=region, key=secret_key, keyid=access_key, subnet_names=['subnet1', 'subnet2']) self.assertEqual(len(describe_subnet_results['subnets']), 2) self.assertEqual(set(describe_subnet_results['subnets'][0].keys()), set(['id', 'cidr_block', 'availability_zone', 'tags']))
'Tests that the availability_zone kwarg is passed on to _create_resource'
@mock_ec2 def test_create_subnet_passes_availability_zone(self):
vpc = self._create_vpc() self._create_subnet(vpc.id, name='subnet1', availability_zone='us-east-1a') describe_subnet_results = boto_vpc.describe_subnets(region=region, key=secret_key, keyid=access_key, subnet_names=['subnet1']) self.assertEqual(describe_subnet_results['subnets'][0]['availability_zone'], 'us-east-1a')
'Tests creating an internet gateway successfully (with no vpc id or name)'
@mock_ec2 def test_that_when_creating_an_internet_gateway_the_create_internet_gateway_method_returns_true(self):
igw_creation_result = boto_vpc.create_internet_gateway(region=region, key=secret_key, keyid=access_key) self.assertTrue(igw_creation_result.get('created'))
'Tests that creating an internet gateway for a non-existent VPC fails.'
@mock_ec2 def test_that_when_creating_an_internet_gateway_with_non_existent_vpc_the_create_internet_gateway_method_returns_an_error(self):
igw_creation_result = boto_vpc.create_internet_gateway(region=region, key=secret_key, keyid=access_key, vpc_name='non-existent-vpc') self.assertTrue(('error' in igw_creation_result))
'Tests creating an internet gateway with vpc name specified.'
@mock_ec2 def test_that_when_creating_an_internet_gateway_with_vpc_name_specified_the_create_internet_gateway_method_returns_true(self):
self._create_vpc(name='test-vpc') igw_creation_result = boto_vpc.create_internet_gateway(region=region, key=secret_key, keyid=access_key, vpc_name='test-vpc') self.assertTrue(igw_creation_result.get('created'))
'Tests creating an internet gateway with vpc name specified.'
@mock_ec2 def test_that_when_creating_an_internet_gateway_with_vpc_id_specified_the_create_internet_gateway_method_returns_true(self):
vpc = self._create_vpc() igw_creation_result = boto_vpc.create_internet_gateway(region=region, key=secret_key, keyid=access_key, vpc_id=vpc.id) self.assertTrue(igw_creation_result.get('created'))
'Tests creating an nat gateway successfully (with subnet_id specified)'
@mock_ec2 def test_that_when_creating_an_nat_gateway_the_create_nat_gateway_method_returns_true(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id, name='subnet1', availability_zone='us-east-1a') ngw_creation_result = boto_vpc.create_nat_gateway(subnet_id=subnet.id, region=region, key=secret_key, keyid=access_key) self.assertTrue(ngw_creation_result.get('created'))
'Tests that creating an nat gateway for a non-existent subnet fails.'
@mock_ec2 def test_that_when_creating_an_nat_gateway_with_non_existent_subnet_the_create_nat_gateway_method_returns_an_error(self):
ngw_creation_result = boto_vpc.create_nat_gateway(region=region, key=secret_key, keyid=access_key, subnet_name='non-existent-subnet') self.assertTrue(('error' in ngw_creation_result))
'Tests creating an nat gateway with subnet name specified.'
@mock_ec2 def test_that_when_creating_an_nat_gateway_with_subnet_name_specified_the_create_nat_gateway_method_returns_true(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id, name='test-subnet', availability_zone='us-east-1a') ngw_creation_result = boto_vpc.create_nat_gateway(region=region, key=secret_key, keyid=access_key, subnet_name='test-subnet') self.assertTrue(ngw_creation_result.get('created'))
'Tests creating an internet gateway successfully (with no vpc id or name)'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_a_customer_gateway_the_create_customer_gateway_method_returns_true(self):
gw_creation_result = boto_vpc.create_customer_gateway('ipsec.1', '10.1.1.1', None) self.assertTrue(gw_creation_result.get('created'))
'Tests checking if a subnet exists when it does exist'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_checking_if_a_subnet_exists_by_id_the_subnet_exists_method_returns_true(self):
gw_creation_result = boto_vpc.create_customer_gateway('ipsec.1', '10.1.1.1', None) gw_exists_result = boto_vpc.customer_gateway_exists(customer_gateway_id=gw_creation_result['id']) self.assertTrue(gw_exists_result['exists'])
'Tests checking if a subnet exists which doesn\'t exist'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_a_subnet_does_not_exist_the_subnet_exists_method_returns_false(self):
gw_exists_result = boto_vpc.customer_gateway_exists('fake') self.assertFalse(gw_exists_result['exists'])
'Tests creating dhcp options successfully'
@mock_ec2 def test_that_when_creating_dhcp_options_succeeds_the_create_dhcp_options_method_returns_true(self):
dhcp_options_creation_result = boto_vpc.create_dhcp_options(**dhcp_options_parameters) self.assertTrue(dhcp_options_creation_result['created'])
'Tests creating dchp options with name successfully'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_dhcp_options_and_specifying_a_name_succeeds_the_create_dhcp_options_method_returns_true(self):
dhcp_options_creation_result = boto_vpc.create_dhcp_options(dhcp_options_name='test', **dhcp_options_parameters) self.assertTrue(dhcp_options_creation_result['created'])
'Tests creating dchp options with tag successfully'
@mock_ec2 def test_that_when_creating_dhcp_options_and_specifying_tags_succeeds_the_create_dhcp_options_method_returns_true(self):
dhcp_options_creation_result = boto_vpc.create_dhcp_options(tags={'test': 'testvalue'}, **dhcp_options_parameters) self.assertTrue(dhcp_options_creation_result['created'])
'Tests creating dhcp options failure'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_that_when_creating_dhcp_options_fails_the_create_dhcp_options_method_returns_error(self):
with patch('moto.ec2.models.DHCPOptionsSetBackend.create_dhcp_options', side_effect=BotoServerError(400, 'Mocked error')): r = dhcp_options_creation_result = boto_vpc.create_dhcp_options(**dhcp_options_parameters) self.assertTrue(('error' in r))
'Tests associating existing dchp options successfully'
@mock_ec2 def test_that_when_associating_an_existing_dhcp_options_set_to_an_existing_vpc_the_associate_dhcp_options_method_returns_true(self):
vpc = self._create_vpc() dhcp_options = self._create_dhcp_options() dhcp_options_association_result = boto_vpc.associate_dhcp_options_to_vpc(dhcp_options.id, vpc.id, **conn_parameters) self.assertTrue(dhcp_options_association_result['associated'])
'Tests associating non-existanct dhcp options successfully'
@mock_ec2 def test_that_when_associating_a_non_existent_dhcp_options_set_to_an_existing_vpc_the_associate_dhcp_options_method_returns_error(self):
vpc = self._create_vpc() dhcp_options_association_result = boto_vpc.associate_dhcp_options_to_vpc('fake', vpc.id, **conn_parameters) self.assertTrue(('error' in dhcp_options_association_result))
'Tests associating existing dhcp options to non-existence vpc'
@mock_ec2 def test_that_when_associating_an_existing_dhcp_options_set_to_a_non_existent_vpc_the_associate_dhcp_options_method_returns_false(self):
dhcp_options = self._create_dhcp_options() dhcp_options_association_result = boto_vpc.associate_dhcp_options_to_vpc(dhcp_options.id, 'fake', **conn_parameters) self.assertTrue(('error' in dhcp_options_association_result))
'Tests creation/association of dchp options to an existing vpc successfully'
@mock_ec2 def test_that_when_creating_dhcp_options_set_to_an_existing_vpc_succeeds_the_associate_new_dhcp_options_method_returns_true(self):
vpc = self._create_vpc() dhcp_creation_result = boto_vpc.create_dhcp_options(vpc_id=vpc.id, **dhcp_options_parameters) self.assertTrue(dhcp_creation_result['created'])
'Tests creation failure during creation/association of dchp options to an existing vpc'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_that_when_creating_and_associating_dhcp_options_set_to_an_existing_vpc_fails_creating_the_dhcp_options_the_associate_new_dhcp_options_method_raises_exception(self):
vpc = self._create_vpc() with patch('moto.ec2.models.DHCPOptionsSetBackend.create_dhcp_options', side_effect=BotoServerError(400, 'Mocked error')): r = boto_vpc.associate_new_dhcp_options_to_vpc(vpc.id, **dhcp_options_parameters) self.assertTrue(('error' in r))
'Tests association failure during creation/association of dchp options to existing vpc'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_that_when_creating_and_associating_dhcp_options_set_to_an_existing_vpc_fails_associating_the_dhcp_options_the_associate_new_dhcp_options_method_raises_exception(self):
vpc = self._create_vpc() with patch('moto.ec2.models.DHCPOptionsSetBackend.associate_dhcp_options', side_effect=BotoServerError(400, 'Mocked error')): r = boto_vpc.associate_new_dhcp_options_to_vpc(vpc.id, **dhcp_options_parameters) self.assertTrue(('error' in r))
'Tests creation/association of dhcp options to non-existent vpc'
@mock_ec2 def test_that_when_creating_dhcp_options_set_to_a_non_existent_vpc_the_dhcp_options_the_associate_new_dhcp_options_method_returns_false(self):
r = boto_vpc.create_dhcp_options(vpc_name='fake', **dhcp_options_parameters) self.assertTrue(('error' in r))
'Tests existence of dhcp options successfully'
@mock_ec2 def test_that_when_dhcp_options_exists_the_dhcp_options_exists_method_returns_true(self):
dhcp_options = self._create_dhcp_options() dhcp_options_exists_result = boto_vpc.dhcp_options_exists(dhcp_options.id, **conn_parameters) self.assertTrue(dhcp_options_exists_result['exists'])
'Tests existence of dhcp options failure'
@mock_ec2 def test_that_when_dhcp_options_do_not_exist_the_dhcp_options_exists_method_returns_false(self):
r = boto_vpc.dhcp_options_exists('fake', **conn_parameters) self.assertFalse(r['exists'])
'Tests checking dhcp option existence with no filters'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_that_when_checking_if_dhcp_options_exists_but_providing_no_filters_the_dhcp_options_exists_method_raises_a_salt_invocation_error(self):
with self.assertRaisesRegex(SaltInvocationError, 'At least one of the following must be provided: id, name, or tags.'): boto_vpc.dhcp_options_exists(**conn_parameters)
'Tests creation of network acl with existing vpc'
@mock_ec2 def test_that_when_creating_network_acl_for_an_existing_vpc_the_create_network_acl_method_returns_true(self):
vpc = self._create_vpc() network_acl_creation_result = boto_vpc.create_network_acl(vpc.id, **conn_parameters) self.assertTrue(network_acl_creation_result)
'Tests creation of network acl via name with an existing vpc'
@mock_ec2 def test_that_when_creating_network_acl_for_an_existing_vpc_and_specifying_a_name_the_create_network_acl_method_returns_true(self):
vpc = self._create_vpc() network_acl_creation_result = boto_vpc.create_network_acl(vpc.id, network_acl_name='test', **conn_parameters) self.assertTrue(network_acl_creation_result)
'Tests creation of network acl via tags with an existing vpc'
@mock_ec2 def test_that_when_creating_network_acl_for_an_existing_vpc_and_specifying_tags_the_create_network_acl_method_returns_true(self):
vpc = self._create_vpc() network_acl_creation_result = boto_vpc.create_network_acl(vpc.id, tags={'test': 'testvalue'}, **conn_parameters) self.assertTrue(network_acl_creation_result)
'Tests creation of network acl with a non-existent vpc'
@mock_ec2 def test_that_when_creating_network_acl_for_a_non_existent_vpc_the_create_network_acl_method_returns_an_error(self):
network_acl_creation_result = boto_vpc.create_network_acl('fake', **conn_parameters) self.assertTrue(('error' in network_acl_creation_result))
'Tests creation of network acl failure'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_network_acl_fails_the_create_network_acl_method_returns_false(self):
vpc = self._create_vpc() with patch('moto.ec2.models.NetworkACLBackend.create_network_acl', side_effect=BotoServerError(400, 'Mocked error')): network_acl_creation_result = boto_vpc.create_network_acl(vpc.id, **conn_parameters) self.assertFalse(network_acl_creation_result)
'Tests deletion of existing network acl successfully'
@mock_ec2 def test_that_when_deleting_an_existing_network_acl_the_delete_network_acl_method_returns_true(self):
vpc = self._create_vpc() network_acl = self._create_network_acl(vpc.id) network_acl_deletion_result = boto_vpc.delete_network_acl(network_acl.id, **conn_parameters) self.assertTrue(network_acl_deletion_result)
'Tests deleting a non-existent network acl'
@mock_ec2 def test_that_when_deleting_a_non_existent_network_acl_the_delete_network_acl_method_returns_an_error(self):
network_acl_deletion_result = boto_vpc.delete_network_acl('fake', **conn_parameters) self.assertTrue(('error' in network_acl_deletion_result))
'Tests existence of network acl'
@mock_ec2 def test_that_when_a_network_acl_exists_the_network_acl_exists_method_returns_true(self):
vpc = self._create_vpc() network_acl = self._create_network_acl(vpc.id) network_acl_deletion_result = boto_vpc.network_acl_exists(network_acl.id, **conn_parameters) self.assertTrue(network_acl_deletion_result)
'Tests checking network acl does not exist'
@mock_ec2 def test_that_when_a_network_acl_does_not_exist_the_network_acl_exists_method_returns_false(self):
network_acl_deletion_result = boto_vpc.network_acl_exists('fake', **conn_parameters) self.assertFalse(network_acl_deletion_result['exists'])
'Tests checking existence of network acl with no filters'
@mock_ec2 @skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493') def test_that_when_checking_if_network_acl_exists_but_providing_no_filters_the_network_acl_exists_method_raises_a_salt_invocation_error(self):
with self.assertRaisesRegex(SaltInvocationError, 'At least one of the following must be provided: id, name, or tags.'): boto_vpc.dhcp_options_exists(**conn_parameters)
'Tests creating network acl successfully'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_a_network_acl_entry_successfully_the_create_network_acl_entry_method_returns_true(self):
vpc = self._create_vpc() network_acl = self._create_network_acl(vpc.id) network_acl_entry_creation_result = boto_vpc.create_network_acl_entry(network_acl.id, *network_acl_entry_parameters, **conn_parameters) self.assertTrue(network_acl_entry_creation_result)
'Tests creating network acl entry for non-existent network acl'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_a_network_acl_entry_for_a_non_existent_network_acl_the_create_network_acl_entry_method_returns_false(self):
network_acl_entry_creation_result = boto_vpc.create_network_acl_entry(*network_acl_entry_parameters, **conn_parameters) self.assertFalse(network_acl_entry_creation_result)
'Tests replacing network acl entry successfully'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_replacing_a_network_acl_entry_successfully_the_replace_network_acl_entry_method_returns_true(self):
vpc = self._create_vpc() network_acl = self._create_network_acl(vpc.id) self._create_network_acl_entry(network_acl.id, *network_acl_entry_parameters) network_acl_entry_creation_result = boto_vpc.replace_network_acl_entry(network_acl.id, *network_acl_entry_parameters, **conn_parameters) self.assertTrue(network_acl_entry_creation_result)
'Tests replacing a network acl entry for a non-existent network acl'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_replacing_a_network_acl_entry_for_a_non_existent_network_acl_the_replace_network_acl_entry_method_returns_false(self):
network_acl_entry_creation_result = boto_vpc.create_network_acl_entry(*network_acl_entry_parameters, **conn_parameters) self.assertFalse(network_acl_entry_creation_result)
'Tests deleting existing network acl entry successfully'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_deleting_an_existing_network_acl_entry_the_delete_network_acl_entry_method_returns_true(self):
vpc = self._create_vpc() network_acl = self._create_network_acl(vpc.id) network_acl_entry = self._create_network_acl_entry(network_acl.id, *network_acl_entry_parameters) network_acl_entry_deletion_result = boto_vpc.delete_network_acl_entry(network_acl_entry.id, 100, **conn_parameters) self.assertTrue(network_acl_entry_deletion_result)
'Tests deleting a non-existent network acl entry'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_deleting_a_non_existent_network_acl_entry_the_delete_network_acl_entry_method_returns_false(self):
network_acl_entry_deletion_result = boto_vpc.delete_network_acl_entry('fake', 100, **conn_parameters) self.assertFalse(network_acl_entry_deletion_result)
'Tests association of existing network acl to existing subnet successfully'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_associating_an_existing_network_acl_to_an_existing_subnet_the_associate_network_acl_method_returns_true(self):
vpc = self._create_vpc() network_acl = self._create_network_acl(vpc.id) subnet = self._create_subnet(vpc.id) network_acl_association_result = boto_vpc.associate_network_acl_to_subnet(network_acl.id, subnet.id, **conn_parameters) self.assertTrue(network_acl_association_result)
'Tests associating a non-existent network acl to existing subnet failure'
@mock_ec2 def test_that_when_associating_a_non_existent_network_acl_to_an_existing_subnet_the_associate_network_acl_method_returns_an_error(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) network_acl_association_result = boto_vpc.associate_network_acl_to_subnet('fake', subnet.id, **conn_parameters) self.assertTrue(('error' in network_acl_association_result))
'Tests associating an existing network acl to a non-existent subnet'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_associating_an_existing_network_acl_to_a_non_existent_subnet_the_associate_network_acl_method_returns_false(self):
vpc = self._create_vpc() network_acl = self._create_network_acl(vpc.id) network_acl_association_result = boto_vpc.associate_network_acl_to_subnet(network_acl.id, 'fake', **conn_parameters) self.assertFalse(network_acl_association_result)
'Tests creating/associating a network acl to a subnet to a new network'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_and_associating_a_network_acl_to_a_subnet_succeeds_the_associate_new_network_acl_to_subnet_method_returns_true(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) network_acl_creation_and_association_result = boto_vpc.associate_new_network_acl_to_subnet(vpc.id, subnet.id, **conn_parameters) self.assertTrue(network_acl_creation_and_association_result)
'Tests creation/association of a network acl to subnet via name successfully'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_and_associating_a_network_acl_to_a_subnet_and_specifying_a_name_succeeds_the_associate_new_network_acl_to_subnet_method_returns_true(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) network_acl_creation_and_association_result = boto_vpc.associate_new_network_acl_to_subnet(vpc.id, subnet.id, network_acl_name='test', **conn_parameters) self.assertTrue(network_acl_creation_and_association_result)
'Tests creating/association of a network acl to a subnet via tag successfully'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_and_associating_a_network_acl_to_a_subnet_and_specifying_tags_succeeds_the_associate_new_network_acl_to_subnet_method_returns_true(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) network_acl_creation_and_association_result = boto_vpc.associate_new_network_acl_to_subnet(vpc.id, subnet.id, tags={'test': 'testvalue'}, **conn_parameters) self.assertTrue(network_acl_creation_and_association_result)
'Tests creation/association of a network acl to a non-existent vpc'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_and_associating_a_network_acl_to_a_non_existent_subnet_the_associate_new_network_acl_to_subnet_method_returns_false(self):
vpc = self._create_vpc() network_acl_creation_and_association_result = boto_vpc.associate_new_network_acl_to_subnet(vpc.id, 'fake', **conn_parameters) self.assertFalse(network_acl_creation_and_association_result)
'Tests creation/association of network acl to a non-existent subnet'
@mock_ec2 def test_that_when_creating_a_network_acl_to_a_non_existent_vpc_the_associate_new_network_acl_to_subnet_method_returns_an_error(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) network_acl_creation_result = boto_vpc.create_network_acl(vpc_name='fake', subnet_id=subnet.id, **conn_parameters) self.assertTrue(('error' in network_acl_creation_result))
'Tests disassociation of network acl success'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_disassociating_network_acl_succeeds_the_disassociate_network_acl_method_should_return_true(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) dhcp_disassociate_result = boto_vpc.disassociate_network_acl(subnet.id, vpc_id=vpc.id, **conn_parameters) self.assertTrue(dhcp_disassociate_result)
'Tests disassociation of network acl from non-existent vpc'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_disassociating_network_acl_for_a_non_existent_vpc_the_disassociate_network_acl_method_should_return_false(self):
vpc = self._create_vpc() subnet = self._create_subnet(vpc.id) dhcp_disassociate_result = boto_vpc.disassociate_network_acl(subnet.id, vpc_id='fake', **conn_parameters) self.assertFalse(dhcp_disassociate_result)
'Tests disassociation of network acl from non-existent subnet'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_disassociating_network_acl_for_a_non_existent_subnet_the_disassociate_network_acl_method_should_return_false(self):
vpc = self._create_vpc() dhcp_disassociate_result = boto_vpc.disassociate_network_acl('fake', vpc_id=vpc.id, **conn_parameters) self.assertFalse(dhcp_disassociate_result)
'Tests creating route table successfully'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_a_route_table_succeeds_the_create_route_table_method_returns_true(self):
vpc = self._create_vpc() route_table_creation_result = boto_vpc.create_route_table(vpc.id, **conn_parameters) self.assertTrue(route_table_creation_result)
'Tests creating route table on a non-existent vpc'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_creating_a_route_table_on_a_non_existent_vpc_the_create_route_table_method_returns_false(self):
route_table_creation_result = boto_vpc.create_route_table('fake', **conn_parameters) self.assertTrue(route_table_creation_result)
'Tests deleting route table successfully'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_deleting_a_route_table_succeeds_the_delete_route_table_method_returns_true(self):
vpc = self._create_vpc() route_table = self._create_route_table(vpc.id) route_table_deletion_result = boto_vpc.delete_route_table(route_table.id, **conn_parameters) self.assertTrue(route_table_deletion_result)
'Tests deleting non-existent route table'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_deleting_a_non_existent_route_table_the_delete_route_table_method_returns_false(self):
route_table_deletion_result = boto_vpc.delete_route_table('fake', **conn_parameters) self.assertFalse(route_table_deletion_result)
'Tests existence of route table success'
@mock_ec2 @skipIf(True, 'Moto has not implemented this feature. Skipping for now.') def test_that_when_route_table_exists_the_route_table_exists_method_returns_true(self):
vpc = self._create_vpc() route_table = self._create_route_table(vpc.id) route_table_existence_result = boto_vpc.route_table_exists(route_table.id, **conn_parameters) self.assertTrue(route_table_existence_result)