@@ -55,6 +55,13 @@ def _instrument_functions_service(self, app=None, status=200, payload=_DEFAULT_R
55
55
testutils .MockAdapter (payload , status , recorder ))
56
56
return functions_service , recorder
57
57
58
+ def test_task_queue_no_project_id (self ):
59
+ def evaluate ():
60
+ app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'no-project-id' )
61
+ with pytest .raises (ValueError ):
62
+ functions .task_queue ('test-function-name' , app = app )
63
+ testutils .run_without_project_id (evaluate )
64
+
58
65
@pytest .mark .parametrize ('function_name' , [
59
66
'projects/test-project/locations/us-central1/functions/test-function-name' ,
60
67
'locations/us-central1/functions/test-function-name' ,
@@ -179,14 +186,16 @@ def _instrument_functions_service(self, app=None, status=200, payload=_DEFAULT_R
179
186
'schedule_time' : None ,
180
187
'dispatch_deadline_seconds' : 200 ,
181
188
'task_id' : 'test-task-id' ,
182
- 'headers' : {'x-test-header' : 'test-header-value' }
189
+ 'headers' : {'x-test-header' : 'test-header-value' },
190
+ 'uri' : 'https://google.com'
183
191
},
184
192
{
185
193
'schedule_delay_seconds' : None ,
186
194
'schedule_time' : _SCHEDULE_TIME ,
187
195
'dispatch_deadline_seconds' : 200 ,
188
196
'task_id' : 'test-task-id' ,
189
- 'headers' : {'x-test-header' : 'test-header-value' }
197
+ 'headers' : {'x-test-header' : 'test-header-value' },
198
+ 'uri' : 'http://google.com'
190
199
},
191
200
])
192
201
def test_task_options (self , task_opts_params ):
@@ -204,6 +213,7 @@ def test_task_options(self, task_opts_params):
204
213
205
214
assert task ['dispatch_deadline' ] == '200s'
206
215
assert task ['http_request' ]['headers' ]['x-test-header' ] == 'test-header-value'
216
+ assert task ['http_request' ]['url' ] in ['http://google.com' , 'https://google.com' ]
207
217
assert task ['name' ] == _DEFAULT_TASK_PATH
208
218
209
219
@@ -223,6 +233,7 @@ def test_schedule_set_twice_error(self):
223
233
str (datetime .utcnow ()),
224
234
datetime .utcnow ().isoformat (),
225
235
datetime .utcnow ().isoformat () + 'Z' ,
236
+ '' , ' '
226
237
])
227
238
def test_invalid_schedule_time_error (self , schedule_time ):
228
239
_ , recorder = self ._instrument_functions_service ()
@@ -235,11 +246,7 @@ def test_invalid_schedule_time_error(self, schedule_time):
235
246
236
247
237
248
@pytest .mark .parametrize ('schedule_delay_seconds' , [
238
- - 1 ,
239
- '100' ,
240
- '-1' ,
241
- - 1.23 ,
242
- 1.23
249
+ - 1 , '100' , '-1' , '' , ' ' , - 1.23 , 1.23
243
250
])
244
251
def test_invalid_schedule_delay_seconds_error (self , schedule_delay_seconds ):
245
252
_ , recorder = self ._instrument_functions_service ()
@@ -252,15 +259,7 @@ def test_invalid_schedule_delay_seconds_error(self, schedule_delay_seconds):
252
259
253
260
254
261
@pytest .mark .parametrize ('dispatch_deadline_seconds' , [
255
- 14 ,
256
- 1801 ,
257
- - 15 ,
258
- - 1800 ,
259
- 0 ,
260
- '100' ,
261
- '-1' ,
262
- - 1.23 ,
263
- 1.23 ,
262
+ 14 , 1801 , - 15 , - 1800 , 0 , '100' , '-1' , '' , ' ' , - 1.23 , 1.23 ,
264
263
])
265
264
def test_invalid_dispatch_deadline_seconds_error (self , dispatch_deadline_seconds ):
266
265
_ , recorder = self ._instrument_functions_service ()
@@ -274,10 +273,7 @@ def test_invalid_dispatch_deadline_seconds_error(self, dispatch_deadline_seconds
274
273
275
274
276
275
@pytest .mark .parametrize ('task_id' , [
277
- 'task/1' ,
278
- 'task.1' ,
279
- 'a' * 501 ,
280
- * non_alphanumeric_chars
276
+ '' , ' ' , 'task/1' , 'task.1' , 'a' * 501 , * non_alphanumeric_chars
281
277
])
282
278
def test_invalid_task_id_error (self , task_id ):
283
279
_ , recorder = self ._instrument_functions_service ()
@@ -290,3 +286,16 @@ def test_invalid_task_id_error(self, task_id):
290
286
'task_id can contain only letters ([A-Za-z]), numbers ([0-9]), '
291
287
'hyphens (-), or underscores (_). The maximum length is 500 characters.'
292
288
)
289
+
290
+ @pytest .mark .parametrize ('uri' , [
291
+ '' , ' ' , 'a' , 'foo' , 'image.jpg' , [], {}, True , 'google.com' , 'www.google.com'
292
+ ])
293
+ def test_invalid_uri_error (self , uri ):
294
+ _ , recorder = self ._instrument_functions_service ()
295
+ opts = functions .TaskOptions (uri = uri )
296
+ queue = functions .task_queue ('test-function-name' )
297
+ with pytest .raises (ValueError ) as excinfo :
298
+ queue .enqueue (_DEFAULT_DATA , opts )
299
+ assert len (recorder ) == 0
300
+ assert str (excinfo .value ) == \
301
+ 'uri must be a valid RFC3986 URI string using the https or http schema.'
0 commit comments