Path: blob/develop/tests/unit/customizations/s3/test_fileformat.py
1569 views
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.12import os13import unittest1415from awscli.customizations.s3.fileformat import FileFormat161718class FileFormatTest(unittest.TestCase):19def setUp(self):20self.file_format = FileFormat()2122def test_op_dir(self):23"""24Format a paths for directory operation. There are slashes at the25end of the paths.26"""27src = '.' + os.sep28dest = 's3://kyknapp/golfVid/'29parameters = {'dir_op': True}30files = self.file_format.format(src, dest, parameters)3132ref_files = {'src': {'path': os.path.abspath(src) + os.sep,33'type': 'local'},34'dest': {'path': 'kyknapp/golfVid/', 'type': 's3'},35'dir_op': True, 'use_src_name': True}36self.assertEqual(files, ref_files)3738def test_op_dir_noslash(self):39"""40Format a paths for directory operation. There are no slashes at the41end of the paths.42"""43src = '.'44dest = 's3://kyknapp/golfVid'45parameters = {'dir_op': True}46files = self.file_format.format(src, dest, parameters)4748ref_files = {'src': {'path': os.path.abspath(src) + os.sep,49'type': 'local'},50'dest': {'path': 'kyknapp/golfVid/', 'type': 's3'},51'dir_op': True, 'use_src_name': True}52self.assertEqual(files, ref_files)5354def test_local_use_src_name(self):55"""56No directory operation. S3 source name given. Existing local57destination directory given.58"""59src = 's3://kyknapp/golfVid/hello.txt'60dest = '.'61parameters = {'dir_op': False}62files = self.file_format.format(src, dest, parameters)6364ref_files = {'src': {'path': 'kyknapp/golfVid/hello.txt',65'type': 's3'},66'dest': {'path': os.path.abspath(dest) + os.sep,67'type': 'local'},68'dir_op': False, 'use_src_name': True}69self.assertEqual(files, ref_files)7071def test_local_noexist_file(self):72"""73No directory operation. S3 source name given. Nonexisting local74destination directory given.75"""76src = 's3://kyknapp/golfVid/hello.txt'77dest = 'someFile' + os.sep78parameters = {'dir_op': False}79files = self.file_format.format(src, dest, parameters)8081ref_files = {'src': {'path': 'kyknapp/golfVid/hello.txt',82'type': 's3'},83'dest': {'path': os.path.abspath(dest) + os.sep,84'type': 'local'},85'dir_op': False, 'use_src_name': True}86self.assertEqual(files, ref_files)8788def test_local_keep_dest_name(self):89"""90No directory operation. S3 source name given. Local91destination filename given.92"""93src = 's3://kyknapp/golfVid/hello.txt'94dest = 'hello.txt'95parameters = {'dir_op': False}96files = self.file_format.format(src, dest, parameters)9798ref_files = {'src': {'path': 'kyknapp/golfVid/hello.txt',99'type': 's3'},100'dest': {'path': os.path.abspath(dest),101'type': 'local'},102'dir_op': False, 'use_src_name': False}103self.assertEqual(files, ref_files)104105def test_s3_use_src_name(self):106"""107No directory operation. Local source name given. S3108common prefix given.109"""110src = 'fileformat_test.py'111dest = 's3://kyknapp/golfVid/'112parameters = {'dir_op': False}113files = self.file_format.format(src, dest, parameters)114115ref_files = {'src': {'path': os.path.abspath(src),116'type': 'local'},117'dest': {'path': 'kyknapp/golfVid/', 'type': 's3'},118'dir_op': False, 'use_src_name': True}119self.assertEqual(files, ref_files)120121def test_s3_keep_dest_name(self):122"""123No directory operation. Local source name given. S3124full key given.125"""126src = 'fileformat_test.py'127dest = 's3://kyknapp/golfVid/file.py'128parameters = {'dir_op': False}129files = self.file_format.format(src, dest, parameters)130131ref_files = {'src': {'path': os.path.abspath(src),132'type': 'local'},133'dest': {'path': 'kyknapp/golfVid/file.py', 'type': 's3'},134'dir_op': False, 'use_src_name': False}135self.assertEqual(files, ref_files)136137138if __name__ == "__main__":139unittest.main()140141142