| OLD | NEW |
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 # Copyright (c) 2006-2011 Mitch Garnaat http://garnaat.org/ | 2 # Copyright (c) 2006-2011 Mitch Garnaat http://garnaat.org/ |
| 3 # Copyright (c) 2010, Eucalyptus Systems, Inc. | 3 # Copyright (c) 2010, Eucalyptus Systems, Inc. |
| 4 # Copyright (c) 2011, Nexenta Systems, Inc. | 4 # Copyright (c) 2011, Nexenta Systems, Inc. |
| 5 # Copyright (c) 2012, Google, Inc. | 5 # Copyright (c) 2012, Google, Inc. |
| 6 # All rights reserved. | 6 # All rights reserved. |
| 7 # | 7 # |
| 8 # Permission is hereby granted, free of charge, to any person obtaining a | 8 # Permission is hereby granted, free of charge, to any person obtaining a |
| 9 # copy of this software and associated documentation files (the | 9 # copy of this software and associated documentation files (the |
| 10 # "Software"), to deal in the Software without restriction, including | 10 # "Software"), to deal in the Software without restriction, including |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 24 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 25 # IN THE SOFTWARE. | 25 # IN THE SOFTWARE. |
| 26 | 26 |
| 27 """ | 27 """ |
| 28 Some integration tests for the GSConnection | 28 Some integration tests for the GSConnection |
| 29 """ | 29 """ |
| 30 | 30 |
| 31 import os | 31 import os |
| 32 import re | 32 import re |
| 33 import StringIO | 33 import StringIO |
| 34 import urllib |
| 34 import xml.sax | 35 import xml.sax |
| 35 | 36 |
| 36 from boto import handler | 37 from boto import handler |
| 37 from boto import storage_uri | 38 from boto import storage_uri |
| 38 from boto.gs.acl import ACL | 39 from boto.gs.acl import ACL |
| 39 from boto.gs.cors import Cors | 40 from boto.gs.cors import Cors |
| 40 from boto.gs.lifecycle import LifecycleConfig | 41 from boto.gs.lifecycle import LifecycleConfig |
| 41 from tests.integration.gs.testcase import GSTestCase | 42 from tests.integration.gs.testcase import GSTestCase |
| 42 | 43 |
| 43 | 44 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 tmpdir = self._MakeTempDir() | 93 tmpdir = self._MakeTempDir() |
| 93 fpath = os.path.join(tmpdir, key_name) | 94 fpath = os.path.join(tmpdir, key_name) |
| 94 fp = open(fpath, 'wb') | 95 fp = open(fpath, 'wb') |
| 95 # now get the contents from gcs to a local file | 96 # now get the contents from gcs to a local file |
| 96 k.get_contents_to_file(fp) | 97 k.get_contents_to_file(fp) |
| 97 fp.close() | 98 fp.close() |
| 98 fp = open(fpath) | 99 fp = open(fpath) |
| 99 # check to make sure content read from gcs is identical to original | 100 # check to make sure content read from gcs is identical to original |
| 100 self.assertEqual(s1, fp.read()) | 101 self.assertEqual(s1, fp.read()) |
| 101 fp.close() | 102 fp.close() |
| 103 # Use generate_url to get the contents |
| 104 url = self._conn.generate_url(900, 'GET', bucket=bucket.name, key=key_na
me) |
| 105 f = urllib.urlopen(url) |
| 106 self.assertEqual(s1, f.read()) |
| 107 f.close() |
| 102 # check to make sure set_contents_from_file is working | 108 # check to make sure set_contents_from_file is working |
| 103 sfp = StringIO.StringIO('foo') | 109 sfp = StringIO.StringIO('foo') |
| 104 k.set_contents_from_file(sfp) | 110 k.set_contents_from_file(sfp) |
| 105 self.assertEqual(k.get_contents_as_string(), 'foo') | 111 self.assertEqual(k.get_contents_as_string(), 'foo') |
| 106 sfp2 = StringIO.StringIO('foo2') | 112 sfp2 = StringIO.StringIO('foo2') |
| 107 k.set_contents_from_file(sfp2) | 113 k.set_contents_from_file(sfp2) |
| 108 self.assertEqual(k.get_contents_as_string(), 'foo2') | 114 self.assertEqual(k.get_contents_as_string(), 'foo2') |
| 109 | 115 |
| 110 def test_get_all_keys(self): | 116 def test_get_all_keys(self): |
| 111 """Tests get_all_keys.""" | 117 """Tests get_all_keys.""" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 uri = storage_uri('gs://' + bucket_name) | 425 uri = storage_uri('gs://' + bucket_name) |
| 420 # get lifecycle config and make sure it's empty | 426 # get lifecycle config and make sure it's empty |
| 421 xml = uri.get_lifecycle_config().to_xml() | 427 xml = uri.get_lifecycle_config().to_xml() |
| 422 self.assertEqual(xml, LIFECYCLE_EMPTY) | 428 self.assertEqual(xml, LIFECYCLE_EMPTY) |
| 423 # set lifecycle config | 429 # set lifecycle config |
| 424 lifecycle_config = LifecycleConfig() | 430 lifecycle_config = LifecycleConfig() |
| 425 lifecycle_config.add_rule('Delete', None, LIFECYCLE_CONDITIONS) | 431 lifecycle_config.add_rule('Delete', None, LIFECYCLE_CONDITIONS) |
| 426 uri.configure_lifecycle(lifecycle_config) | 432 uri.configure_lifecycle(lifecycle_config) |
| 427 xml = uri.get_lifecycle_config().to_xml() | 433 xml = uri.get_lifecycle_config().to_xml() |
| 428 self.assertEqual(xml, LIFECYCLE_DOC) | 434 self.assertEqual(xml, LIFECYCLE_DOC) |
| OLD | NEW |