@@ -78,42 +78,46 @@ def test_use_default(self):
7878 self ._lookup_bucket_hit_helper (use_default = True )
7979
8080
81- class Test_get_all_buckets (unittest2 .TestCase ):
81+ class Test_list_buckets (unittest2 .TestCase ):
8282
83- def _callFUT (self , project = None , connection = None ):
84- from gcloud .storage .api import get_all_buckets
85- return get_all_buckets ( project = project , connection = connection )
83+ def _callFUT (self , * args , ** kwargs ):
84+ from gcloud .storage .api import list_buckets
85+ return list_buckets ( * args , ** kwargs )
8686
8787 def test_empty (self ):
88+ from six .moves .urllib .parse import urlencode
8889 from gcloud .storage .connection import Connection
8990 PROJECT = 'project'
9091 conn = Connection ()
92+ query_params = urlencode ({'project' : PROJECT , 'projection' : 'noAcl' })
9193 URI = '/' .join ([
9294 conn .API_BASE_URL ,
9395 'storage' ,
9496 conn .API_VERSION ,
95- 'b?project= %s' % PROJECT ,
97+ 'b?%s' % ( query_params ,) ,
9698 ])
9799 http = conn ._http = Http (
98100 {'status' : '200' , 'content-type' : 'application/json' },
99101 b'{}' ,
100102 )
101- buckets = list (self ._callFUT (PROJECT , conn ))
103+ buckets = list (self ._callFUT (project = PROJECT , connection = conn ))
102104 self .assertEqual (len (buckets ), 0 )
103105 self .assertEqual (http ._called_with ['method' ], 'GET' )
104106 self .assertEqual (http ._called_with ['uri' ], URI )
105107
106- def _get_all_buckets_non_empty_helper (self , project , use_default = False ):
108+ def _list_buckets_non_empty_helper (self , project , use_default = False ):
109+ from six .moves .urllib .parse import urlencode
107110 from gcloud ._testing import _monkey_defaults as _base_monkey_defaults
108111 from gcloud .storage ._testing import _monkey_defaults
109112 from gcloud .storage .connection import Connection
110113 BUCKET_NAME = 'bucket-name'
111114 conn = Connection ()
115+ query_params = urlencode ({'project' : project , 'projection' : 'noAcl' })
112116 URI = '/' .join ([
113117 conn .API_BASE_URL ,
114118 'storage' ,
115119 conn .API_VERSION ,
116- 'b?project= %s' % project ,
120+ 'b?%s' % ( query_params ,) ,
117121 ])
118122 http = conn ._http = Http (
119123 {'status' : '200' , 'content-type' : 'application/json' },
@@ -126,18 +130,66 @@ def _get_all_buckets_non_empty_helper(self, project, use_default=False):
126130 with _monkey_defaults (connection = conn ):
127131 buckets = list (self ._callFUT ())
128132 else :
129- buckets = list (self ._callFUT (project , conn ))
133+ buckets = list (self ._callFUT (project = project , connection = conn ))
130134
131135 self .assertEqual (len (buckets ), 1 )
132136 self .assertEqual (buckets [0 ].name , BUCKET_NAME )
133137 self .assertEqual (http ._called_with ['method' ], 'GET' )
134138 self .assertEqual (http ._called_with ['uri' ], URI )
135139
136140 def test_non_empty (self ):
137- self ._get_all_buckets_non_empty_helper ('PROJECT' , use_default = False )
141+ self ._list_buckets_non_empty_helper ('PROJECT' , use_default = False )
138142
139143 def test_non_use_default (self ):
140- self ._get_all_buckets_non_empty_helper ('PROJECT' , use_default = True )
144+ self ._list_buckets_non_empty_helper ('PROJECT' , use_default = True )
145+
146+ def test_all_arguments (self ):
147+ from six .moves .urllib .parse import parse_qs
148+ from six .moves .urllib .parse import urlparse
149+ from gcloud .storage .connection import Connection
150+ PROJECT = 'foo-bar'
151+ MAX_RESULTS = 10
152+ PAGE_TOKEN = 'ABCD'
153+ PREFIX = 'subfolder'
154+ PROJECTION = 'full'
155+ FIELDS = 'items/id,nextPageToken'
156+ EXPECTED_QUERY = {
157+ 'project' : [PROJECT ],
158+ 'maxResults' : [str (MAX_RESULTS )],
159+ 'pageToken' : [PAGE_TOKEN ],
160+ 'prefix' : [PREFIX ],
161+ 'projection' : [PROJECTION ],
162+ 'fields' : [FIELDS ],
163+ }
164+ CONNECTION = Connection ()
165+ http = CONNECTION ._http = Http (
166+ {'status' : '200' , 'content-type' : 'application/json' },
167+ '{"items": []}' ,
168+ )
169+ iterator = self ._callFUT (
170+ project = PROJECT ,
171+ max_results = MAX_RESULTS ,
172+ page_token = PAGE_TOKEN ,
173+ prefix = PREFIX ,
174+ projection = PROJECTION ,
175+ fields = FIELDS ,
176+ connection = CONNECTION ,
177+ )
178+ buckets = list (iterator )
179+ self .assertEqual (buckets , [])
180+ self .assertEqual (http ._called_with ['method' ], 'GET' )
181+ self .assertEqual (http ._called_with ['body' ], None )
182+
183+ BASE_URI = '/' .join ([
184+ CONNECTION .API_BASE_URL ,
185+ 'storage' ,
186+ CONNECTION .API_VERSION ,
187+ 'b'
188+ ])
189+ URI = http ._called_with ['uri' ]
190+ self .assertTrue (URI .startswith (BASE_URI ))
191+ uri_parts = urlparse (URI )
192+ self .assertEqual (parse_qs (uri_parts .query ), EXPECTED_QUERY )
141193
142194
143195class Test_get_bucket (unittest2 .TestCase ):
0 commit comments