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

Side by Side Diff: third_party/gsutil/boto/tests/s3/test_multipart.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, 8 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 MultiPartUpload
27 """
28
29 # Note:
30 # Multipart uploads require at least one part. If you upload
31 # multiple parts then all parts except the last part has to be
32 # bigger than 5M. Hence we just use 1 part so we can keep
33 # things small and still test logic.
34
35 import unittest
36 import time
37 import StringIO
38 from boto.s3.connection import S3Connection
39
40 class S3MultiPartUploadTest (unittest.TestCase):
41
42 def setUp(self):
43 self.conn = S3Connection(is_secure=False)
44 self.bucket_name = 'multipart-%d' % int(time.time())
45 self.bucket = self.conn.create_bucket(self.bucket_name)
46
47 def tearDown(self):
48 for key in self.bucket:
49 key.delete()
50 self.bucket.delete()
51
52 def test_abort(self):
53 key_name = u"テスト"
54 mpu = self.bucket.initiate_multipart_upload(key_name)
55 mpu.cancel_upload()
56
57 def test_complete_ascii(self):
58 key_name = "test"
59 mpu = self.bucket.initiate_multipart_upload(key_name)
60 fp = StringIO.StringIO("small file")
61 mpu.upload_part_from_file(fp, part_num=1)
62 fp.close()
63 cmpu = mpu.complete_upload()
64 self.assertEqual(cmpu.key_name, key_name)
65 self.assertNotEqual(cmpu.etag, None)
66
67 def test_complete_japanese(self):
68 key_name = u"テスト"
69 mpu = self.bucket.initiate_multipart_upload(key_name)
70 fp = StringIO.StringIO("small file")
71 mpu.upload_part_from_file(fp, part_num=1)
72 fp.close()
73 cmpu = mpu.complete_upload()
74 # LOL... just found an Amazon bug when it returns the
75 # key in the completemultipartupload result. AWS returns
76 # ??? instead of the correctly encoded key name. We should
77 # fix this to the comment line below when amazon fixes this
78 # and this test starts failing due to below assertion.
79 self.assertEqual(cmpu.key_name, "???")
80 #self.assertEqual(cmpu.key_name, key_name)
81 self.assertNotEqual(cmpu.etag, None)
82
83 def test_list_japanese(self):
84 key_name = u"テスト"
85 mpu = self.bucket.initiate_multipart_upload(key_name)
86 rs = self.bucket.list_multipart_uploads()
87 # New bucket, so only one upload expected
88 lmpu = iter(rs).next()
89 self.assertEqual(lmpu.id, mpu.id)
90 self.assertEqual(lmpu.key_name, key_name)
91 # Abort using the one returned in the list
92 lmpu.cancel_upload()
93
94 def test_list_multipart_uploads(self):
95 key_name = u"テスト"
96 mpus = []
97 mpus.append(self.bucket.initiate_multipart_upload(key_name))
98 mpus.append(self.bucket.initiate_multipart_upload(key_name))
99 rs = self.bucket.list_multipart_uploads()
100 # uploads (for a key) are returned in time initiated asc order
101 for lmpu in rs:
102 ompu = mpus.pop(0)
103 self.assertEqual(lmpu.key_name, ompu.key_name)
104 self.assertEqual(lmpu.id, ompu.id)
105 self.assertEqual(0, len(mpus))
106
107 def test_four_part_file(self):
108 key_name = "k"
109 contents = "01234567890123456789"
110 sfp = StringIO.StringIO(contents)
111
112 # upload 20 bytes in 4 parts of 5 bytes each
113 mpu = self.bucket.initiate_multipart_upload(key_name)
114 mpu.upload_part_from_file(sfp, part_num=1, size=5)
115 mpu.upload_part_from_file(sfp, part_num=2, size=5)
116 mpu.upload_part_from_file(sfp, part_num=3, size=5)
117 mpu.upload_part_from_file(sfp, part_num=4, size=5)
118 sfp.close()
119
120 etags = {}
121 pn = 0
122 for part in mpu:
123 pn += 1
124 self.assertEqual(5, part.size)
125 etags[pn] = part.etag
126 self.assertEqual(pn, 4)
127 # etags for 01234
128 self.assertEqual(etags[1], etags[3])
129 # etags for 56789
130 self.assertEqual(etags[2], etags[4])
131 # etag 01234 != etag 56789
132 self.assertNotEqual(etags[1], etags[2])
133
134 # parts are too small to compete as each part must
135 # be a min of 5MB so so we'll assume that is enough
136 # testing and abort the upload.
137 mpu.cancel_upload()
OLDNEW
« no previous file with comments | « third_party/gsutil/boto/tests/s3/test_multidelete.py ('k') | third_party/gsutil/boto/tests/s3/test_pool.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698