Ejemplo n.º 1
0
class TestPackageCommand(unittest.TestCase):
    def setUp(self):
        self.session = mock.Mock()
        self.session.get_scoped_config.return_value = {}
        self.parsed_args = FakeArgs(template_file='./foo',
                                    s3_bucket="s3bucket",
                                    s3_prefix="s3prefix",
                                    kms_key_id="kmskeyid",
                                    output_template_file="./oputput",
                                    force_upload=False)
        self.parsed_globals = FakeArgs(region="us-east-1",
                                       endpoint_url=None,
                                       verify_ssl=None)
        self.package_command = PackageCommand(self.session)

    @patch("awscli.customizations.cloudformation.package.yaml_dump")
    def test_main(self, mock_yaml_dump):
        exported_template = {}
        exported_template_str = "hello"

        self.package_command.write_output = Mock()
        self.package_command._export = Mock()
        mock_yaml_dump.return_value = exported_template_str

        # Create a temporary file and make this my template
        with tempfile.NamedTemporaryFile() as handle:
            filename = handle.name
            self.parsed_args.template_file = filename

            rc = self.package_command._run_main(self.parsed_args,
                                                self.parsed_globals)
            self.assertEquals(rc, 0)

            self.package_command._export.assert_called_once_with(filename)
            self.package_command.write_output.assert_called_once_with(
                self.parsed_args.output_template_file, mock.ANY)

    def test_main_error(self):

        self.package_command._export = Mock()
        self.package_command._export.side_effect = RuntimeError()

        # Create a temporary file and make this my template
        with tempfile.NamedTemporaryFile() as handle:
            filename = handle.name
            self.parsed_args.template_file = filename

            with self.assertRaises(RuntimeError):
                self.package_command._run_main(self.parsed_args,
                                               self.parsed_globals)

    @patch("awscli.customizations.cloudformation.package.sys.stdout")
    def test_write_output_to_stdout(self, stdoutmock):
        data = u"some data"
        filename = None

        self.package_command.write_output(filename, data)
        stdoutmock.write.assert_called_once_with(data)
Ejemplo n.º 2
0
class TestPackageCommand(unittest.TestCase):

    def setUp(self):
        self.session = mock.Mock()
        self.session.get_scoped_config.return_value = {}
        self.parsed_args = FakeArgs(template_file='./foo',
                                    s3_bucket="s3bucket",
                                    s3_prefix="s3prefix",
                                    kms_key_id="kmskeyid",
                                    output_template_file="./oputput",
                                    force_upload=False)
        self.parsed_globals = FakeArgs(region="us-east-1", endpoint_url=None,
                                       verify_ssl=None)
        self.package_command = PackageCommand(self.session)


    @patch("awscli.customizations.cloudformation.package.yaml_dump")
    def test_main(self, mock_yaml_dump):
        exported_template = {}
        exported_template_str = "hello"

        self.package_command.write_output = Mock()
        self.package_command._export = Mock()
        mock_yaml_dump.return_value = exported_template_str

        # Create a temporary file and make this my template
        with tempfile.NamedTemporaryFile() as handle:
            filename = handle.name
            self.parsed_args.template_file = filename

            rc = self.package_command._run_main(self.parsed_args, self.parsed_globals)
            self.assertEquals(rc, 0)

            self.package_command._export.assert_called_once_with(filename)
            self.package_command.write_output.assert_called_once_with(
                    self.parsed_args.output_template_file, mock.ANY)

    def test_main_error(self):

        self.package_command._export = Mock()
        self.package_command._export.side_effect = RuntimeError()

        # Create a temporary file and make this my template
        with tempfile.NamedTemporaryFile() as handle:
            filename = handle.name
            self.parsed_args.template_file = filename

            with self.assertRaises(RuntimeError):
                self.package_command._run_main(self.parsed_args, self.parsed_globals)


    @patch("awscli.customizations.cloudformation.package.sys.stdout")
    def test_write_output_to_stdout(self, stdoutmock):
        data = u"some data"
        filename = None

        self.package_command.write_output(filename, data)
        stdoutmock.write.assert_called_once_with(data)
Ejemplo n.º 3
0
 def setUp(self):
     self.session = mock.Mock()
     self.session.get_scoped_config.return_value = {}
     self.parsed_args = FakeArgs(template_file='./foo',
                                 s3_bucket="s3bucket",
                                 s3_prefix="s3prefix",
                                 kms_key_id="kmskeyid",
                                 output_template_file="./oputput",
                                 force_upload=False)
     self.parsed_globals = FakeArgs(region="us-east-1",
                                    endpoint_url=None,
                                    verify_ssl=None)
     self.package_command = PackageCommand(self.session)
def inject_commands(command_table, session, **kwargs):
    """
    Called when the CloudFormation command table is being built. Used to
    inject new high level commands into the command list. These high level
    commands must not collide with existing low-level API call names.
    """
    command_table['package'] = PackageCommand(session)
    command_table['deploy'] = DeployCommand(session)
Ejemplo n.º 5
0
 def setUp(self):
     self.session = mock.Mock()
     self.session.get_scoped_config.return_value = {}
     self.parsed_args = FakeArgs(template_file='./foo',
                                 s3_bucket="s3bucket",
                                 s3_prefix="s3prefix",
                                 kms_key_id="kmskeyid",
                                 output_template_file="./oputput",
                                 force_upload=False)
     self.parsed_globals = FakeArgs(region="us-east-1", endpoint_url=None,
                                    verify_ssl=None)
     self.package_command = PackageCommand(self.session)