Skip to content

Commit

Permalink
Renamed the recently added classes.
Browse files Browse the repository at this point in the history
Also moved the ``test_plugin.py`` tests out of
``us-east-1`` and into ``us-west-2``.
  • Loading branch information
kyleknap committed Aug 13, 2014
1 parent c931e54 commit 8e832a6
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 112 deletions.
4 changes: 2 additions & 2 deletions awscli/customizations/s3/filegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, directory, filename):
super(FileDecodingError, self).__init__(self.error_message)


class FileBase(object):
class FileStat(object):
def __init__(self, src, dest=None, compare_key=None, size=None,
last_update=None, src_type=None, dest_type=None,
operation_name=None):
Expand Down Expand Up @@ -100,7 +100,7 @@ def call(self, files):
sep_table[dest_type])
else:
dest_path = dest['path']
yield FileBase(src=src_path, dest=dest_path,
yield FileStat(src=src_path, dest=dest_path,
compare_key=compare_key, size=size,
last_update=last_update, src_type=src_type,
dest_type=dest_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from awscli.customizations.s3.fileinfo import FileInfo


class InfoSetter(object):
class FileInfoBuilder(object):
"""
This class takes a ``FileBase`` object's attributes and generates
a ``FileInfo`` object so that the operation can be performed.
Expand All @@ -29,10 +29,10 @@ def __init__(self, service, endpoint, source_endpoint=None,

def call(self, files):
for file_base in files:
file_info = self.inject_info(file_base)
file_info = self._inject_info(file_base)
yield file_info

def inject_info(self, file_base):
def _inject_info(self, file_base):
file_info_attr = {}
file_info_attr['src'] = file_base.src
file_info_attr['dest'] = file_base.dest
Expand Down
14 changes: 7 additions & 7 deletions awscli/customizations/s3/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from awscli.customizations.commands import BasicCommand
from awscli.customizations.s3.comparator import Comparator
from awscli.customizations.s3.infosetter import InfoSetter
from awscli.customizations.s3.fileinfobuilder import FileInfoBuilder
from awscli.customizations.s3.fileformat import FileFormat
from awscli.customizations.s3.filegenerator import FileGenerator
from awscli.customizations.s3.fileinfo import TaskInfo
Expand Down Expand Up @@ -512,7 +512,7 @@ def create_instructions(self):
if self.cmd == 'sync':
self.instructions.append('comparator')
if self.cmd not in ['mb', 'rb']:
self.instructions.append('info_setter')
self.instructions.append('file_info_builder')
self.instructions.append('s3_handler')

def run(self):
Expand Down Expand Up @@ -566,7 +566,7 @@ def run(self):
operation_name=operation_name,
service=self._service,
endpoint=self._endpoint)]
info_setter = InfoSetter(self._service, self._endpoint,
file_info_builder = FileInfoBuilder(self._service, self._endpoint,
self._source_endpoint, self.parameters)
s3handler = S3Handler(self.session, self.parameters)

Expand All @@ -578,25 +578,25 @@ def run(self):
'filters': [create_filter(self.parameters),
create_filter(self.parameters)],
'comparator': [Comparator(self.parameters)],
'info_setter': [info_setter],
'file_info_builder': [file_info_builder],
's3_handler': [s3handler]}
elif self.cmd == 'cp':
command_dict = {'setup': [files],
'file_generator': [file_generator],
'filters': [create_filter(self.parameters)],
'info_setter': [info_setter],
'file_info_builder': [file_info_builder],
's3_handler': [s3handler]}
elif self.cmd == 'rm':
command_dict = {'setup': [files],
'file_generator': [file_generator],
'filters': [create_filter(self.parameters)],
'info_setter': [info_setter],
'file_info_builder': [file_info_builder],
's3_handler': [s3handler]}
elif self.cmd == 'mv':
command_dict = {'setup': [files],
'file_generator': [file_generator],
'filters': [create_filter(self.parameters)],
'info_setter': [info_setter],
'file_info_builder': [file_info_builder],
's3_handler': [s3handler]}
elif self.cmd == 'mb':
command_dict = {'setup': [taskinfo],
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/customizations/s3/test_filegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import botocore.session
from awscli import EnvironmentVariables
from awscli.customizations.s3.filegenerator import FileGenerator, FileBase
from awscli.customizations.s3.filegenerator import FileGenerator, FileStat
from tests.unit.customizations.s3 import make_s3_files, s3_cleanup, \
compare_files

Expand Down Expand Up @@ -51,14 +51,14 @@ def test_s3_file(self):
result_list = list(
FileGenerator(self.service, self.endpoint, '').call(
input_s3_file))
file_base = FileBase(src=self.file1, dest='text1.txt',
file_stat = FileStat(src=self.file1, dest='text1.txt',
compare_key='text1.txt',
size=expected_file_size,
last_update=result_list[0].last_update,
src_type='s3',
dest_type='local', operation_name='')

expected_list = [file_base]
expected_list = [file_stat]
self.assertEqual(len(result_list), 1)
compare_files(self, result_list[0], expected_list[0])

Expand All @@ -74,22 +74,22 @@ def test_s3_directory(self):
result_list = list(
FileGenerator(self.service, self.endpoint, '').call(
input_s3_file))
file_base = FileBase(src=self.file2,
file_stat = FileStat(src=self.file2,
dest='another_directory' + os.sep + 'text2.txt',
compare_key='another_directory/text2.txt',
size=21,
last_update=result_list[0].last_update,
src_type='s3',
dest_type='local', operation_name='')
file_base2 = FileBase(src=self.file1,
file_stat2 = FileStat(src=self.file1,
dest='text1.txt',
compare_key='text1.txt',
size=15,
last_update=result_list[1].last_update,
src_type='s3',
dest_type='local', operation_name='')

expected_result = [file_base, file_base2]
expected_result = [file_stat, file_stat2]
self.assertEqual(len(result_list), 2)
compare_files(self, result_list[0], expected_result[0])
compare_files(self, result_list[1], expected_result[1])
Expand All @@ -108,23 +108,23 @@ def test_s3_delete_directory(self):
'delete').call(
input_s3_file))

file_base1 = FileBase(
file_stat1 = FileStat(
src=self.bucket + '/another_directory/',
dest='another_directory' + os.sep,
compare_key='another_directory/',
size=0,
last_update=result_list[0].last_update,
src_type='s3',
dest_type='local', operation_name='delete')
file_base2 = FileBase(
file_stat2 = FileStat(
src=self.file2,
dest='another_directory' + os.sep + 'text2.txt',
compare_key='another_directory/text2.txt',
size=21,
last_update=result_list[1].last_update,
src_type='s3',
dest_type='local', operation_name='delete')
file_base3 = FileBase(
file_stat3 = FileStat(
src=self.file1,
dest='text1.txt',
compare_key='text1.txt',
Expand All @@ -133,7 +133,7 @@ def test_s3_delete_directory(self):
src_type='s3',
dest_type='local', operation_name='delete')

expected_list = [file_base1, file_base2, file_base3]
expected_list = [file_stat1, file_stat2, file_stat3]
self.assertEqual(len(result_list), 3)
compare_files(self, result_list[0], expected_list[0])
compare_files(self, result_list[1], expected_list[1])
Expand Down
18 changes: 15 additions & 3 deletions tests/integration/customizations/s3/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import botocore.session
import six

from awscli.testutils import unittest, aws, FileCreator
from awscli.testutils import unittest, FileCreator
from awscli.testutils import aws as _aws
from tests.unit.customizations.s3 import create_bucket as _create_bucket
from awscli.customizations.s3 import constants

Expand All @@ -41,6 +42,14 @@ def cd(directory):
os.chdir(original)


def aws(command, collect_memory=False, env_vars=None, wait_for_finish=True):
if not env_vars:
env_vars = os.environ.copy()
env_vars['AWS_DEFAULT_REGION'] = "us-west-2"
return _aws(command, collect_memory=collect_memory, env_vars=env_vars,
wait_for_finish=wait_for_finish)


class BaseS3CLICommand(unittest.TestCase):
"""Base class for aws s3 command.
Expand All @@ -53,7 +62,7 @@ def setUp(self):
self.session = botocore.session.get_session()
self.service = self.session.get_service('s3')
self.regions = {}
self.region = 'us-east-1'
self.region = 'us-west-2'
self.endpoint = self.service.get_endpoint(self.region)
self.extra_setup()

Expand Down Expand Up @@ -597,6 +606,9 @@ def test_sync_with_delete_option_with_same_prefix(self):
class TestSourceRegion(BaseS3CLICommand):
def extra_setup(self):
name_comp = []
# This creates a non DNS compatible bucket name by making two random
# sequences of characters and joining them with a period and
# adding a .com at the end.
for i in range(2):
name_comp.append(''.join(random.sample(string.ascii_lowercase +
string.digits,10)))
Expand All @@ -607,7 +619,7 @@ def extra_setup(self):
string.digits,10)))
self.dest_name = '.'.join(name_comp + ['com'])
self.src_region = 'us-west-1'
self.dest_region = 'us-west-2'
self.dest_region = 'us-east-1'
self.src_bucket = self.create_bucket(self.src_name, self.src_region)
self.dest_bucket = self.create_bucket(self.dest_name, self.dest_region)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/customizations/s3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def create_bucket(session, name=None, region=None):
"""
service = session.get_service('s3')
if not region:
region = 'us-east-1'
region = 'us-west-2'
endpoint = service.get_endpoint(region)
if name:
bucket_name = name
Expand Down Expand Up @@ -150,7 +150,7 @@ def s3_cleanup(bucket, session, key1='text1.txt', key2='text2.txt'):

def compare_files(self, result_file, ref_file):
"""
Ensures that the FileBase's properties are what they
Ensures that the FileStat's properties are what they
are suppose to be.
"""
self.assertEqual(result_file.src, ref_file.src)
Expand Down
Loading

0 comments on commit 8e832a6

Please sign in to comment.