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

Side by Side Diff: third_party/gsutil/gslib/tests/test_setmeta.py

Issue 12317103: Added gsutil to depot tools (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: added readme Created 7 years, 9 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
OLDNEW
(Empty)
1 # -*- coding: utf-8 -*-
2 # Copyright 2013 Google Inc. All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import gslib.tests.testcase as testcase
17 from gslib.util import Retry
18 from gslib.tests.util import ObjectToURI as suri
19
20
21 class TestSetMeta(testcase.GsUtilIntegrationTestCase):
22 """Integration tests for setmeta command."""
23
24 def test_initial_metadata(self):
25 objuri = suri(self.CreateObject(contents='foo'))
26 inpath = self.CreateTempFile()
27 ct = 'image/gif'
28 self.RunGsUtil(['-h', 'x-goog-meta-xyz:abc', '-h', 'Content-Type:%s' % ct,
29 'cp', inpath, objuri])
30 # Use @Retry as hedge against bucket listing eventual consistency.
31 @Retry(AssertionError, tries=3, delay=1, backoff=1)
32 def _Check1():
33 stdout = self.RunGsUtil(['ls', '-L', objuri], return_stdout=True)
34 self.assertIn('Content-Type:\t%s' % ct, stdout)
35 self.assertIn('x-goog-meta-xyz:\tabc', stdout)
36 _Check1()
37
38 def test_overwrite_existing(self):
39 objuri = suri(self.CreateObject(contents='foo'))
40 inpath = self.CreateTempFile()
41 self.RunGsUtil(['-h', 'x-goog-meta-xyz:abc', '-h', 'Content-Type:image/gif',
42 'cp', inpath, objuri])
43 self.RunGsUtil(['setmeta', '-n', '-h', 'Content-Type:text/html', '-h',
44 'x-goog-meta-xyz', objuri])
45 # Use @Retry as hedge against bucket listing eventual consistency.
46 @Retry(AssertionError, tries=3, delay=1, backoff=1)
47 def _Check1():
48 stdout = self.RunGsUtil(['ls', '-L', objuri], return_stdout=True)
49 self.assertIn('Content-Type:\ttext/html', stdout)
50 self.assertNotIn('xyz', stdout)
51 _Check1()
52
53 def test_missing_header(self):
54 stderr = self.RunGsUtil(['setmeta', '"Content-Type"', 'gs://foo/bar'],
55 expected_status=1, return_stderr=True)
56 self.assertIn('Fields being added must include values', stderr)
57
58 def test_minus_header_value(self):
59 stderr = self.RunGsUtil(['setmeta', '"-Content-Type:text/html"',
60 'gs://foo/bar'], expected_status=1,
61 return_stderr=True)
62 self.assertIn('Removal spec may not contain ":"', stderr)
63
64 def test_plus_and_minus(self):
65 stderr = self.RunGsUtil(['setmeta', ('"Content-Type:text/html",'
66 '"-Content-Type"'), 'gs://foo/bar'],
67 expected_status=1, return_stderr=True)
68 self.assertIn('Each header must appear at most once', stderr)
69
70 def test_non_ascii_custom_header(self):
71 stderr = self.RunGsUtil(['setmeta', '"x-goog-meta-soufflé:5"',
72 'gs://foo/bar'], expected_status=1,
73 return_stderr=True)
74 self.assertIn('Invalid non-ASCII header', stderr)
75
76 def test_disallowed_header(self):
77 stderr = self.RunGsUtil(['setmeta', '"Content-Length:5"',
78 'gs://foo/bar'], expected_status=1,
79 return_stderr=True)
80 self.assertIn('Invalid or disallowed header', stderr)
81
82 def test_deprecated_syntax(self):
83 objuri = suri(self.CreateObject(contents='foo'))
84 inpath = self.CreateTempFile()
85 self.RunGsUtil(['-h', 'x-goog-meta-xyz:abc', '-h', 'Content-Type:image/gif',
86 'cp', inpath, objuri])
87
88 # Use @Retry as hedge against bucket listing eventual consistency.
89 @Retry(AssertionError, tries=3, delay=1, backoff=1)
90 def _Check1():
91 stdout = self.RunGsUtil(['ls', '-L', objuri], return_stdout=True)
92 self.assertIn('Content-Type:\timage/gif', stdout)
93 self.assertIn('x-goog-meta-xyz:\tabc', stdout)
94 _Check1()
95
96 stderr = self.RunGsUtil(
97 ['setmeta', '-n', '"Content-Type:text/html","-x-goog-meta-xyz"',
98 objuri],
99 return_stderr=True)
100 self.assertIn('WARNING: metadata spec syntax', stderr)
101 self.assertIn('is deprecated and will eventually be removed', stderr)
102 # Use @Retry as hedge against bucket listing eventual consistency.
103 @Retry(AssertionError, tries=3, delay=1, backoff=1)
104 def _Check2():
105 stdout = self.RunGsUtil(['ls', '-L', objuri], return_stdout=True)
106 self.assertIn('Content-Type:\ttext/html', stdout)
107 self.assertNotIn('xyz', stdout)
108 _Check2()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698