Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/s3/syncstrategy/test_exacttimestamps.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.exacttimestamps import \
17
ExactTimestampsSync
18
19
from awscli.testutils import unittest
20
21
22
class TestExactTimestampsSync(unittest.TestCase):
23
def setUp(self):
24
self.sync_strategy = ExactTimestampsSync()
25
26
def test_compare_exact_timestamps_dest_older(self):
27
"""
28
Confirm that same-sized files are synced when
29
the destination is older than the source and
30
`exact_timestamps` is set.
31
"""
32
time_src = datetime.datetime.now()
33
time_dst = time_src - datetime.timedelta(days=1)
34
35
src_file = FileStat(src='', dest='',
36
compare_key='test.py', size=10,
37
last_update=time_src, src_type='s3',
38
dest_type='local', operation_name='download')
39
40
dst_file = FileStat(src='', dest='',
41
compare_key='test.py', size=10,
42
last_update=time_dst, src_type='local',
43
dest_type='s3', operation_name='')
44
45
should_sync = self.sync_strategy.determine_should_sync(
46
src_file, dst_file)
47
self.assertTrue(should_sync)
48
49
def test_compare_exact_timestamps_src_older(self):
50
"""
51
Confirm that same-sized files are synced when
52
the source is older than the destination and
53
`exact_timestamps` is set.
54
"""
55
time_src = datetime.datetime.now() - datetime.timedelta(days=1)
56
time_dst = datetime.datetime.now()
57
58
src_file = FileStat(src='', dest='',
59
compare_key='test.py', size=10,
60
last_update=time_src, src_type='s3',
61
dest_type='local', operation_name='download')
62
63
dst_file = FileStat(src='', dest='',
64
compare_key='test.py', size=10,
65
last_update=time_dst, src_type='local',
66
dest_type='s3', operation_name='')
67
68
should_sync = self.sync_strategy.determine_should_sync(
69
src_file, dst_file)
70
self.assertTrue(should_sync)
71
72
def test_compare_exact_timestamps_same_age_same_size(self):
73
"""
74
Confirm that same-sized files are not synced when
75
the source and destination are the same age and
76
`exact_timestamps` is set.
77
"""
78
time_both = datetime.datetime.now()
79
80
src_file = FileStat(src='', dest='',
81
compare_key='test.py', size=10,
82
last_update=time_both, src_type='s3',
83
dest_type='local', operation_name='download')
84
85
dst_file = FileStat(src='', dest='',
86
compare_key='test.py', size=10,
87
last_update=time_both, src_type='local',
88
dest_type='s3', operation_name='')
89
90
should_sync = self.sync_strategy.determine_should_sync(
91
src_file, dst_file)
92
self.assertFalse(should_sync)
93
94
def test_compare_exact_timestamps_same_age_diff_size(self):
95
"""
96
Confirm that files of differing sizes are synced when
97
the source and destination are the same age and
98
`exact_timestamps` is set.
99
"""
100
time_both = datetime.datetime.now()
101
102
src_file = FileStat(src='', dest='',
103
compare_key='test.py', size=20,
104
last_update=time_both, src_type='s3',
105
dest_type='local', operation_name='download')
106
107
dst_file = FileStat(src='', dest='',
108
compare_key='test.py', size=10,
109
last_update=time_both, src_type='local',
110
dest_type='s3', operation_name='')
111
112
should_sync = self.sync_strategy.determine_should_sync(
113
src_file, dst_file)
114
self.assertTrue(should_sync)
115
116
def test_compare_exact_timestamps_diff_age_not_download(self):
117
"""
118
Confirm that same sized files are synced when the timestamps differ,
119
the type of operation is not a download, and ``exact_timestamps``
120
is set.
121
"""
122
time_src = datetime.datetime.now()
123
time_dst = time_src - datetime.timedelta(days=1)
124
125
src_file = FileStat(src='', dest='',
126
compare_key='test.py', size=10,
127
last_update=time_src, src_type='s3',
128
dest_type='local', operation_name='upload')
129
130
dst_file = FileStat(src='', dest='',
131
compare_key='test.py', size=10,
132
last_update=time_dst, src_type='local',
133
dest_type='s3', operation_name='')
134
135
should_sync = self.sync_strategy.determine_should_sync(
136
src_file, dst_file)
137
self.assertTrue(should_sync)
138
139
140
if __name__ == "__main__":
141
unittest.main()
142
143