@@ -78,42 +78,55 @@ 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 parse_qs
89+ from six .moves .urllib .parse import urlparse
8890 from gcloud .storage .connection import Connection
8991 PROJECT = 'project'
9092 conn = Connection ()
91- URI = '/' .join ([
92- conn .API_BASE_URL ,
93- 'storage' ,
94- conn .API_VERSION ,
95- 'b?project=%s' % PROJECT ,
96- ])
93+ EXPECTED_QUERY = {
94+ 'project' : [PROJECT ],
95+ 'projection' : ['noAcl' ],
96+ }
9797 http = conn ._http = Http (
9898 {'status' : '200' , 'content-type' : 'application/json' },
9999 b'{}' ,
100100 )
101- buckets = list (self ._callFUT (PROJECT , conn ))
101+ buckets = list (self ._callFUT (project = PROJECT , connection = conn ))
102102 self .assertEqual (len (buckets ), 0 )
103103 self .assertEqual (http ._called_with ['method' ], 'GET' )
104- self .assertEqual (http ._called_with ['uri' ], URI )
104+ self .assertEqual (http ._called_with ['body' ], None )
105+
106+ BASE_URI = '/' .join ([
107+ conn .API_BASE_URL ,
108+ 'storage' ,
109+ conn .API_VERSION ,
110+ 'b' ,
111+ ])
112+ URI = http ._called_with ['uri' ]
113+ self .assertTrue (URI .startswith (BASE_URI ))
114+ uri_parts = urlparse (URI )
115+ self .assertEqual (parse_qs (uri_parts .query ), EXPECTED_QUERY )
105116
106- def _get_all_buckets_non_empty_helper (self , project , use_default = False ):
117+ def _list_buckets_non_empty_helper (self , project , use_default = False ):
118+ from six .moves .urllib .parse import urlencode
107119 from gcloud ._testing import _monkey_defaults as _base_monkey_defaults
108120 from gcloud .storage ._testing import _monkey_defaults
109121 from gcloud .storage .connection import Connection
110122 BUCKET_NAME = 'bucket-name'
111123 conn = Connection ()
124+ query_params = urlencode ({'project' : project , 'projection' : 'noAcl' })
112125 URI = '/' .join ([
113126 conn .API_BASE_URL ,
114127 'storage' ,
115128 conn .API_VERSION ,
116- 'b?project= %s' % project ,
129+ 'b?%s' % ( query_params ,) ,
117130 ])
118131 http = conn ._http = Http (
119132 {'status' : '200' , 'content-type' : 'application/json' },
@@ -126,18 +139,66 @@ def _get_all_buckets_non_empty_helper(self, project, use_default=False):
126139 with _monkey_defaults (connection = conn ):
127140 buckets = list (self ._callFUT ())
128141 else :
129- buckets = list (self ._callFUT (project , conn ))
142+ buckets = list (self ._callFUT (project = project , connection = conn ))
130143
131144 self .assertEqual (len (buckets ), 1 )
132145 self .assertEqual (buckets [0 ].name , BUCKET_NAME )
133146 self .assertEqual (http ._called_with ['method' ], 'GET' )
134147 self .assertEqual (http ._called_with ['uri' ], URI )
135148
136149 def test_non_empty (self ):
137- self ._get_all_buckets_non_empty_helper ('PROJECT' , use_default = False )
150+ self ._list_buckets_non_empty_helper ('PROJECT' , use_default = False )
138151
139152 def test_non_use_default (self ):
140- self ._get_all_buckets_non_empty_helper ('PROJECT' , use_default = True )
153+ self ._list_buckets_non_empty_helper ('PROJECT' , use_default = True )
154+
155+ def test_all_arguments (self ):
156+ from six .moves .urllib .parse import parse_qs
157+ from six .moves .urllib .parse import urlparse
158+ from gcloud .storage .connection import Connection
159+ PROJECT = 'foo-bar'
160+ MAX_RESULTS = 10
161+ PAGE_TOKEN = 'ABCD'
162+ PREFIX = 'subfolder'
163+ PROJECTION = 'full'
164+ FIELDS = 'items/id,nextPageToken'
165+ EXPECTED_QUERY = {
166+ 'project' : [PROJECT ],
167+ 'maxResults' : [str (MAX_RESULTS )],
168+ 'pageToken' : [PAGE_TOKEN ],
169+ 'prefix' : [PREFIX ],
170+ 'projection' : [PROJECTION ],
171+ 'fields' : [FIELDS ],
172+ }
173+ CONNECTION = Connection ()
174+ http = CONNECTION ._http = Http (
175+ {'status' : '200' , 'content-type' : 'application/json' },
176+ '{"items": []}' ,
177+ )
178+ iterator = self ._callFUT (
179+ project = PROJECT ,
180+ max_results = MAX_RESULTS ,
181+ page_token = PAGE_TOKEN ,
182+ prefix = PREFIX ,
183+ projection = PROJECTION ,
184+ fields = FIELDS ,
185+ connection = CONNECTION ,
186+ )
187+ buckets = list (iterator )
188+ self .assertEqual (buckets , [])
189+ self .assertEqual (http ._called_with ['method' ], 'GET' )
190+ self .assertEqual (http ._called_with ['body' ], None )
191+
192+ BASE_URI = '/' .join ([
193+ CONNECTION .API_BASE_URL ,
194+ 'storage' ,
195+ CONNECTION .API_VERSION ,
196+ 'b'
197+ ])
198+ URI = http ._called_with ['uri' ]
199+ self .assertTrue (URI .startswith (BASE_URI ))
200+ uri_parts = urlparse (URI )
201+ self .assertEqual (parse_qs (uri_parts .query ), EXPECTED_QUERY )
141202
142203
143204class Test_get_bucket (unittest2 .TestCase ):
0 commit comments