Пример #1
0
 def setUp(self):
     super(TestCodeDeployPush, self).setUp()
     self.codedeploypush = CodeDeployPush(self.session)
     self.codedeploypush.s3 = Mock()
     self.codedeploypush.s3.upload_to_s3.return_value = self.upload_response
     self.codedeploypush.codedeploy = Mock()
Пример #2
0
 def setUp(self):
     super(TestCodeDeployPush, self).setUp()
     self.codedeploypush = CodeDeployPush(self.session)
     self.codedeploypush.s3 = Mock()
     self.codedeploypush.s3.upload_to_s3.return_value = self.upload_response
     self.codedeploypush.codedeploy = Mock()
Пример #3
0
class TestCodeDeployPush(CodeDeployTestCase):
    def setUp(self):
        super(TestCodeDeployPush, self).setUp()
        self.codedeploypush = CodeDeployPush(self.session)
        self.codedeploypush.s3 = Mock()
        self.codedeploypush.s3.upload_to_s3.return_value = self.upload_response
        self.codedeploypush.codedeploy = Mock()

    def test_flatten_args_throws_on_invalid_s3_url(self):
        self.args.s3_location = 's3:/foo/bar/baz'
        with self.assertRaises(RuntimeError) as error:
            self.codedeploypush._flatten_args(self.args)

    def test_flatten_args_throws_on_ignore_and_no_ignore_hidden_files(self):
        self.args.ignore_hidden_files = True
        self.args.no_ignore_hidden_files = True
        with self.assertRaises(RuntimeError) as error:
            self.codedeploypush._flatten_args(self.args)

    def test_flatten_args_default_description(self):
        self.args.description = None
        self.codedeploypush._flatten_args(self.args)
        self.assertRegexpMatches(self.args.description,
                                 'Uploaded by AWS CLI .* UTC')

    def test_call_throws_on_upload_to_s3_error(self):
        self.args.bucket = self.bucket
        self.args.key = self.key
        self.codedeploypush._compress = Mock(return_value=self.bundle_mock)
        self.codedeploypush.s3.upload_to_s3.side_effect = RuntimeError('error')
        with self.assertRaises(RuntimeError) as error:
            self.codedeploypush._call(self.args, self.globals)

    @patch('sys.stdout', new_callable=StringIO)
    def test_call_output_message(self, stdout_mock):
        self.args.bucket = self.bucket
        self.args.key = self.key
        self.codedeploypush._compress = Mock(return_value=self.bundle_mock)
        self.codedeploypush._call(self.args, self.globals)
        output = stdout_mock.getvalue().strip()
        expected_revision_output = (
            '--s3-location bucket={0},key={1},'
            'bundleType=zip,eTag={2},version={3}'.format(
                self.bucket, self.key, self.eTag, self.version_id))
        expected_output = ('To deploy with this revision, run:\n'
                           'aws deploy create-deployment '
                           '--application-name {0} {1} '
                           '--deployment-group-name <deployment-group-name> '
                           '--deployment-config-name <deployment-config-name> '
                           '--description <description>'.format(
                               self.application_name,
                               expected_revision_output))
        self.assertEquals(expected_output, output)

    @patch('zipfile.ZipFile')
    @patch('tempfile.TemporaryFile')
    @patch('os.path')
    @patch('os.walk')
    def test_compress_throws_when_no_appspec(self, walk, path, tf, zf):
        walk.return_value = [(self.source, [], ['noappspec.yml'])]
        noappsec_path = self.source + '/noappspec.yml'
        path.join.return_value = noappsec_path
        path.sep = '/'
        path.abspath.side_effect = [self.source, noappsec_path]
        tf.return_value = self.bundle_mock
        zf.return_value = self.zipfile_mock
        with self.assertRaises(RuntimeError) as error:
            with self.codedeploypush._compress(
                    self.args.source, self.args.ignore_hidden_files) as bundle:
                pass

    @patch('zipfile.ZipFile')
    @patch('tempfile.TemporaryFile')
    @patch('os.path')
    @patch('os.walk')
    def test_compress_writes_to_zip_file(self, walk, path, tf, zf):
        walk.return_value = [(self.source, [], [self.appspec])]
        path.join.return_value = self.appspec_path
        path.sep = '/'
        path.abspath.side_effect = [self.source, self.appspec_path]
        tf.return_value = self.bundle_mock
        zf.return_value = self.zipfile_mock
        with self.codedeploypush._compress(
                self.args.source, self.args.ignore_hidden_files) as bundle:
            zf().write.assert_called_with('/tmp/appspec.yml', self.appspec)
