Path: blob/develop/tests/unit/customizations/s3/syncstrategy/test_sizeonly.py
1569 views
# Copyright 2014 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 datetime1314from awscli.customizations.s3.filegenerator import FileStat15from awscli.customizations.s3.syncstrategy.sizeonly import SizeOnlySync1617from awscli.testutils import unittest181920class TestSizeOnlySync(unittest.TestCase):21def setUp(self):22self.sync_strategy = SizeOnlySync()2324def test_compare_size_only(self):25"""26Confirm that files are synced when size differs.27"""28time_src = datetime.datetime.now()29time_dst = time_src + datetime.timedelta(days=1)3031src_file = FileStat(src='', dest='',32compare_key='test.py', size=11,33last_update=time_src, src_type='local',34dest_type='s3', operation_name='upload')3536dst_file = FileStat(src='', dest='',37compare_key='test.py', size=10,38last_update=time_dst, src_type='s3',39dest_type='local', operation_name='')4041should_sync = self.sync_strategy.determine_should_sync(42src_file, dst_file)43self.assertTrue(should_sync)4445def test_compare_size_only_different_update_times(self):46"""47Confirm that files with the same size but different update times48are not synced.49"""50time_src = datetime.datetime.now()51time_dst = time_src + datetime.timedelta(days=1)5253src_file = FileStat(src='', dest='',54compare_key='test.py', size=10,55last_update=time_src, src_type='local',56dest_type='s3', operation_name='upload')5758dst_file = FileStat(src='', dest='',59compare_key='test.py', size=10,60last_update=time_dst, src_type='s3',61dest_type='local', operation_name='')6263should_sync = self.sync_strategy.determine_should_sync(64src_file, dst_file)65self.assertFalse(should_sync)666768if __name__ == "__main__":69unittest.main()707172