Added unit tests that verify that dhcp options creation and association reports success/failure correctly.

This commit is contained in:
Omer Katz 2014-09-29 13:05:37 +03:00
parent 0bae036a21
commit b5aaa2b3e8

View File

@ -53,6 +53,9 @@ access_key = 'GKTADJGHEIQSXMKKRBJ08H'
secret_key = 'askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs' secret_key = 'askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs'
conn_parameters = {'region': region, 'key': access_key, 'keyid': secret_key, 'profile': {}} conn_parameters = {'region': region, 'key': access_key, 'keyid': secret_key, 'profile': {}}
cidr_block = '10.0.0.0/24' cidr_block = '10.0.0.0/24'
dhcp_options = {'domain_name': 'example.com', 'domain_name_servers': ['1.2.3.4'], 'ntp_servers': ['5.6.7.8'],
'netbios_name_servers': ['10.0.0.1'], 'netbios_node_type': 2}
dhcp_options.update(conn_parameters)
def _has_required_boto(): def _has_required_boto():
@ -275,37 +278,23 @@ class BotoVpcTestCase(TestCase):
@mock_ec2 @mock_ec2
def test_when_creating_dhcp_options_succeeds_the_create_dhcp_options_method_returns_true(self): def test_when_creating_dhcp_options_succeeds_the_create_dhcp_options_method_returns_true(self):
dhcp_options_creation_result = boto_vpc.create_dhcp_options(domain_name='example.com', dhcp_options_creation_result = boto_vpc.create_dhcp_options(**dhcp_options)
domain_name_servers=['1.2.3.4'],
ntp_servers=['5.6.7.8'],
netbios_name_servers=['10.0.0.1'],
netbios_node_type=2, **conn_parameters)
self.assertTrue(dhcp_options_creation_result) self.assertTrue(dhcp_options_creation_result)
@mock_ec2 @mock_ec2
def test_when_creating_dhcp_options_and_specifying_a_name_succeeds_the_create_dhcp_options_method_returns_true( def test_when_creating_dhcp_options_and_specifying_a_name_succeeds_the_create_dhcp_options_method_returns_true(
self): self):
dhcp_options_creation_result = boto_vpc.create_dhcp_options(domain_name='example.com', dhcp_options_creation_result = boto_vpc.create_dhcp_options(dhcp_options_name='test',
domain_name_servers=['1.2.3.4'], **dhcp_options)
ntp_servers=['5.6.7.8'],
netbios_name_servers=['10.0.0.1'],
netbios_node_type=2,
dhcp_options_name='test',
**conn_parameters)
self.assertTrue(dhcp_options_creation_result) self.assertTrue(dhcp_options_creation_result)
@mock_ec2 @mock_ec2
def test_when_creating_dhcp_options_and_specifying_tags_succeeds_the_create_dhcp_options_method_returns_true( def test_when_creating_dhcp_options_and_specifying_tags_succeeds_the_create_dhcp_options_method_returns_true(
self): self):
dhcp_options_creation_result = boto_vpc.create_dhcp_options(domain_name='example.com', dhcp_options_creation_result = boto_vpc.create_dhcp_options(tags={'test': 'testvalue'},
domain_name_servers=['1.2.3.4'], **dhcp_options)
ntp_servers=['5.6.7.8'],
netbios_name_servers=['10.0.0.1'],
netbios_node_type=2,
tags={'test': 'testvalue'},
**conn_parameters)
self.assertTrue(dhcp_options_creation_result) self.assertTrue(dhcp_options_creation_result)
@ -313,11 +302,7 @@ class BotoVpcTestCase(TestCase):
def test_when_creating_dhcp_options_fails_the_create_dhcp_options_method_returns_false(self): def test_when_creating_dhcp_options_fails_the_create_dhcp_options_method_returns_false(self):
with patch('moto.ec2.models.DHCPOptionsSetBackend.create_dhcp_options', with patch('moto.ec2.models.DHCPOptionsSetBackend.create_dhcp_options',
side_effect=BotoServerError(400, 'Mocked error')): side_effect=BotoServerError(400, 'Mocked error')):
dhcp_options_creation_result = boto_vpc.create_dhcp_options(domain_name='example.com', dhcp_options_creation_result = boto_vpc.create_dhcp_options(**dhcp_options)
domain_name_servers=['1.2.3.4'],
ntp_servers=['5.6.7.8'],
netbios_name_servers=['10.0.0.1'],
netbios_node_type=2, **conn_parameters)
self.assertFalse(dhcp_options_creation_result) self.assertFalse(dhcp_options_creation_result)
@ -351,6 +336,44 @@ class BotoVpcTestCase(TestCase):
self.assertFalse(dhcp_options_association_result) self.assertFalse(dhcp_options_association_result)
@mock_ec2
def test_when_creating_and_associating_dhcp_options_set_to_an_existing_vpc_succeeds_the_associate_new_dhcp_options_method_returns_true(
self):
vpc = self._create_vpc()
dhcp_creation_and_association_result = boto_vpc.associate_new_dhcp_options_to_vpc(vpc.id, **dhcp_options)
self.assertTrue(dhcp_creation_and_association_result)
@mock_ec2
def test_when_creating_and_associating_dhcp_options_set_to_an_existing_vpc_fails_creating_the_dhcp_options_the_associate_new_dhcp_options_method_returns_false(
self):
vpc = self._create_vpc()
with patch('moto.ec2.models.DHCPOptionsSetBackend.create_dhcp_options',
side_effect=BotoServerError(400, 'Mocked error')):
dhcp_creation_and_association_result = boto_vpc.associate_new_dhcp_options_to_vpc(vpc.id, **dhcp_options)
self.assertFalse(dhcp_creation_and_association_result)
@mock_ec2
def test_when_creating_and_associating_dhcp_options_set_to_an_existing_vpc_fails_associating_the_dhcp_options_the_associate_new_dhcp_options_method_returns_false(
self):
vpc = self._create_vpc()
with patch('moto.ec2.models.DHCPOptionsSetBackend.associate_dhcp_options',
side_effect=BotoServerError(400, 'Mocked error')):
dhcp_creation_and_association_result = boto_vpc.associate_new_dhcp_options_to_vpc(vpc.id, **dhcp_options)
self.assertFalse(dhcp_creation_and_association_result)
@mock_ec2
def test_when_creating_and_associating_dhcp_options_set_to_a_non_existent_vpc_the_dhcp_options_the_associate_new_dhcp_options_method_returns_false(
self):
dhcp_creation_and_association_result = boto_vpc.associate_new_dhcp_options_to_vpc('fake', **dhcp_options)
self.assertFalse(dhcp_creation_and_association_result)
@mock_ec2 @mock_ec2
def test_that_when_dhcp_options_exists_the_dhcp_options_exists_method_returns_true(self): def test_that_when_dhcp_options_exists_the_dhcp_options_exists_method_returns_true(self):
dhcp_options = self._create_dhcp_options() dhcp_options = self._create_dhcp_options()
@ -366,8 +389,6 @@ class BotoVpcTestCase(TestCase):
self.assertFalse(dhcp_options_exists_result) self.assertFalse(dhcp_options_exists_result)
if __name__ == '__main__': if __name__ == '__main__':
from integration import run_tests from integration import run_tests