Пример #4
0
class TestCodeDeployPush(CodeDeployTestCase):
    def setUp(self):
        super(TestCodeDeployPush, self).setUp()
        self.codedeploypush = CodeDeployPush(self.session)
        self.codedeploypush.s3 = Mock()
        self.codedeploypush.s3.upload_to_s3.return_value = self.upload_response
        self.codedeploypush.codedeploy = Mock()

    def test_flatten_args_throws_on_invalid_s3_url(self):
        self.args.s3_location = 's3:/foo/bar/baz'
        with self.assertRaises(RuntimeError) as error:
            self.codedeploypush._flatten_args(self.args)

    def test_flatten_args_throws_on_ignore_and_no_ignore_hidden_files(self):
        self.args.ignore_hidden_files = True
        self.args.no_ignore_hidden_files = True
        with self.assertRaises(RuntimeError) as error:
            self.codedeploypush._flatten_args(self.args)

    def test_flatten_args_default_description(self):
        self.args.description = None
        self.codedeploypush._flatten_args(self.args)
        self.assertRegexpMatches(
            self.args.description,
            'Uploaded by AWS CLI .* UTC'
        )

    def test_call_throws_on_upload_to_s3_error(self):
        self.args.bucket = self.bucket
        self.args.key = self.key
        self.codedeploypush._compress = Mock(return_value=self.bundle_mock)
        self.codedeploypush.s3.upload_to_s3.side_effect = RuntimeError('error')
        with self.assertRaises(RuntimeError) as error:
            self.codedeploypush._call(self.args, self.globals)

    @patch('sys.stdout', new_callable=StringIO)
    def test_call_output_message(self, stdout_mock):
        self.args.bucket = self.bucket
        self.args.key = self.key
        self.codedeploypush._compress = Mock(return_value=self.bundle_mock)
        self.codedeploypush._call(self.args, self.globals)
        output = stdout_mock.getvalue().strip()
        expected_revision_output = (
            '--s3-location bucket={0},key={1},'
            'bundleType=zip,eTag={2},version={3}'.format(
                self.bucket,
                self.key,
                self.eTag,
                self.version_id)
        )
        expected_output = (
            'To deploy with this revision, run:\n'
            'aws deploy create-deployment '
            '--application-name {0} {1} '
            '--deployment-group-name <deployment-group-name> '
            '--deployment-config-name <deployment-config-name> '
            '--description <description>'.format(
                self.application_name,
                expected_revision_output
            )
        )
        self.assertEquals(expected_output, output)

    @patch('zipfile.ZipFile')
    @patch('tempfile.TemporaryFile')
    @patch('os.path')
    @patch('os.walk')
    def test_compress_throws_when_no_appspec(self, walk, path, tf, zf):
        walk.return_value = [(self.source, [], ['noappspec.yml'])]
        noappsec_path = self.source + '/noappspec.yml'
        path.join.return_value = noappsec_path
        path.sep = '/'
        path.abspath.side_effect = [self.source, noappsec_path]
        tf.return_value = self.bundle_mock
        zf.return_value = self.zipfile_mock
        with self.assertRaises(RuntimeError) as error:
            with self.codedeploypush._compress(
                    self.args.source,
                    self.args.ignore_hidden_files
            ) as bundle:
                pass

    @patch('zipfile.ZipFile')
    @patch('tempfile.TemporaryFile')
    @patch('os.path')
    @patch('os.walk')
    def test_compress_writes_to_zip_file(self, walk, path, tf, zf):
        walk.return_value = [(self.source, [], [self.appspec])]
        path.join.return_value = self.appspec_path
        path.sep = '/'
        path.abspath.side_effect = [self.source, self.appspec_path]
        tf.return_value = self.bundle_mock
        zf.return_value = self.zipfile_mock
        with self.codedeploypush._compress(
                self.args.source,
                self.args.ignore_hidden_files
        ) as bundle:
            zf().write.assert_called_with(
                '/tmp/appspec.yml',
                self.appspec
            )