コード例 #1
0
    def test_handler_on_create_linux(self):
        result = {}

        def send_mock(*args):
            result["args"] = args

        with mock.patch("collect_info.cfnresponse.send",
                        side_effect=send_mock):
            event = {
                "RequestType": "Create",
                "ResourceProperties": {
                    "AmiId": LINUX_AMI_ID,
                    "VpcId": "vpc-id-12345"
                }
            }
            context = {}
            collect_info.handler(event, context)

            print result["args"]
            (event, context, responseStatus, responseData,
             physicalResourceId) = result["args"]
            self.assertEqual(responseStatus, "SUCCESS")
            self.assertDictContainsSubset(
                {
                    "Platform": "linux",
                    "VpcId": "vpc-id-12345"
                }, responseData)
            self.assertIsNone(physicalResourceId)
コード例 #2
0
    def test_handler_on_create_windows(self):
        result = {}

        def send_mock(*args):
            result["args"] = args

        default_vpc = util.find_default_vpc(ec2_client)

        with mock.patch("collect_info.cfnresponse.send",
                        side_effect=send_mock):
            event = {
                "RequestType": "Create",
                "ResourceProperties": {
                    "AmiId": WINDOWS_AMI_ID,
                    "VpcId": "Default"
                }
            }
            context = {}
            collect_info.handler(event, context)

            (event, context, responseStatus, responseData,
             physicalResourceId) = result["args"]
            self.assertEqual(responseStatus, "SUCCESS")
            self.assertDictContainsSubset(
                {
                    "Platform": "windows",
                    "VpcId": default_vpc["VpcId"]
                }, responseData)
            self.assertIsNone(physicalResourceId)
コード例 #3
0
    def test_handler_on_create_bad_ami(self):
        result = {}

        def send_mock(*args):
            result["args"] = args

        with mock.patch("collect_info.cfnresponse.send",
                        side_effect=send_mock):
            event = {
                "RequestType": "Create",
                "ResourceProperties": {
                    "AmiId": "ami-invalid123"
                }
            }
            context = {}
            collect_info.handler(event, context)

            (event, context, responseStatus, responseData,
             physicalResourceId) = result["args"]
            self.assertEqual(responseStatus, "FAILED")
            self.assertIsNone(physicalResourceId)
コード例 #4
0
    def test_handler_on_delete(self):
        result = {}

        def send_mock(*args):
            result["args"] = args

        with mock.patch("collect_info.cfnresponse.send",
                        side_effect=send_mock):
            event = {
                "RequestType": "Delete",
                "PhysicalResourceId": "testing_resource_id",
                "ResourceProperties": {
                    "AmiId": LINUX_AMI_ID
                }
            }
            context = {}
            collect_info.handler(event, context)

            (event, context, responseStatus, responseData,
             physicalResourceId) = result["args"]
            self.assertEqual(responseStatus, "SUCCESS")
            self.assertEqual(physicalResourceId, "testing_resource_id")
コード例 #5
0
    def test_handler_on_update_linux(self):
        result = {}

        def send_mock(*args):
            result["args"] = args

        with mock.patch("collect_info.cfnresponse.send",
                        side_effect=send_mock):
            event = {
                "RequestType": "Update",
                "PhysicalResourceId": "testing_resource_id",
                "ResourceProperties": {
                    "AmiId": LINUX_AMI_ID
                }
            }
            context = {}
            collect_info.handler(event, context)

            (event, context, responseStatus, responseData,
             physicalResourceId) = result["args"]
            self.assertEqual(responseStatus, "SUCCESS")
            self.assertDictContainsSubset({"Platform": "linux"}, responseData)
            self.assertEqual("testing_resource_id", physicalResourceId)