Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/s3/syncstrategy/test_sizeonly.py
1569 views
1
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
import datetime
14
15
from awscli.customizations.s3.filegenerator import FileStat
16
from awscli.customizations.s3.syncstrategy.sizeonly import SizeOnlySync
17
18
from awscli.testutils import unittest
19
20
21
class TestSizeOnlySync(unittest.TestCase):
22
def setUp(self):
23
self.sync_strategy = SizeOnlySync()
24
25
def test_compare_size_only(self):
26
"""
27
Confirm that files are synced when size differs.
28
"""
29
time_src = datetime.datetime.now()
30
time_dst = time_src + datetime.timedelta(days=1)
31
32
src_file = FileStat(src='', dest='',
33
compare_key='test.py', size=11,
34
last_update=time_src, src_type='local',
35
dest_type='s3', operation_name='upload')
36
37
dst_file = FileStat(src='', dest='',
38
compare_key='test.py', size=10,
39
last_update=time_dst, src_type='s3',
40
dest_type='local', operation_name='')
41
42
should_sync = self.sync_strategy.determine_should_sync(
43
src_file, dst_file)
44
self.assertTrue(should_sync)
45
46
def test_compare_size_only_different_update_times(self):
47
"""
48
Confirm that files with the same size but different update times
49
are not synced.
50
"""
51
time_src = datetime.datetime.now()
52
time_dst = time_src + datetime.timedelta(days=1)
53
54
src_file = FileStat(src='', dest='',
55
compare_key='test.py', size=10,
56
last_update=time_src, src_type='local',
57
dest_type='s3', operation_name='upload')
58
59
dst_file = FileStat(src='', dest='',
60
compare_key='test.py', size=10,
61
last_update=time_dst, src_type='s3',
62
dest_type='local', operation_name='')
63
64
should_sync = self.sync_strategy.determine_should_sync(
65
src_file, dst_file)
66
self.assertFalse(should_sync)
67
68
69
if __name__ == "__main__":
70
unittest.main()
71
72