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

Side by Side Diff: py/utils/gs_utils_manualtest.py

Issue 427893002: add is_gs_url(), split_gs_url() static methods to gs_utils.py (Closed) Base URL: https://skia.googlesource.com/common.git@master
Patch Set: Ravi comments Created 6 years, 4 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
« no previous file with comments | « py/utils/gs_utils.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 """Tests for gs_utils.py. 3 """Tests for gs_utils.py.
4 4
5 TODO(epoger): How should we exercise these self-tests? See http://skbug.com/2751 5 TODO(epoger): How should we exercise these self-tests? See http://skbug.com/2751
6 """ 6 """
7 7
8 # System-level imports. 8 # System-level imports.
9 import os 9 import os
10 import posixpath 10 import posixpath
(...skipping 21 matching lines...) Expand all
32 into gs://%s? 32 into gs://%s?
33 """ % TEST_BUCKET 33 """ % TEST_BUCKET
34 raise 34 raise
35 35
36 36
37 def _get_unique_posix_dir(): 37 def _get_unique_posix_dir():
38 """Returns a unique directory name suitable for use in Google Storage.""" 38 """Returns a unique directory name suitable for use in Google Storage."""
39 return 'gs_utils_manualtest/%d' % random.randint(0, sys.maxint) 39 return 'gs_utils_manualtest/%d' % random.randint(0, sys.maxint)
40 40
41 41
42 def _test_static_methods():
43 """Test all static methods."""
44 gs = gs_utils.GSUtils
45
46 # (input url, output bucket, output path) for each test case
47 testcases = [
48 (None, None, None),
49 (5, None, None),
50 ('', None, None),
51 ('/one/two', None, None),
52 ('http://one/two', None, None),
53 ('gs:', None, None),
54 ('gs://', None, None),
55 ('gs:///', None, None),
56 ('gs://???', None, None),
57 ('gs:///bucket', None, None),
58 ('gs://bucket', 'bucket', ''),
59 ('GS://bucket/', 'bucket', ''),
60 ('gs://bucket//', 'bucket', ''),
61 ('gs://bucket/path1', 'bucket', 'path1'),
62 ('gs://bucket/path1/path2', 'bucket', 'path1/path2'),
63 ('gs://bucket/path1/path2/', 'bucket', 'path1/path2'),
64 ('gs://bucket///path1/path2///', 'bucket', 'path1/path2'),
65 ('gs://bucket///path1//path2///', 'bucket', 'path1//path2'),
66 ]
67 for (url, bucket, path) in testcases:
68 is_legal_url = (bucket != None)
69 assert gs.is_gs_url(url) == is_legal_url, 'gs.is_gs_url("%s") == %s' % (
70 url, is_legal_url)
71 if is_legal_url:
72 assert gs.split_gs_url(url) == (bucket, path), (
73 'gs.split_gs_url("%s") == ("%s", "%s")' % (url, bucket, path))
74
75
42 def _test_public_read(): 76 def _test_public_read():
43 """Make sure we can read from public files without .boto file credentials.""" 77 """Make sure we can read from public files without .boto file credentials."""
44 gs = gs_utils.GSUtils() 78 gs = gs_utils.GSUtils()
45 gs.list_bucket_contents(bucket=TEST_BUCKET, subdir=None) 79 gs.list_bucket_contents(bucket=TEST_BUCKET, subdir=None)
46 80
47 81
48 def _test_upload_if_one_file(): 82 def _test_upload_if_one_file():
49 """Test upload_if param within upload_file().""" 83 """Test upload_if param within upload_file()."""
50 gs = _get_authenticated_gs_handle() 84 gs = _get_authenticated_gs_handle()
51 filename = 'filename' 85 filename = 'filename'
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 assert file_contents == 'contents of %s\n' % filename, ( 382 assert file_contents == 'contents of %s\n' % filename, (
349 '%s == "contents of %s\n"' % (file_contents, filename)) 383 '%s == "contents of %s\n"' % (file_contents, filename))
350 finally: 384 finally:
351 shutil.rmtree(local_dest_dir) 385 shutil.rmtree(local_dest_dir)
352 for filename in filenames: 386 for filename in filenames:
353 gs.delete_file(bucket=TEST_BUCKET, 387 gs.delete_file(bucket=TEST_BUCKET,
354 path=posixpath.join(remote_dir, subdir, filename)) 388 path=posixpath.join(remote_dir, subdir, filename))
355 389
356 390
357 if __name__ == '__main__': 391 if __name__ == '__main__':
392 _test_static_methods()
358 _test_upload_if_multiple_files() 393 _test_upload_if_multiple_files()
359 _test_upload_if_one_file() 394 _test_upload_if_one_file()
360 _test_public_read() 395 _test_public_read()
361 _test_authenticated_round_trip() 396 _test_authenticated_round_trip()
362 _test_dir_upload_and_download() 397 _test_dir_upload_and_download()
363 # TODO(epoger): Add _test_unauthenticated_access() to make sure we raise 398 # TODO(epoger): Add _test_unauthenticated_access() to make sure we raise
364 # an exception when we try to access without needed credentials. 399 # an exception when we try to access without needed credentials.
OLDNEW
« no previous file with comments | « py/utils/gs_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698