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

Side by Side Diff: tests/download_from_google_storage_unittests.py

Issue 76583002: Add no_auth flag to skip auth checking for buckets that don't require it. Also fix tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 # pylint: disable=W0212 5 # pylint: disable=W0212
6 6
7 """Unit tests for download_from_google_storage.py.""" 7 """Unit tests for download_from_google_storage.py."""
8 8
9 import optparse 9 import optparse
10 import os 10 import os
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 self.assertEqual(code, 0) 75 self.assertEqual(code, 0)
76 self.assertEqual(err, '') 76 self.assertEqual(err, '')
77 77
78 def test_gsutil_version(self): 78 def test_gsutil_version(self):
79 gsutil = download_from_google_storage.Gsutil(GSUTIL_DEFAULT_PATH, None) 79 gsutil = download_from_google_storage.Gsutil(GSUTIL_DEFAULT_PATH, None)
80 _, _, err = gsutil.check_call('version') 80 _, _, err = gsutil.check_call('version')
81 err_lines = err.splitlines() 81 err_lines = err.splitlines()
82 self.assertEqual(err_lines[0], 'gsutil version 3.25') 82 self.assertEqual(err_lines[0], 'gsutil version 3.25')
83 self.assertEqual( 83 self.assertEqual(
84 err_lines[1], 84 err_lines[1],
85 'checksum 010822c61d38d70ac23600bc955fccf5 (OK)') 85 'checksum c9cffb512f467c0aa54880788b9ee6ca (OK)')
86 86
87 def test_get_sha1(self): 87 def test_get_sha1(self):
88 lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt') 88 lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt')
89 self.assertEqual( 89 self.assertEqual(
90 download_from_google_storage.get_sha1(lorem_ipsum), 90 download_from_google_storage.get_sha1(lorem_ipsum),
91 '7871c8e24da15bad8b0be2c36edc9dc77e37727f') 91 '7871c8e24da15bad8b0be2c36edc9dc77e37727f')
92 92
93 def test_get_md5(self): 93 def test_get_md5(self):
94 lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt') 94 lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt')
95 self.assertEqual( 95 self.assertEqual(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 self.queue.put((None, None)) 172 self.queue.put((None, None))
173 stdout_queue = Queue.Queue() 173 stdout_queue = Queue.Queue()
174 download_from_google_storage._downloader_worker_thread( 174 download_from_google_storage._downloader_worker_thread(
175 0, self.queue, False, self.base_url, self.gsutil, 175 0, self.queue, False, self.base_url, self.gsutil,
176 stdout_queue, self.ret_codes) 176 stdout_queue, self.ret_codes)
177 expected_calls = [ 177 expected_calls = [
178 ('check_call', 178 ('check_call',
179 ('ls', input_filename)), 179 ('ls', input_filename)),
180 ('check_call', 180 ('check_call',
181 ('cp', '-q', input_filename, output_filename))] 181 ('cp', '-q', input_filename, output_filename))]
182 if not sys.platform.startswith('win'):
M-A Ruel 2013/11/19 19:34:40 if sys.platform != 'win32': since it will never b
183 expected_calls.append(
184 ('check_call',
185 ('ls',
186 '-L',
187 'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f')))
182 expected_output = [ 188 expected_output = [
183 '0> Downloading %s...' % output_filename] 189 '0> Downloading %s...' % output_filename]
184 expected_ret_codes = [] 190 expected_ret_codes = []
185 self.assertEqual(list(stdout_queue.queue), expected_output) 191 self.assertEqual(list(stdout_queue.queue), expected_output)
186 self.assertEqual(self.gsutil.history, expected_calls) 192 self.assertEqual(self.gsutil.history, expected_calls)
187 self.assertEqual(list(self.ret_codes.queue), expected_ret_codes) 193 self.assertEqual(list(self.ret_codes.queue), expected_ret_codes)
188 194
189 def test_download_worker_skips_file(self): 195 def test_download_worker_skips_file(self):
190 sha1_hash = 'e6c4fbd4fe7607f3e6ebf68b2ea4ef694da7b4fe' 196 sha1_hash = 'e6c4fbd4fe7607f3e6ebf68b2ea4ef694da7b4fe'
191 output_filename = os.path.join(self.base_path, 'rootfolder_text.txt') 197 output_filename = os.path.join(self.base_path, 'rootfolder_text.txt')
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 force=True, 250 force=True,
245 output=output_filename, 251 output=output_filename,
246 ignore_errors=False, 252 ignore_errors=False,
247 sha1_file=False) 253 sha1_file=False)
248 expected_calls = [ 254 expected_calls = [
249 ('check_call', 255 ('check_call',
250 ('ls', input_filename)), 256 ('ls', input_filename)),
251 ('check_call', 257 ('check_call',
252 ('cp', '-q', input_filename, output_filename)) 258 ('cp', '-q', input_filename, output_filename))
253 ] 259 ]
260 if not sys.platform.startswith('win'):
261 expected_calls.append(
262 ('check_call',
263 ('ls',
264 '-L',
265 'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f')))
254 self.assertEqual(self.gsutil.history, expected_calls) 266 self.assertEqual(self.gsutil.history, expected_calls)
255 self.assertEqual(code, 101) 267 self.assertEqual(code, 101)
256 268
257 def test_download_directory_no_recursive_non_force(self): 269 def test_download_directory_no_recursive_non_force(self):
258 sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f' 270 sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f'
259 input_filename = '%s/%s' % (self.base_url, sha1_hash) 271 input_filename = '%s/%s' % (self.base_url, sha1_hash)
260 output_filename = os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt') 272 output_filename = os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt')
261 code = download_from_google_storage.download_from_google_storage( 273 code = download_from_google_storage.download_from_google_storage(
262 input_filename=self.base_path, 274 input_filename=self.base_path,
263 base_url=self.base_url, 275 base_url=self.base_url,
264 gsutil=self.gsutil, 276 gsutil=self.gsutil,
265 num_threads=1, 277 num_threads=1,
266 directory=True, 278 directory=True,
267 recursive=False, 279 recursive=False,
268 force=False, 280 force=False,
269 output=None, 281 output=None,
270 ignore_errors=False, 282 ignore_errors=False,
271 sha1_file=False) 283 sha1_file=False)
272 expected_calls = [ 284 expected_calls = [
273 ('check_call', 285 ('check_call',
274 ('ls', input_filename)), 286 ('ls', input_filename)),
275 ('check_call', 287 ('check_call',
276 ('cp', '-q', input_filename, output_filename))] 288 ('cp', '-q', input_filename, output_filename))]
289 if not sys.platform.startswith('win'):
290 expected_calls.append(
291 ('check_call',
292 ('ls',
293 '-L',
294 'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f')))
277 self.assertEqual(self.gsutil.history, expected_calls) 295 self.assertEqual(self.gsutil.history, expected_calls)
278 self.assertEqual(code, 0) 296 self.assertEqual(code, 0)
279 297
280 298
281 if __name__ == '__main__': 299 if __name__ == '__main__':
282 unittest.main() 300 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698