Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some unit tests for deploy #1000

Merged
merged 1 commit into from
Nov 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions awscli/customizations/codedeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
import os
import zipfile
import tempfile
import io
import contextlib
from datetime import datetime

import six

from awscli.argprocess import unpack_cli_arg
from awscli.arguments import CustomArgument
from awscli.arguments import create_argument_model_from_schema
Expand Down Expand Up @@ -269,7 +270,7 @@ def _multipart_upload_to_s3(self, parsed_args, bundle, size_remaining):
key=parsed_args.key,
uploadId=upload_id,
partNumber=part_num,
body=io.BytesIO(data)
body=six.BytesIO(data)
)
multipart_list.append({
'PartNumber': part_num,
Expand Down Expand Up @@ -477,11 +478,10 @@ def _call(self, parsed_args, parsed_globals):
parsed_args.version = upload_response['VersionId']
except Exception as e:
raise RuntimeError(
'Failed to upload \'{0}\' to \'{1}\': {2}'.format(
parsed_args.source,
parsed_args.s3_location,
e.message
)
'Failed to upload \'%s\' to \'%s\': %s' %
(parsed_args.source,
parsed_args.s3_location,
str(e))
)
self.codedeploy.register_revision(parsed_args)

Expand Down Expand Up @@ -515,7 +515,7 @@ def _call(self, parsed_args, parsed_globals):
def _compress(self, source, ignore_hidden_files=False):
source_path = os.path.abspath(source)
appspec_path = os.path.sep.join([source_path, 'appspec.yml'])
with tempfile.TemporaryFile() as tf:
with tempfile.TemporaryFile('w+b') as tf:
zf = zipfile.ZipFile(tf, 'w')
# Using 'try'/'finally' instead of 'with' statement since ZipFile
# does not have support context manager in Python 2.6.
Expand Down
10 changes: 4 additions & 6 deletions tests/unit/customizations/test_codedeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,7 @@ def setUp(self):
self.version_id = '12341234-1234-1234-1234-123412341234'
self.upload_id = 'upload_id'
self.region = 'us-east-1'
self.endpoint_url = 'https://codedeploy-{}.amazonaws.com'.format(
self.region
)
self.endpoint_url = 'https://codedeploy-%s.amazonaws.com' % self.region

self.args = argparse.Namespace()
self.args.application_name = self.application_name
Expand Down Expand Up @@ -534,7 +532,7 @@ def setUp(self):

self.bundle_mock = MagicMock()
self.bundle_mock.tell.return_value = (5 << 20)
self.bundle_mock.read.return_value = 'a' * (5 << 20)
self.bundle_mock.read.return_value = b'a' * (5 << 20)
self.bundle_mock.__enter__.return_value = self.bundle_mock
self.bundle_mock.__exit__.return_value = None

Expand Down Expand Up @@ -585,7 +583,7 @@ def test_upload_to_s3_with_multipart_upload(self):
self.args.bucket = self.bucket
self.args.key = self.key
self.bundle_mock.tell.return_value = (6 << 20)
self.bundle_mock.read.return_value = 'a' * (6 << 20)
self.bundle_mock.read.return_value = b'a' * (6 << 20)
response = self.s3client.upload_to_s3(self.args, self.bundle_mock)
self.assertDictEqual(self.upload_response, response)

Expand Down Expand Up @@ -613,7 +611,7 @@ def test_upload_to_s3_with_multipart_upload_aborted_on_error(self):
self.args.bucket = self.bucket
self.args.key = self.key
self.bundle_mock.tell.return_value = (6 << 20)
self.bundle_mock.read.return_value = 'a' * (6 << 20)
self.bundle_mock.read.return_value = b'a' * (6 << 20)
self.s3client.s3.UploadPart.side_effect = RuntimeError('error')

with self.assertRaises(RuntimeError) as error:
Expand Down