Example #1
0
 def _generate(self, fail_on_error=True):
     return_code = cli.generate()
     sys.stdout.seek(0)
     out = '\n'.join([line for line in sys.stdout.readlines()])
     if return_code != 0:
         if fail_on_error:
             self.fail(
                 'generate failed, stdout dump follows:\n{0}'.format(out))
     return out
Example #2
0
    def test_generate(self):
        # Make a pyplate that uses the options mapping
        pyplate_contents = dedent(u'''\
        cft = CloudFormationTemplate('This is a test')
        cft.parameters.update({
            'Exists': options['ThisKeyExists'],
            'DoesNotExist': options['ThisKeyDoesNotExist']
        })''')
        pyplate = NamedTemporaryFile()
        pyplate.write(pyplate_contents)
        pyplate.flush()

        # Now make an options mapping with only one of those keys in it
        # to simultaneously test options interpolation and
        # user-prompted input
        options_mapping_contents = dedent(u'''\
        {
            'ThisKeyExists': true
        }
        ''')
        options_mapping = NamedTemporaryFile()
        options_mapping.write(options_mapping_contents)
        options_mapping.flush()

        # The outfile which will receive the rendered json
        outfile = NamedTemporaryFile()

        # Populate sys.argv with something reasonable based on all the
        # tempfiles. On the command line this would look like
        # "cfn_py_generate pyplate outfile -o options_mapping"
        sys.argv = [
            'cfn_py_generate', pyplate.name, outfile.name, '-o',
            options_mapping.name
        ]
        # Prime stdin with the answer to our interactive question
        input = 'Test'
        sys.stdin.write('{0}\n'.format(input))
        sys.stdin.seek(0)

        # Run the command, catch it if it tries to exit the interpreter
        return_code = cli.generate()
        if return_code != 0:
            sys.stdout.seek(0)
            message = sys.stdout.read()
            self.fail(
                'generate failed, stdout dump follows:\n{0}'.format(message))

        # Load the output back into python for assertions
        output = json.load(outfile)

        # The Exists parameter should evaluate to bool True...
        # If so, then options_mapping interpolation works
        self.assertTrue(output['Parameters']['Exists'])

        # The DoesNotExist parameter should be what was injected to stdin
        # If so, then prompts to populate missing options_mapping entries work
        self.assertEqual(output['Parameters']['DoesNotExist'], input)
Example #3
0
    def test_generate(self):
        # Make a pyplate that uses the options mapping
        pyplate_contents = dedent(u'''\
        cft = CloudFormationTemplate('This is a test')
        cft.parameters.update({
            'Exists': options['ThisKeyExists'],
            'DoesNotExist': options['ThisKeyDoesNotExist']
        })''')
        pyplate = NamedTemporaryFile()
        pyplate.write(pyplate_contents)
        pyplate.flush()

        # Now make an options mapping with only one of those keys in it
        # to simultaneously test options interpolation and
        # user-prompted input
        options_mapping_contents = dedent(u'''\
        {
            'ThisKeyExists': true
        }
        ''')
        options_mapping = NamedTemporaryFile()
        options_mapping.write(options_mapping_contents)
        options_mapping.flush()

        # The outfile which will receive the rendered json
        outfile = NamedTemporaryFile()

        # Populate sys.argv with something reasonable based on all the
        # tempfiles. On the command line this would look like
        # "cfn_py_generate pyplate outfile -o options_mapping"
        sys.argv = ['cfn_py_generate', pyplate.name, outfile.name,
            '-o', options_mapping.name]
        # Prime stdin with the answer to our interactive question
        input = 'Test'
        sys.stdin.write('{0}\n'.format(input))
        sys.stdin.seek(0)

        # Run the command, catch it if it tries to exit the interpreter
        return_code = cli.generate()
        if return_code != 0:
            sys.stdout.seek(0)
            message = sys.stdout.read()
            self.fail('generate failed, stdout dump follows:\n{0}'.format(
                message)
            )

        # Load the output back into python for assertions
        output = json.load(outfile)

        # The Exists parameter should evaluate to bool True...
        # If so, then options_mapping interpolation works
        self.assertTrue(output['Parameters']['Exists'])

        # The DoesNotExist parameter should be what was injected to stdin
        # If so, then prompts to populate missing options_mapping entries work
        self.assertEqual(output['Parameters']['DoesNotExist'], input)
Example #4
0
 def _generate(self, fail_on_error=True):
     return_code = cli.generate()
     sys.stdout.seek(0)
     out = '\n'.join([line for line in sys.stdout.readlines()])
     if return_code != 0:
         if fail_on_error:
             self.fail('generate failed, stdout dump follows:\n{0}'.format(
                 out)
             )
     return out