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

Unified Diff: gslib/tests/test_setmeta.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_rsync_funcs.py ('k') | gslib/tests/test_signurl.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gslib/tests/test_setmeta.py
===================================================================
--- gslib/tests/test_setmeta.py (revision 33376)
+++ gslib/tests/test_setmeta.py (working copy)
@@ -12,41 +12,48 @@
# 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 setmeta command."""
+from __future__ import absolute_import
+
import gslib.tests.testcase as testcase
+from gslib.tests.testcase.integration_testcase import SkipForS3
+from gslib.tests.util import ObjectToURI as suri
from gslib.util import Retry
-from gslib.tests.util import ObjectToURI as suri
+from gslib.util import UTF8
class TestSetMeta(testcase.GsUtilIntegrationTestCase):
"""Integration tests for setmeta command."""
def test_initial_metadata(self):
+ """Tests copying file to an object with metadata."""
objuri = suri(self.CreateObject(contents='foo'))
inpath = self.CreateTempFile()
ct = 'image/gif'
- self.RunGsUtil(['-h', 'x-goog-meta-xyz:abc', '-h', 'Content-Type:%s' % ct,
- 'cp', inpath, objuri])
+ self.RunGsUtil(['-h', 'x-%s-meta-xyz:abc' % self.provider_custom_meta,
+ '-h', 'Content-Type:%s' % ct, 'cp', inpath, objuri])
# Use @Retry as hedge against bucket listing eventual consistency.
@Retry(AssertionError, tries=3, timeout_secs=1)
def _Check1():
stdout = self.RunGsUtil(['ls', '-L', objuri], return_stdout=True)
- self.assertRegexpMatches(stdout, 'Content-Type:\s+%s' % ct)
- self.assertRegexpMatches(stdout, 'x-goog-meta-xyz:\s+abc')
+ self.assertRegexpMatches(stdout, r'Content-Type:\s+%s' % ct)
+ self.assertRegexpMatches(stdout, r'xyz:\s+abc')
_Check1()
def test_overwrite_existing(self):
+ """Tests overwriting an object's metadata."""
objuri = suri(self.CreateObject(contents='foo'))
inpath = self.CreateTempFile()
- self.RunGsUtil(['-h', 'x-goog-meta-xyz:abc', '-h', 'Content-Type:image/gif',
- 'cp', inpath, objuri])
+ self.RunGsUtil(['-h', 'x-%s-meta-xyz:abc' % self.provider_custom_meta,
+ '-h', 'Content-Type:image/gif', 'cp', inpath, objuri])
self.RunGsUtil(['setmeta', '-n', '-h', 'Content-Type:text/html', '-h',
- 'x-goog-meta-xyz', objuri])
+ 'x-%s-meta-xyz' % self.provider_custom_meta, objuri])
# Use @Retry as hedge against bucket listing eventual consistency.
@Retry(AssertionError, tries=3, timeout_secs=1)
def _Check1():
stdout = self.RunGsUtil(['ls', '-L', objuri], return_stdout=True)
- self.assertRegexpMatches(stdout, 'Content-Type:\s+text/html')
+ self.assertRegexpMatches(stdout, r'Content-Type:\s+text/html')
self.assertNotIn('xyz', stdout)
_Check1()
@@ -61,7 +68,7 @@
['setmeta', '-h', 'Content-Type:text/html', '-h', 'Content-Type:foobar',
'gs://foo/bar'], expected_status=1, return_stderr=True)
self.assertIn('Each header must appear at most once', stderr)
-
+
def test_recursion_works(self):
bucket_uri = self.CreateBucket()
object1_uri = self.CreateObject(bucket_uri=bucket_uri, contents='foo')
@@ -74,24 +81,26 @@
self.assertIn('footype', stdout)
def test_invalid_non_ascii_custom_header(self):
- unicode_header = u'x-goog-meta-soufflé:5'
- unicode_header_bytes = unicode_header.encode('utf-8')
+ unicode_header = u'x-%s-meta-soufflé:5' % self.provider_custom_meta
+ unicode_header_bytes = unicode_header.encode(UTF8)
stderr = self.RunGsUtil(
['setmeta', '-h', unicode_header_bytes, 'gs://foo/bar'],
expected_status=1, return_stderr=True)
self.assertIn('Invalid non-ASCII header', stderr)
+ @SkipForS3('Only ASCII characters are supported for x-amz-meta headers')
def test_valid_non_ascii_custom_header(self):
+ """Tests setting custom metadata with a non-ASCII content."""
objuri = self.CreateObject(contents='foo')
- unicode_header = u'x-goog-meta-dessert:soufflé'
- unicode_header_bytes = unicode_header.encode('utf-8')
+ unicode_header = u'x-%s-meta-dessert:soufflé' % self.provider_custom_meta
+ unicode_header_bytes = unicode_header.encode(UTF8)
self.RunGsUtil(['setmeta', '-h', unicode_header_bytes, suri(objuri)])
# Use @Retry as hedge against bucket listing eventual consistency.
@Retry(AssertionError, tries=3, timeout_secs=1)
def _Check1():
stdout = self.RunGsUtil(['ls', '-L', suri(objuri)], return_stdout=True)
- stdout = stdout.decode('utf-8')
- self.assertIn(u'x-goog-meta-dessert:\tsoufflé', stdout)
+ stdout = stdout.decode(UTF8)
+ self.assertIn(u'dessert:\t\tsoufflé', stdout)
_Check1()
def test_disallowed_header(self):
@@ -103,8 +112,8 @@
def test_setmeta_bucket(self):
bucket_uri = self.CreateBucket()
stderr = self.RunGsUtil(
- ['setmeta', '-h', 'x-goog-meta-foo:5', suri(bucket_uri)],
- expected_status=1, return_stderr=True)
+ ['setmeta', '-h', 'x-%s-meta-foo:5' % self.provider_custom_meta,
+ suri(bucket_uri)], expected_status=1, return_stderr=True)
self.assertIn('must name an object', stderr)
def test_setmeta_invalid_arg(self):
@@ -113,9 +122,15 @@
return_stderr=True)
self.assertIn('must be either header or header:value', stderr)
+ def test_setmeta_with_canned_acl(self):
+ stderr = self.RunGsUtil(
+ ['setmeta', '-h', 'x-%s-acl:public-read' % self.provider_custom_meta,
+ 'gs://foo/bar'], expected_status=1, return_stderr=True)
+ self.assertIn('gsutil setmeta no longer allows canned ACLs', stderr)
+
def test_invalid_non_ascii_header_value(self):
unicode_header = u'Content-Type:dessert/soufflé'
- unicode_header_bytes = unicode_header.encode('utf-8')
+ unicode_header_bytes = unicode_header.encode(UTF8)
stderr = self.RunGsUtil(
['setmeta', '-h', unicode_header_bytes, 'gs://foo/bar'],
expected_status=1, return_stderr=True)
« no previous file with comments | « gslib/tests/test_rsync_funcs.py ('k') | gslib/tests/test_signurl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698