OLD | NEW |
1 #!/usr/bin/env python | |
2 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
3 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ | 2 # Copyright (c) 2006-2011 Mitch Garnaat http://garnaat.org/ |
4 # Copyright (c) 2010, Eucalyptus Systems, Inc. | 3 # Copyright (c) 2010, Eucalyptus Systems, Inc. |
| 4 # Copyright (c) 2011, Nexenta Systems, Inc. |
5 # All rights reserved. | 5 # All rights reserved. |
6 # | 6 # |
7 # Permission is hereby granted, free of charge, to any person obtaining a | 7 # Permission is hereby granted, free of charge, to any person obtaining a |
8 # copy of this software and associated documentation files (the | 8 # copy of this software and associated documentation files (the |
9 # "Software"), to deal in the Software without restriction, including | 9 # "Software"), to deal in the Software without restriction, including |
10 # without limitation the rights to use, copy, modify, merge, publish, dis- | 10 # without limitation the rights to use, copy, modify, merge, publish, dis- |
11 # tribute, sublicense, and/or sell copies of the Software, and to permit | 11 # tribute, sublicense, and/or sell copies of the Software, and to permit |
12 # persons to whom the Software is furnished to do so, subject to the fol- | 12 # persons to whom the Software is furnished to do so, subject to the fol- |
13 # lowing conditions: | 13 # lowing conditions: |
14 # | 14 # |
15 # The above copyright notice and this permission notice shall be included | 15 # The above copyright notice and this permission notice shall be included |
16 # in all copies or substantial portions of the Software. | 16 # in all copies or substantial portions of the Software. |
17 # | 17 # |
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
19 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | 19 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
20 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | 20 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
21 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | 21 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
22 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 22 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
24 # IN THE SOFTWARE. | 24 # IN THE SOFTWARE. |
25 | 25 |
26 """ | 26 """ |
27 Some unit tests for the GSConnection | 27 Some unit tests for the GSConnection |
28 """ | 28 """ |
29 | 29 |
30 import unittest | 30 import unittest |
31 import time | 31 import time |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 k.name = 'fie/bar' | 69 k.name = 'fie/bar' |
70 k.set_contents_from_string(s1) | 70 k.set_contents_from_string(s1) |
71 k.name = 'fie/bas' | 71 k.name = 'fie/bas' |
72 k.set_contents_from_string(s1) | 72 k.set_contents_from_string(s1) |
73 k.name = 'fie/bat' | 73 k.name = 'fie/bat' |
74 k.set_contents_from_string(s1) | 74 k.set_contents_from_string(s1) |
75 # try resetting the contents to another value | 75 # try resetting the contents to another value |
76 md5 = k.md5 | 76 md5 = k.md5 |
77 k.set_contents_from_string(s2) | 77 k.set_contents_from_string(s2) |
78 assert k.md5 != md5 | 78 assert k.md5 != md5 |
| 79 # Test for stream API |
| 80 fp2 = open('foobar', 'rb') |
| 81 k.md5 = None |
| 82 k.base64md5 = None |
| 83 k.set_contents_from_stream(fp2, headers=headers) |
| 84 fp = open('foobar1', 'wb') |
| 85 k.get_contents_to_file(fp) |
| 86 fp.close() |
| 87 fp2.seek(0,0) |
| 88 fp = open('foobar1', 'rb') |
| 89 assert (fp2.read() == fp.read()), 'Chunked Transfer corrupted the Data' |
| 90 fp.close() |
| 91 fp2.close() |
| 92 os.unlink('foobar1') |
79 os.unlink('foobar') | 93 os.unlink('foobar') |
80 all = bucket.get_all_keys() | 94 all = bucket.get_all_keys() |
81 assert len(all) == 6 | 95 assert len(all) == 6 |
82 rs = bucket.get_all_keys(prefix='foo') | 96 rs = bucket.get_all_keys(prefix='foo') |
83 assert len(rs) == 3 | 97 assert len(rs) == 3 |
84 rs = bucket.get_all_keys(prefix='', delimiter='/') | 98 rs = bucket.get_all_keys(prefix='', delimiter='/') |
85 assert len(rs) == 2 | 99 assert len(rs) == 2 |
86 rs = bucket.get_all_keys(maxkeys=5) | 100 rs = bucket.get_all_keys(maxkeys=5) |
87 assert len(rs) == 5 | 101 assert len(rs) == 5 |
88 # test the lookup method | 102 # test the lookup method |
89 k = bucket.lookup('foo/bar') | 103 k = bucket.lookup('foo/bar') |
90 assert isinstance(k, bucket.key_class) | 104 assert isinstance(k, bucket.key_class) |
91 assert k.content_type == phony_mimetype | 105 assert k.content_type == phony_mimetype |
92 k = bucket.lookup('notthere') | 106 k = bucket.lookup('notthere') |
93 assert k == None | 107 assert k == None |
94 # try some metadata stuff | 108 # try some metadata stuff |
95 k = bucket.new_key() | 109 k = bucket.new_key() |
96 k.name = 'has_metadata' | 110 k.name = 'has_metadata' |
97 mdkey1 = 'meta1' | 111 mdkey1 = 'meta1' |
98 mdval1 = 'This is the first metadata value' | 112 mdval1 = 'This is the first metadata value' |
99 k.set_metadata(mdkey1, mdval1) | 113 k.set_metadata(mdkey1, mdval1) |
100 mdkey2 = 'meta2' | 114 mdkey2 = 'meta2' |
101 mdval2 = 'This is the second metadata value' | 115 mdval2 = 'This is the second metadata value' |
102 k.set_metadata(mdkey2, mdval2) | 116 k.set_metadata(mdkey2, mdval2) |
103 # try a unicode metadata value | 117 # try a unicode metadata value |
104 | 118 |
105 mdval3 = u'föö' | 119 mdval3 = u'föö' |
106 mdkey3 = 'meta3' | 120 mdkey3 = 'meta3' |
107 k.set_metadata(mdkey3, mdval3) | 121 k.set_metadata(mdkey3, mdval3) |
108 k.set_contents_from_string(s1) | 122 k.set_contents_from_string(s1) |
109 | 123 |
110 k = bucket.lookup('has_metadata') | 124 k = bucket.lookup('has_metadata') |
111 assert k.get_metadata(mdkey1) == mdval1 | 125 assert k.get_metadata(mdkey1) == mdval1 |
112 assert k.get_metadata(mdkey2) == mdval2 | 126 assert k.get_metadata(mdkey2) == mdval2 |
113 assert k.get_metadata(mdkey3) == mdval3 | 127 assert k.get_metadata(mdkey3) == mdval3 |
114 k = bucket.new_key() | 128 k = bucket.new_key() |
115 k.name = 'has_metadata' | 129 k.name = 'has_metadata' |
116 k.get_contents_as_string() | 130 k.get_contents_as_string() |
117 assert k.get_metadata(mdkey1) == mdval1 | 131 assert k.get_metadata(mdkey1) == mdval1 |
118 assert k.get_metadata(mdkey2) == mdval2 | 132 assert k.get_metadata(mdkey2) == mdval2 |
119 assert k.get_metadata(mdkey3) == mdval3 | 133 assert k.get_metadata(mdkey3) == mdval3 |
(...skipping 13 matching lines...) Expand all Loading... |
133 bucket.set_acl('private') | 147 bucket.set_acl('private') |
134 acl = bucket.get_acl() | 148 acl = bucket.get_acl() |
135 assert len(acl.entries.entry_list) == 1 | 149 assert len(acl.entries.entry_list) == 1 |
136 k = bucket.lookup('foo/bar') | 150 k = bucket.lookup('foo/bar') |
137 k.set_acl('public-read') | 151 k.set_acl('public-read') |
138 acl = k.get_acl() | 152 acl = k.get_acl() |
139 assert len(acl.entries.entry_list) == 2 | 153 assert len(acl.entries.entry_list) == 2 |
140 k.set_acl('private') | 154 k.set_acl('private') |
141 acl = k.get_acl() | 155 acl = k.get_acl() |
142 assert len(acl.entries.entry_list) == 1 | 156 assert len(acl.entries.entry_list) == 1 |
| 157 # try set/get raw logging subresource |
| 158 empty_logging_str="<?xml version='1.0' encoding='UTF-8'?><Logging/>" |
| 159 logging_str = ( |
| 160 "<?xml version='1.0' encoding='UTF-8'?><Logging>" |
| 161 "<LogBucket>log-bucket</LogBucket>" + |
| 162 "<LogObjectPrefix>example</LogObjectPrefix>" + |
| 163 "<PredefinedAcl>bucket-owner-full-control</PredefinedAcl>" + |
| 164 "</Logging>") |
| 165 bucket.set_subresource('logging', logging_str); |
| 166 assert bucket.get_subresource('logging') == logging_str; |
| 167 # try disable/enable logging |
| 168 bucket.disable_logging() |
| 169 assert bucket.get_subresource('logging') == empty_logging_str |
| 170 bucket.enable_logging('log-bucket', 'example', |
| 171 canned_acl='bucket-owner-full-control') |
| 172 assert bucket.get_subresource('logging') == logging_str; |
143 # now delete all keys in bucket | 173 # now delete all keys in bucket |
144 for k in bucket: | 174 for k in bucket: |
145 bucket.delete_key(k) | 175 bucket.delete_key(k) |
146 # now delete bucket | 176 # now delete bucket |
147 time.sleep(5) | 177 time.sleep(5) |
148 c.delete_bucket(bucket) | 178 c.delete_bucket(bucket) |
149 print '--- tests completed ---' | 179 print '--- tests completed ---' |
OLD | NEW |