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

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

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 Mitch Garnaat http://garnaat.org/
4 # All rights reserved.
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish, dis-
10 # tribute, sublicense, and/or sell copies of the Software, and to permit
11 # persons to whom the Software is furnished to do so, subject to the fol-
12 # lowing conditions:
13 #
14 # The above copyright notice and this permission notice shall be included
15 # in all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
19 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
20 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 # IN THE SOFTWARE.
24
25 """
26 Some unit tests for the S3 Bucket
27 """
28
29 import unittest
30 import time
31
32 from boto.s3.connection import S3Connection
33 from boto.s3.bucketlogging import BucketLogging
34 from boto.s3.acl import Grant
35
36 class S3BucketTest (unittest.TestCase):
37
38 def setUp(self):
39 self.conn = S3Connection()
40 self.bucket_name = 'bucket-%d' % int(time.time())
41 self.bucket = self.conn.create_bucket(self.bucket_name)
42
43 def tearDown(self):
44 for key in self.bucket:
45 key.delete()
46 self.bucket.delete()
47
48 def test_next_marker(self):
49 expected = ["a/", "b", "c"]
50 for key_name in expected:
51 key = self.bucket.new_key(key_name)
52 key.set_contents_from_string(key_name)
53
54 # Normal list of first 2 keys will have
55 # no NextMarker set, so we use last key to iterate
56 # last element will be "b" so no issue.
57 rs = self.bucket.get_all_keys(max_keys=2)
58 for element in rs:
59 pass
60 self.assertEqual(element.name, "b")
61 self.assertEqual(rs.next_marker, None)
62
63 # list using delimiter of first 2 keys will have
64 # a NextMarker set (when truncated). As prefixes
65 # are grouped together at the end, we get "a/" as
66 # last element, but luckily we have next_marker.
67 rs = self.bucket.get_all_keys(max_keys=2, delimiter="/")
68 for element in rs:
69 pass
70 self.assertEqual(element.name, "a/")
71 self.assertEqual(rs.next_marker, "b")
72
73 # ensure bucket.list() still works by just
74 # popping elements off the front of expected.
75 rs = self.bucket.list()
76 for element in rs:
77 self.assertEqual(element.name, expected.pop(0))
78 self.assertEqual(expected, [])
79
80 def test_logging(self):
81 # use self.bucket as the target bucket so that teardown
82 # will delete any log files that make it into the bucket
83 # automatically and all we have to do is delete the
84 # source bucket.
85 sb_name = "src-" + self.bucket_name
86 sb = self.conn.create_bucket(sb_name)
87 # grant log write perms to target bucket using canned-acl
88 self.bucket.set_acl("log-delivery-write")
89 target_bucket = self.bucket_name
90 target_prefix = u"jp/ログ/"
91 # Check existing status is disabled
92 bls = sb.get_logging_status()
93 self.assertEqual(bls.target, None)
94 # Create a logging status and grant auth users READ PERM
95 authuri = "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
96 authr = Grant(permission="READ", type="Group", uri=authuri)
97 sb.enable_logging(target_bucket, target_prefix=target_prefix, grants=[au thr])
98 # Check the status and confirm its set.
99 bls = sb.get_logging_status()
100 self.assertEqual(bls.target, target_bucket)
101 self.assertEqual(bls.prefix, target_prefix)
102 self.assertEqual(len(bls.grants), 1)
103 self.assertEqual(bls.grants[0].type, "Group")
104 self.assertEqual(bls.grants[0].uri, authuri)
105 # finally delete the src bucket
106 sb.delete()
OLDNEW
« no previous file with comments | « third_party/gsutil/boto/tests/s3/other_cacerts.txt ('k') | third_party/gsutil/boto/tests/s3/test_connection.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698