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

Side by Side Diff: third_party/gsutil/20110627/boto/tests/s3/test_gsconnection.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 # Copyright (c) 2006-2011 Mitch Garnaat http://garnaat.org/
3 # Copyright (c) 2010, Eucalyptus Systems, Inc.
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 GSConnection
27 """
28
29 import unittest
30 import time
31 import os
32 from boto.gs.connection import GSConnection
33
34 class GSConnectionTest (unittest.TestCase):
35
36 def test_1_basic(self):
37 print '--- running GSConnection tests ---'
38 c = GSConnection()
39 # create a new, empty bucket
40 bucket_name = 'test-%d' % int(time.time())
41 bucket = c.create_bucket(bucket_name)
42 # now try a get_bucket call and see if it's really there
43 bucket = c.get_bucket(bucket_name)
44 k = bucket.new_key()
45 k.name = 'foobar'
46 s1 = 'This is a test of file upload and download'
47 s2 = 'This is a second string to test file upload and download'
48 k.set_contents_from_string(s1)
49 fp = open('foobar', 'wb')
50 # now get the contents from s3 to a local file
51 k.get_contents_to_file(fp)
52 fp.close()
53 fp = open('foobar')
54 # check to make sure content read from s3 is identical to original
55 assert s1 == fp.read(), 'corrupted file'
56 fp.close()
57 bucket.delete_key(k)
58 # test a few variations on get_all_keys - first load some data
59 # for the first one, let's override the content type
60 phony_mimetype = 'application/x-boto-test'
61 headers = {'Content-Type': phony_mimetype}
62 k.name = 'foo/bar'
63 k.set_contents_from_string(s1, headers)
64 k.name = 'foo/bas'
65 k.set_contents_from_filename('foobar')
66 k.name = 'foo/bat'
67 k.set_contents_from_string(s1)
68 k.name = 'fie/bar'
69 k.set_contents_from_string(s1)
70 k.name = 'fie/bas'
71 k.set_contents_from_string(s1)
72 k.name = 'fie/bat'
73 k.set_contents_from_string(s1)
74 # try resetting the contents to another value
75 md5 = k.md5
76 k.set_contents_from_string(s2)
77 assert k.md5 != md5
78 os.unlink('foobar')
79 all = bucket.get_all_keys()
80 assert len(all) == 6
81 rs = bucket.get_all_keys(prefix='foo')
82 assert len(rs) == 3
83 rs = bucket.get_all_keys(prefix='', delimiter='/')
84 assert len(rs) == 2
85 rs = bucket.get_all_keys(maxkeys=5)
86 assert len(rs) == 5
87 # test the lookup method
88 k = bucket.lookup('foo/bar')
89 assert isinstance(k, bucket.key_class)
90 assert k.content_type == phony_mimetype
91 k = bucket.lookup('notthere')
92 assert k == None
93 # try some metadata stuff
94 k = bucket.new_key()
95 k.name = 'has_metadata'
96 mdkey1 = 'meta1'
97 mdval1 = 'This is the first metadata value'
98 k.set_metadata(mdkey1, mdval1)
99 mdkey2 = 'meta2'
100 mdval2 = 'This is the second metadata value'
101 k.set_metadata(mdkey2, mdval2)
102 # try a unicode metadata value
103
104 mdval3 = u'föö'
105 mdkey3 = 'meta3'
106 k.set_metadata(mdkey3, mdval3)
107 k.set_contents_from_string(s1)
108
109 k = bucket.lookup('has_metadata')
110 assert k.get_metadata(mdkey1) == mdval1
111 assert k.get_metadata(mdkey2) == mdval2
112 assert k.get_metadata(mdkey3) == mdval3
113 k = bucket.new_key()
114 k.name = 'has_metadata'
115 k.get_contents_as_string()
116 assert k.get_metadata(mdkey1) == mdval1
117 assert k.get_metadata(mdkey2) == mdval2
118 assert k.get_metadata(mdkey3) == mdval3
119 bucket.delete_key(k)
120 # test list and iterator
121 rs1 = bucket.list()
122 num_iter = 0
123 for r in rs1:
124 num_iter = num_iter + 1
125 rs = bucket.get_all_keys()
126 num_keys = len(rs)
127 assert num_iter == num_keys
128 # try some acl stuff
129 bucket.set_acl('public-read')
130 acl = bucket.get_acl()
131 assert len(acl.entries.entry_list) == 2
132 bucket.set_acl('private')
133 acl = bucket.get_acl()
134 assert len(acl.entries.entry_list) == 1
135 k = bucket.lookup('foo/bar')
136 k.set_acl('public-read')
137 acl = k.get_acl()
138 assert len(acl.entries.entry_list) == 2
139 k.set_acl('private')
140 acl = k.get_acl()
141 assert len(acl.entries.entry_list) == 1
142 # now delete all keys in bucket
143 for k in bucket:
144 bucket.delete_key(k)
145 # now delete bucket
146 time.sleep(5)
147 c.delete_bucket(bucket)
148 print '--- tests completed ---'
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698