|
1 |
| -# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 1 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | #
|
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You
|
4 | 4 | # may not use this file except in compliance with the License. A copy of
|
|
12 | 12 | # language governing permissions and limitations under the License.
|
13 | 13 | import datetime
|
14 | 14 |
|
| 15 | +import pytest |
| 16 | + |
15 | 17 | from awscli.customizations.s3.filegenerator import FileStat
|
16 | 18 | from awscli.customizations.s3.syncstrategy.nooverwrite import NoOverwriteSync
|
17 |
| -from awscli.testutils import unittest |
18 | 19 |
|
19 | 20 |
|
20 |
| -class TestNoOverwriteSync(unittest.TestCase): |
21 |
| - def setUp(self): |
22 |
| - self.sync_strategy = NoOverwriteSync() |
| 21 | +@pytest.fixture |
| 22 | +def sync_strategy(): |
| 23 | + return NoOverwriteSync() |
| 24 | + |
23 | 25 |
|
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() |
| 26 | +def test_file_does_not_exist_at_destination(sync_strategy): |
| 27 | + time_src = datetime.datetime.now() |
29 | 28 |
|
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) |
| 29 | + src_file = FileStat( |
| 30 | + src='', |
| 31 | + dest='', |
| 32 | + compare_key='test.py', |
| 33 | + size=10, |
| 34 | + last_update=time_src, |
| 35 | + src_type='s3', |
| 36 | + dest_type='local', |
| 37 | + operation_name='download', |
| 38 | + ) |
| 39 | + dest_file = None |
| 40 | + should_sync = sync_strategy.determine_should_sync(src_file, dest_file) |
| 41 | + assert should_sync |
45 | 42 |
|
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 | 43 |
|
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) |
| 44 | +def test_file_exists_at_destination_with_different_key(sync_strategy): |
| 45 | + time_src = datetime.datetime.now() |
76 | 46 |
|
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() |
| 47 | + src_file = FileStat( |
| 48 | + src='', |
| 49 | + dest='', |
| 50 | + compare_key='test.py', |
| 51 | + size=10, |
| 52 | + last_update=time_src, |
| 53 | + src_type='s3', |
| 54 | + dest_type='s3', |
| 55 | + operation_name='copy', |
| 56 | + ) |
| 57 | + dest_file = FileStat( |
| 58 | + src='', |
| 59 | + dest='', |
| 60 | + compare_key='test1.py', |
| 61 | + size=100, |
| 62 | + last_update=time_src, |
| 63 | + src_type='s3', |
| 64 | + dest_type='s3', |
| 65 | + operation_name='', |
| 66 | + ) |
| 67 | + should_sync = sync_strategy.determine_should_sync(src_file, dest_file) |
| 68 | + assert should_sync |
82 | 69 |
|
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 | 70 |
|
| 71 | +def test_file_exists_at_destination_with_same_key(): |
| 72 | + sync_strategy = NoOverwriteSync('file_at_src_and_dest') |
| 73 | + time_src = datetime.datetime.now() |
108 | 74 |
|
109 |
| -if __name__ == "__main__": |
110 |
| - unittest.main() |
| 75 | + src_file = FileStat( |
| 76 | + src='', |
| 77 | + dest='', |
| 78 | + compare_key='test.py', |
| 79 | + size=10, |
| 80 | + last_update=time_src, |
| 81 | + src_type='local', |
| 82 | + dest_type='s3', |
| 83 | + operation_name='upload', |
| 84 | + ) |
| 85 | + dest_file = FileStat( |
| 86 | + src='', |
| 87 | + dest='', |
| 88 | + compare_key='test.py', |
| 89 | + size=100, |
| 90 | + last_update=time_src, |
| 91 | + src_type='local', |
| 92 | + dest_type='s3', |
| 93 | + operation_name='', |
| 94 | + ) |
| 95 | + should_sync = sync_strategy.determine_should_sync(src_file, dest_file) |
| 96 | + assert not should_sync |
0 commit comments