def test_create_dhcp_options(self):
        ctx = {
            'name': 'dhcp01',
            'domain_name': [
                'test01.us-west-2.aws'
            ],
            'domain_name_servers': [
                '10.0.10.2'
            ],
            'tags': {
                'description': 'DHCP options set for VPC vpc01'
            }
        }

        tags = [
            {
                'Key': 'Name',
                'Value': 'dhcp01'
            },
            {
                'Key': 'Description',
                'Value': 'DHCP options set for VPC vpc01'
            }
        ]

        dhcp_configurations = [
            {
                'Key': 'domain-name',
                'Values': [{'Value': 'test01.us-west-2.aws'}]
            },
            {
                'Key': 'domain-name-servers',
                'Values': [{'Value': '10.0.10.2'}]
            }
        ]

        filters = [{'Name': 'tag:Name', 'Values': ['dhcp01']}]

        def _add_wrapper(base_classes, **kwargs):
            base_classes.insert(0, ec2_dhcp.DhcpOptionsWrapper)

        with mock_ec2():
            event = 'creating-resource-class.ec2.DhcpOptions'
            session = Session(**self.credentials)
            session.events.register(event, _add_wrapper)
            ec2 = session.resource('ec2')

            # Create the DHCP options set
            h = ec2_dhcp.create_handler(ctx, self.credentials)
            h.create_resource()

            dhcp_options_sets = list(ec2.dhcp_options_sets.filter(Filters=filters))
            dhcp = dhcp_options_sets[0]

            self.assertEqual(len(dhcp_options_sets), 1)
            self.assertEqual(dhcp.name, 'dhcp01')
            self.assertCountEqual(dhcp.dhcp_configurations, dhcp_configurations)
            self.assertCountEqual(dhcp.tags, tags)
    def test_delete_dhcp_options_set(self):
        ctx = {
            'name': 'dhcp01',
            'domain_name': [
                'test01.us-west-2.aws'
            ],
            'domain_name_servers': [
                '10.0.10.2'
            ]
        }

        filters = [{'Name': 'tag:Name', 'Values': ['dhcp01']}]

        def _add_wrapper(base_classes, **kwargs):
            base_classes.insert(0, ec2_dhcp.DhcpOptionsWrapper)

        with mock_ec2():
            event = 'creating-resource-class.ec2.DhcpOptions'
            session = Session(**self.credentials)
            session.events.register(event, _add_wrapper)
            ec2 = session.resource('ec2')

            # Create the DHCP options set
            h = ec2_dhcp.create_handler(ctx, self.credentials)
            h.create_resource()

            dhcp_options_sets = list(ec2.dhcp_options_sets.filter(Filters=filters))

            self.assertEqual(len(dhcp_options_sets), 1)

            # We clear the resource cache to simulate a new
            # program execution with the 'delete' option
            base.BaseHandler._cache.clear()

            # Delete the DHCP options set
            h.delete_resource()

            dhcp_options_sets = list(ec2.dhcp_options_sets.filter(Filters=filters))

            self.assertEqual(len(dhcp_options_sets), 0)
    def test_update_dhcp_options(self):
        ctx1 = {
            'name': 'dhcp01',
            'domain_name': [
                'test01.us-west-2.aws'
            ],
            'domain_name_servers': [
                '10.0.10.2'
            ],
            'tags': {
                'description': 'DHCP options set for VPC vpc01',
                'stack': 'Test',
                'owner': 'Team A'

            }
        }

        ctx2 = {
            'name': 'dhcp01',
            'domain_name': [
                'test01.us-west-2.aws'
            ],
            'domain_name_servers': [
                '10.0.10.2'
            ],
            'tags': {
                'description': 'DHCP options set for VPC vpc01',
                'stack': 'Production'
            }
        }

        tags1 = [
            {
                'Key': 'Name',
                'Value': 'dhcp01'
            },
            {
                'Key': 'Description',
                'Value': 'DHCP options set for VPC vpc01'
            },
            {
                'Key': 'Stack',
                'Value': 'Test'
            },
            {
                'Key': 'Owner',
                'Value': 'Team A'
            }
        ]

        tags2 = [
            {
                'Key': 'Name',
                'Value': 'dhcp01'
            },
            {
                'Key': 'Description',
                'Value': 'DHCP options set for VPC vpc01'
            },
            {
                'Key': 'Stack',
                'Value': 'Production'
            }
        ]

        filters = [{'Name': 'tag:Name', 'Values': ['dhcp01']}]

        def _add_wrapper(base_classes, **kwargs):
            base_classes.insert(0, ec2_dhcp.DhcpOptionsWrapper)

        with mock_ec2():
            event = 'creating-resource-class.ec2.DhcpOptions'
            session = Session(**self.credentials)
            session.events.register(event, _add_wrapper)
            ec2 = session.resource('ec2')

            # Create the DHCP options set
            h = ec2_dhcp.create_handler(ctx1, self.credentials)
            h.create_resource()

            dhcp_options_sets = list(ec2.dhcp_options_sets.filter(Filters=filters))
            dhcp = dhcp_options_sets[0]
            dhcp_id = dhcp.id

            self.assertEqual(len(dhcp_options_sets), 1)
            self.assertCountEqual(dhcp.tags, tags1)

            # Update the DHCP options set
            h = ec2_dhcp.create_handler(ctx2, self.credentials)
            h.update_resource()

            dhcp_options_sets = list(ec2.dhcp_options_sets.filter(Filters=filters))
            dhcp = dhcp_options_sets[0]

            self.assertEqual(len(dhcp_options_sets), 1)
            self.assertEqual(dhcp.id, dhcp_id)
            self.assertCountEqual(dhcp.tags, tags2)