Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: third_party/gsutil/boto/tests/unit/s3/test_lifecycle.py

Issue 12317103: Added gsutil to depot tools (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: added readme Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21 #
22 from tests.unit import AWSMockServiceTestCase
23
24 from boto.s3.connection import S3Connection
25 from boto.s3.bucket import Bucket
26 from boto.s3.lifecycle import Rule, Lifecycle, Transition
27
28
29 class TestS3LifeCycle(AWSMockServiceTestCase):
30 connection_class = S3Connection
31
32 def default_body(self):
33 return """
34 <LifecycleConfiguration>
35 <Rule>
36 <ID>rule-1</ID>
37 <Prefix>prefix/foo</Prefix>
38 <Status>Enabled</Status>
39 <Transition>
40 <Days>30</Days>
41 <StorageClass>GLACIER</StorageClass>
42 </Transition>
43 <Expiration>
44 <Days>365</Days>
45 </Expiration>
46 </Rule>
47 <Rule>
48 <ID>rule-2</ID>
49 <Prefix>prefix/bar</Prefix>
50 <Status>Disabled</Status>
51 <Transition>
52 <Date>2012-12-31T00:00:000Z</Date>
53 <StorageClass>GLACIER</StorageClass>
54 </Transition>
55 </Rule>
56 </LifecycleConfiguration>
57 """
58
59 def test_parse_lifecycle_response(self):
60 self.set_http_response(status_code=200)
61 bucket = Bucket(self.service_connection, 'mybucket')
62 response = bucket.get_lifecycle_config()
63 self.assertEqual(len(response), 2)
64 rule = response[0]
65 self.assertEqual(rule.id, 'rule-1')
66 self.assertEqual(rule.prefix, 'prefix/foo')
67 self.assertEqual(rule.status, 'Enabled')
68 self.assertEqual(rule.expiration.days, 365)
69 self.assertIsNone(rule.expiration.date)
70 transition = rule.transition
71 self.assertEqual(transition.days, 30)
72 self.assertEqual(transition.storage_class, 'GLACIER')
73 self.assertEqual(response[1].transition.date, '2012-12-31T00:00:000Z')
74
75 def test_expiration_with_no_transition(self):
76 lifecycle = Lifecycle()
77 lifecycle.add_rule('myid', 'prefix', 'Enabled', 30)
78 xml = lifecycle.to_xml()
79 self.assertIn('<Expiration><Days>30</Days></Expiration>', xml)
80
81 def test_expiration_is_optional(self):
82 t = Transition(days=30, storage_class='GLACIER')
83 r = Rule('myid', 'prefix', 'Enabled', expiration=None,
84 transition=t)
85 xml = r.to_xml()
86 self.assertIn(
87 '<Transition><StorageClass>GLACIER</StorageClass><Days>30</Days>',
88 xml)
89
90 def test_expiration_with_expiration_and_transition(self):
91 t = Transition(date='2012-11-30T00:00:000Z', storage_class='GLACIER')
92 r = Rule('myid', 'prefix', 'Enabled', expiration=30, transition=t)
93 xml = r.to_xml()
94 self.assertIn(
95 '<Transition><StorageClass>GLACIER</StorageClass>'
96 '<Date>2012-11-30T00:00:000Z</Date>', xml)
97 self.assertIn('<Expiration><Days>30</Days></Expiration>', xml)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698