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

Unified Diff: gslib/tests/test_lifecycle.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gslib/tests/test_help.py ('k') | gslib/tests/test_logging.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gslib/tests/test_lifecycle.py
===================================================================
--- gslib/tests/test_lifecycle.py (revision 33376)
+++ gslib/tests/test_lifecycle.py (working copy)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,51 +12,59 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+"""Integration tests for lifecycle command."""
+from __future__ import absolute_import
+
+import json
import posixpath
from xml.dom.minidom import parseString
-from gslib.util import Retry
import gslib.tests.testcase as testcase
+from gslib.tests.testcase.base import NotParallelizable
+from gslib.tests.testcase.integration_testcase import SkipForS3
from gslib.tests.util import ObjectToURI as suri
+from gslib.translation_helper import LifecycleTranslation
+from gslib.util import Retry
+@SkipForS3('Lifecycle command is only supported for gs:// URLs')
class TestSetLifecycle(testcase.GsUtilIntegrationTestCase):
"""Integration tests for lifecycle command."""
- empty_doc1 = parseString(
- '<LifecycleConfiguration/>').toprettyxml(indent=' ')
+ empty_doc1 = '{}'
- empty_doc2 = parseString(
- '<LifecycleConfiguration>'
- '</LifecycleConfiguration>').toprettyxml(indent=' ')
-
- bad_doc1 = ('<?xml version="1.0" ?><LifecycleConfiguration><Rule>'
- '<Action><Delete/></Action></Rule></LifecycleConfiguration>')
-
- bad_doc2 = ('<?xml version="1.0" ?><LifecycleConfiguration><Rule>'
- '<Condition><Age>365</Age></Condition></Rule>'
- '</LifecycleConfiguration>')
-
- bad_doc3 = ('<?xml version="1.0" ?><LifecycleConfiguration><Rule>'
- '<Delete/><Condition><Age>365</Age></Condition></Rule>'
- '</LifecycleConfiguration>')
-
- bad_doc4 = ('<?xml version="1.0" ?><LifecycleConfiguration><Rule>'
- '<Action><Delete/></Action><Age>365</Age></Rule>'
- '</LifecycleConfiguration>')
-
- valid_doc = parseString(
+ xml_doc = parseString(
'<LifecycleConfiguration><Rule>'
'<Action><Delete/></Action>'
'<Condition><Age>365</Age></Condition>'
'</Rule></LifecycleConfiguration>').toprettyxml(indent=' ')
+ bad_doc = (
+ '{"rule": [{"action": {"type": "Add"}, "condition": {"age": 365}}]}\n')
+
+ lifecycle_doc = (
+ '{"rule": [{"action": {"type": "Delete"}, "condition": {"age": 365}}]}\n')
+ lifecycle_json_obj = json.loads(lifecycle_doc)
+
+ no_lifecycle_config = 'has no lifecycle configuration.'
+
+ def test_lifecycle_translation(self):
+ """Tests lifecycle translation for various formats."""
+ json_text = self.lifecycle_doc
+ entries_list = LifecycleTranslation.JsonLifecycleToMessage(json_text)
+ boto_lifecycle = LifecycleTranslation.BotoLifecycleFromMessage(entries_list)
+ converted_entries_list = LifecycleTranslation.BotoLifecycleToMessage(
+ boto_lifecycle)
+ converted_json_text = LifecycleTranslation.JsonLifecycleFromMessage(
+ converted_entries_list)
+ self.assertEqual(json.loads(json_text), json.loads(converted_json_text))
+
def test_default_lifecycle(self):
bucket_uri = self.CreateBucket()
stdout = self.RunGsUtil(['lifecycle', 'get', suri(bucket_uri)],
return_stdout=True)
- self.assertEqual(stdout, self.empty_doc1)
+ self.assertIn(self.no_lifecycle_config, stdout)
def test_set_empty_lifecycle1(self):
bucket_uri = self.CreateBucket()
@@ -63,77 +72,66 @@
self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)])
stdout = self.RunGsUtil(['lifecycle', 'get', suri(bucket_uri)],
return_stdout=True)
- self.assertEqual(stdout, self.empty_doc1)
+ self.assertIn(self.no_lifecycle_config, stdout)
- def test_set_empty_lifecycle2(self):
- bucket_uri = self.CreateBucket()
- fpath = self.CreateTempFile(contents=self.empty_doc2)
- self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)])
- stdout = self.RunGsUtil(['lifecycle', 'get', suri(bucket_uri)],
- return_stdout=True)
- self.assertEqual(stdout, self.empty_doc1)
-
def test_valid_lifecycle(self):
bucket_uri = self.CreateBucket()
- fpath = self.CreateTempFile(contents=self.valid_doc)
+ fpath = self.CreateTempFile(contents=self.lifecycle_doc)
self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)])
stdout = self.RunGsUtil(['lifecycle', 'get', suri(bucket_uri)],
return_stdout=True)
- self.assertEqual(stdout, self.valid_doc)
+ self.assertEqual(json.loads(stdout), self.lifecycle_json_obj)
- def test_bad_lifecycle1(self):
+ def test_bad_lifecycle(self):
bucket_uri = self.CreateBucket()
- fpath = self.CreateTempFile(contents=self.bad_doc1)
- self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)],
- expected_status=1)
+ fpath = self.CreateTempFile(contents=self.bad_doc)
+ stderr = self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)],
+ expected_status=1, return_stderr=True)
+ self.assertNotIn('XML lifecycle data provided', stderr)
- def test_bad_lifecycle2(self):
+ def test_bad_xml_lifecycle(self):
bucket_uri = self.CreateBucket()
- fpath = self.CreateTempFile(contents=self.bad_doc2)
- self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)],
- expected_status=1)
+ fpath = self.CreateTempFile(contents=self.xml_doc)
+ stderr = self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)],
+ expected_status=1, return_stderr=True)
+ self.assertIn('XML lifecycle data provided', stderr)
- def test_bad_lifecycle3(self):
- bucket_uri = self.CreateBucket()
- fpath = self.CreateTempFile(contents=self.bad_doc3)
- self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)],
- expected_status=1)
-
- def test_bad_lifecycle4(self):
- bucket_uri = self.CreateBucket()
- fpath = self.CreateTempFile(contents=self.bad_doc4)
- self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)],
- expected_status=1)
-
def test_set_lifecycle_and_reset(self):
+ """Tests setting and turning off lifecycle configuration."""
bucket_uri = self.CreateBucket()
tmpdir = self.CreateTempDir()
- fpath = self.CreateTempFile(tmpdir=tmpdir, contents=self.valid_doc)
+ fpath = self.CreateTempFile(tmpdir=tmpdir, contents=self.lifecycle_doc)
self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)])
stdout = self.RunGsUtil(['lifecycle', 'get', suri(bucket_uri)],
return_stdout=True)
- self.assertEqual(stdout, self.valid_doc)
+ self.assertEqual(json.loads(stdout), self.lifecycle_json_obj)
fpath = self.CreateTempFile(tmpdir=tmpdir, contents=self.empty_doc1)
self.RunGsUtil(['lifecycle', 'set', fpath, suri(bucket_uri)])
stdout = self.RunGsUtil(['lifecycle', 'get', suri(bucket_uri)],
return_stdout=True)
- self.assertEqual(stdout, self.empty_doc1)
+ self.assertIn(self.no_lifecycle_config, stdout)
def test_set_lifecycle_multi_buckets(self):
+ """Tests setting lifecycle configuration on multiple buckets."""
bucket1_uri = self.CreateBucket()
bucket2_uri = self.CreateBucket()
- fpath = self.CreateTempFile(contents=self.valid_doc)
+ fpath = self.CreateTempFile(contents=self.lifecycle_doc)
self.RunGsUtil(
['lifecycle', 'set', fpath, suri(bucket1_uri), suri(bucket2_uri)])
stdout = self.RunGsUtil(['lifecycle', 'get', suri(bucket1_uri)],
return_stdout=True)
- self.assertEqual(stdout, self.valid_doc)
+ self.assertEqual(json.loads(stdout), self.lifecycle_json_obj)
stdout = self.RunGsUtil(['lifecycle', 'get', suri(bucket2_uri)],
return_stdout=True)
- self.assertEqual(stdout, self.valid_doc)
+ self.assertEqual(json.loads(stdout), self.lifecycle_json_obj)
+ # Script lists buckets with wildcards while they are being deleted by other
+ # tests, which can cause an XML metadata get for the buckets' lifecycle
+ # configurations to fail on a just-deleted bucket.
+ @NotParallelizable
def test_set_lifecycle_wildcard(self):
+ """Tests setting lifecycle with a wildcarded bucket URI."""
random_prefix = self.MakeRandomTestString()
bucket1_name = self.MakeTempName('bucket', prefix=random_prefix)
bucket2_name = self.MakeTempName('bucket', prefix=random_prefix)
@@ -149,7 +147,7 @@
'gs://%sgsutil-test-test_set_lifecycle_wildcard-' % random_prefix))
wildcard = '%s*' % common_prefix
- fpath = self.CreateTempFile(contents=self.valid_doc)
+ fpath = self.CreateTempFile(contents=self.lifecycle_doc)
# Use @Retry as hedge against bucket listing eventual consistency.
expected = set([
@@ -167,7 +165,7 @@
stdout = self.RunGsUtil(['lifecycle', 'get', suri(bucket1_uri)],
return_stdout=True)
- self.assertEqual(stdout, self.valid_doc)
+ self.assertEqual(json.loads(stdout), self.lifecycle_json_obj)
stdout = self.RunGsUtil(['lifecycle', 'get', suri(bucket2_uri)],
return_stdout=True)
- self.assertEqual(stdout, self.valid_doc)
+ self.assertEqual(json.loads(stdout), self.lifecycle_json_obj)
« no previous file with comments | « gslib/tests/test_help.py ('k') | gslib/tests/test_logging.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698