|
| 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.nooverwrite import NoOverwriteSync |
| 17 | +from awscli.testutils import unittest |
| 18 | + |
| 19 | + |
| 20 | +class TestNoOverwriteSync(unittest.TestCase): |
| 21 | + def setUp(self): |
| 22 | + self.sync_strategy = NoOverwriteSync() |
| 23 | + |
| 24 | + def test_file_does_not_exist_at_destination(self): |
| 25 | + """ |
| 26 | + Confirms that files are synced when not present at destination. |
| 27 | + """ |
| 28 | + time_src = datetime.datetime.now() |
| 29 | + |
| 30 | + src_file = FileStat( |
| 31 | + src='', |
| 32 | + dest='', |
| 33 | + compare_key='test.py', |
| 34 | + size=10, |
| 35 | + last_update=time_src, |
| 36 | + src_type='s3', |
| 37 | + dest_type='local', |
| 38 | + operation_name='download', |
| 39 | + ) |
| 40 | + dest_file = None |
| 41 | + should_sync = self.sync_strategy.determine_should_sync( |
| 42 | + src_file, dest_file |
| 43 | + ) |
| 44 | + self.assertTrue(should_sync) |
| 45 | + |
| 46 | + def test_file_exists_at_destination_with_different_key(self): |
| 47 | + """ |
| 48 | + Confirms that files are synced when key differs. |
| 49 | + """ |
| 50 | + time_src = datetime.datetime.now() |
| 51 | + |
| 52 | + src_file = FileStat( |
| 53 | + src='', |
| 54 | + dest='', |
| 55 | + compare_key='test.py', |
| 56 | + size=10, |
| 57 | + last_update=time_src, |
| 58 | + src_type='s3', |
| 59 | + dest_type='s3', |
| 60 | + operation_name='copy', |
| 61 | + ) |
| 62 | + dest_file = FileStat( |
| 63 | + src='', |
| 64 | + dest='', |
| 65 | + compare_key='test1.py', |
| 66 | + size=100, |
| 67 | + last_update=time_src, |
| 68 | + src_type='s3', |
| 69 | + dest_type='s3', |
| 70 | + operation_name='', |
| 71 | + ) |
| 72 | + should_sync = self.sync_strategy.determine_should_sync( |
| 73 | + src_file, dest_file |
| 74 | + ) |
| 75 | + self.assertTrue(should_sync) |
| 76 | + |
| 77 | + def test_file_exists_at_destination_with_same_key(self): |
| 78 | + """ |
| 79 | + Confirm that files with the same key are not synced. |
| 80 | + """ |
| 81 | + time_src = datetime.datetime.now() |
| 82 | + |
| 83 | + src_file = FileStat( |
| 84 | + src='', |
| 85 | + dest='', |
| 86 | + compare_key='test.py', |
| 87 | + size=10, |
| 88 | + last_update=time_src, |
| 89 | + src_type='local', |
| 90 | + dest_type='s3', |
| 91 | + operation_name='upload', |
| 92 | + ) |
| 93 | + dest_file = FileStat( |
| 94 | + src='', |
| 95 | + dest='', |
| 96 | + compare_key='test.py', |
| 97 | + size=100, |
| 98 | + last_update=time_src, |
| 99 | + src_type='local', |
| 100 | + dest_type='s3', |
| 101 | + operation_name='', |
| 102 | + ) |
| 103 | + should_sync = self.sync_strategy.determine_should_sync( |
| 104 | + src_file, dest_file |
| 105 | + ) |
| 106 | + self.assertFalse(should_sync) |
| 107 | + |
| 108 | + |
| 109 | +if __name__ == "__main__": |
| 110 | + unittest.main() |
0 commit comments