Path: blob/develop/tests/unit/customizations/s3/syncstrategy/test_exacttimestamps.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.exacttimestamps import \16ExactTimestampsSync1718from awscli.testutils import unittest192021class TestExactTimestampsSync(unittest.TestCase):22def setUp(self):23self.sync_strategy = ExactTimestampsSync()2425def test_compare_exact_timestamps_dest_older(self):26"""27Confirm that same-sized files are synced when28the destination is older than the source and29`exact_timestamps` is set.30"""31time_src = datetime.datetime.now()32time_dst = time_src - datetime.timedelta(days=1)3334src_file = FileStat(src='', dest='',35compare_key='test.py', size=10,36last_update=time_src, src_type='s3',37dest_type='local', operation_name='download')3839dst_file = FileStat(src='', dest='',40compare_key='test.py', size=10,41last_update=time_dst, src_type='local',42dest_type='s3', operation_name='')4344should_sync = self.sync_strategy.determine_should_sync(45src_file, dst_file)46self.assertTrue(should_sync)4748def test_compare_exact_timestamps_src_older(self):49"""50Confirm that same-sized files are synced when51the source is older than the destination and52`exact_timestamps` is set.53"""54time_src = datetime.datetime.now() - datetime.timedelta(days=1)55time_dst = datetime.datetime.now()5657src_file = FileStat(src='', dest='',58compare_key='test.py', size=10,59last_update=time_src, src_type='s3',60dest_type='local', operation_name='download')6162dst_file = FileStat(src='', dest='',63compare_key='test.py', size=10,64last_update=time_dst, src_type='local',65dest_type='s3', operation_name='')6667should_sync = self.sync_strategy.determine_should_sync(68src_file, dst_file)69self.assertTrue(should_sync)7071def test_compare_exact_timestamps_same_age_same_size(self):72"""73Confirm that same-sized files are not synced when74the source and destination are the same age and75`exact_timestamps` is set.76"""77time_both = datetime.datetime.now()7879src_file = FileStat(src='', dest='',80compare_key='test.py', size=10,81last_update=time_both, src_type='s3',82dest_type='local', operation_name='download')8384dst_file = FileStat(src='', dest='',85compare_key='test.py', size=10,86last_update=time_both, src_type='local',87dest_type='s3', operation_name='')8889should_sync = self.sync_strategy.determine_should_sync(90src_file, dst_file)91self.assertFalse(should_sync)9293def test_compare_exact_timestamps_same_age_diff_size(self):94"""95Confirm that files of differing sizes are synced when96the source and destination are the same age and97`exact_timestamps` is set.98"""99time_both = datetime.datetime.now()100101src_file = FileStat(src='', dest='',102compare_key='test.py', size=20,103last_update=time_both, src_type='s3',104dest_type='local', operation_name='download')105106dst_file = FileStat(src='', dest='',107compare_key='test.py', size=10,108last_update=time_both, src_type='local',109dest_type='s3', operation_name='')110111should_sync = self.sync_strategy.determine_should_sync(112src_file, dst_file)113self.assertTrue(should_sync)114115def test_compare_exact_timestamps_diff_age_not_download(self):116"""117Confirm that same sized files are synced when the timestamps differ,118the type of operation is not a download, and ``exact_timestamps``119is set.120"""121time_src = datetime.datetime.now()122time_dst = time_src - datetime.timedelta(days=1)123124src_file = FileStat(src='', dest='',125compare_key='test.py', size=10,126last_update=time_src, src_type='s3',127dest_type='local', operation_name='upload')128129dst_file = FileStat(src='', dest='',130compare_key='test.py', size=10,131last_update=time_dst, src_type='local',132dest_type='s3', operation_name='')133134should_sync = self.sync_strategy.determine_should_sync(135src_file, dst_file)136self.assertTrue(should_sync)137138139if __name__ == "__main__":140unittest.main()141142143