Skip to content

Commit

Permalink
Removed uri and add doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanedey committed Feb 13, 2024
1 parent 4f7c6e0 commit 73f801c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 35 deletions.
26 changes: 8 additions & 18 deletions firebase_admin/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,6 @@ def _validate_task_options(
', or underscores (_). The maximum length is 500 characters.')
task.name = self._get_url(
resource, _CLOUD_TASKS_API_RESOURCE_PATH + f'/{opts.task_id}')
if opts.uri is not None:
if not _Validators.is_url(opts.uri):
raise ValueError(
'uri must be a valid RFC3986 URI string using the https or http schema.')
task.http_request['url'] = opts.uri
return task

def _update_task_payload(self, task: Task, resource: Resource, extension_id: str) -> Task:
Expand Down Expand Up @@ -387,17 +382,12 @@ class TaskOptions:
By default, Content-Type is set to 'application/json'.
The size of the headers must be less than 80KB.
uri: The full URL path that the request will be sent to. Must be a valid RFC3986 https or
http URL.
"""
schedule_delay_seconds: Optional[int] = None
schedule_time: Optional[datetime] = None
dispatch_deadline_seconds: Optional[int] = None
task_id: Optional[str] = None
headers: Optional[Dict[str, str]] = None
uri: Optional[str] = None

@dataclass
class Task:
Expand All @@ -407,25 +397,25 @@ class Task:
https://cloud.google.com/tasks/docs/reference/rest/v2/projects.locations.queues.tasks#resource:-task
Args:
httpRequest:
name:
schedule_time:
dispatch_deadline:
httpRequest: The request to be made by the task worker.
name: The url path to identify the function.
schedule_time: The time when the task is scheduled to be attempted or retried.
dispatch_deadline: The deadline for requests sent to the worker.
"""
http_request: Dict[str, Optional[str | dict]]
name: Optional[str] = None
schedule_time: Optional[str] = None
dispatch_deadline: Optional[str] = None


Task()
@dataclass
class Resource:
"""Contains the parsed address of a resource.
Args:
resource_id:
project_id:
location_id:
resource_id: The ID of the resource.
project_id: The project ID of the resource.
location_id: The location ID of the resource.
"""
resource_id: str
project_id: Optional[str] = None
Expand Down
19 changes: 2 additions & 17 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,14 @@ def _instrument_functions_service(self, app=None, status=200, payload=_DEFAULT_R
'schedule_time': None,
'dispatch_deadline_seconds': 200,
'task_id': 'test-task-id',
'headers': {'x-test-header': 'test-header-value'},
'uri': 'https://google.com'
'headers': {'x-test-header': 'test-header-value'}
},
{
'schedule_delay_seconds': None,
'schedule_time': _SCHEDULE_TIME,
'dispatch_deadline_seconds': 200,
'task_id': 'test-task-id',
'headers': {'x-test-header': 'test-header-value'},
'uri': 'http://google.com'
'headers': {'x-test-header': 'test-header-value'}
},
])
def test_task_options(self, task_opts_params):
Expand Down Expand Up @@ -306,16 +304,3 @@ def test_invalid_task_id_error(self, task_id):
'hyphens (-), or underscores (_). The maximum length is 500 characters.'
)

@pytest.mark.parametrize('uri', [
'', ' ', 'a', 'foo', 'image.jpg', [], {}, True, 'google.com', 'www.google.com',
'file://www.google.com'
])
def test_invalid_uri_error(self, uri):
_, recorder = self._instrument_functions_service()
opts = functions.TaskOptions(uri=uri)
queue = functions.task_queue('test-function-name')
with pytest.raises(ValueError) as excinfo:
queue.enqueue(_DEFAULT_DATA, opts)
assert len(recorder) == 0
assert str(excinfo.value) == \
'uri must be a valid RFC3986 URI string using the https or http schema.'

0 comments on commit 73f801c

Please sign in to comment.