Skip to content

Commit 4b90002

Browse files
committed
Merge branch 'main' of https://github.com/invertase/firebase-functions-python2 into 8-storage
2 parents 281bce6 + 9ab36cf commit 4b90002

File tree

5 files changed

+57
-13
lines changed

5 files changed

+57
-13
lines changed

.vscode/settings.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
"python.linting.enabled": true,
33
"python.linting.pylintEnabled": false,
44
"python.formatting.provider": "yapf",
5-
"python.formatting.yapfArgs": ["--style", "{based_on_style: google, indent_width: 4}"],
5+
"python.formatting.yapfArgs": [
6+
"--style",
7+
"{based_on_style: google, indent_width: 4}"
8+
],
69
"python.linting.pylintPath": "pylint",
7-
"python.envFile": "${workspaceFolder}/.env",
8-
"python.defaultInterpreterPath": "${workspaceFolder}/.env/bin/python3.10",
10+
"python.envFile": "${workspaceFolder}/venv",
11+
"python.defaultInterpreterPath": "${workspaceFolder}/venv/bin/python3.10",
912
"editor.formatOnSave": true,
1013
"python.linting.lintOnSave": true,
1114
"python.linting.mypyEnabled": true,
12-
"mypy.dmypyExecutable": "${workspaceFolder}/.env/bin/dmypy",
15+
"mypy.dmypyExecutable": "${workspaceFolder}/venv/bin/dmypy",
1316
"files.autoSave": "afterDelay"
1417
}

src/firebase_functions/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _db_endpoint_handler(
7777
raw: _ce.CloudEvent,
7878
) -> None:
7979
event_attributes = raw._get_attributes()
80-
event_data = raw._get_data()
80+
event_data: _typing.Any = raw.get_data()
8181
# TODO Params are built locally via path pattern which is currently unimplemented
8282
params: dict[str, str] = {}
8383
database_event_data = event_data["data"]

src/firebase_functions/params.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def __str__(self) -> str:
209209
return f"params.{self.name}"
210210

211211
def __post_init__(self):
212+
if isinstance(self, _DefaultStringParam):
213+
return
212214
if not _re.match(r"^[A-Z0-9_]+$", self.name):
213215
raise ValueError(
214216
"Parameter names must only use uppercase letters, numbers and "
@@ -339,24 +341,36 @@ def value(self) -> list[str]:
339341
return []
340342

341343

342-
PROJECT_ID = StringParam("GCLOUD_PROJECT",
343-
description="The active Firebase project")
344+
@_dataclasses.dataclass(frozen=True)
345+
class _DefaultStringParam(StringParam):
346+
"""
347+
Internal use only.
348+
This is a parameter that is available by default in all functions.
349+
These are excluded from the list of parameters that are prompted to the user.
350+
"""
351+
344352

345-
STORAGE_BUCKET = StringParam(
353+
PROJECT_ID = _DefaultStringParam(
354+
"GCLOUD_PROJECT",
355+
description="The active Firebase project",
356+
)
357+
358+
STORAGE_BUCKET = _DefaultStringParam(
346359
"STORAGE_BUCKET",
347-
description="The default Cloud Storage for Firebase bucket")
360+
description="The default Cloud Storage for Firebase bucket",
361+
)
348362

349-
DATABASE_URL = StringParam(
363+
DATABASE_URL = _DefaultStringParam(
350364
"DATABASE_URL",
351365
description="The Firebase project's default Realtime Database instance URL",
352366
)
353367

354-
DATABASE_INSTANCE = StringParam(
368+
DATABASE_INSTANCE = _DefaultStringParam(
355369
"DATABASE_INSTANCE",
356370
description="The Firebase project's default Realtime Database instance name",
357371
)
358372

359-
EXTENSION_ID = StringParam(
373+
EXTENSION_ID = _DefaultStringParam(
360374
"EXT_INSTANCE_ID",
361375
label="Extension instance ID",
362376
description="When a function is running as part of an extension, "

src/firebase_functions/pubsub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def _message_handler(
9999
raw: _ce.CloudEvent,
100100
) -> None:
101101
event_attributes = raw._get_attributes()
102-
event_data = raw.get_data()
102+
event_data: _typing.Any = raw.get_data()
103103
event_dict = {"data": event_data, **event_attributes}
104104
data = event_dict["data"]
105105
message_dict = data["message"]

tests/test_params.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,30 @@ def test_list_param_equality(self):
189189
["123"]).value() is True), "Failure, equality check returned False"
190190
assert (params.ListParam("LIST_TEST2", default=["456"]).equals(
191191
["123"]).value() is False), "Failure, equality check returned False"
192+
193+
194+
class TestParamsManifest:
195+
"""
196+
Tests any created params are tracked for the purposes
197+
of outputting to the generated manifest.
198+
"""
199+
200+
def test_params_stored(self):
201+
"""Testing if params are internally stored."""
202+
environ["TEST_STORING"] = "TEST_STORING_VALUE"
203+
param = params.StringParam("TEST_STORING")
204+
assert param.value() == "TEST_STORING_VALUE", \
205+
'Failure, params value != "TEST_STORING_VALUE"'
206+
# pylint: disable=protected-access
207+
assert params._params["TEST_STORING"] == param, \
208+
"Failure, param was not stored"
209+
210+
def test_default_params_not_stored(self):
211+
"""Testing if default params are skipped from being stored."""
212+
environ["GCLOUD_PROJECT"] = "python-testing-project"
213+
214+
assert params.PROJECT_ID.value() == "python-testing-project", \
215+
'Failure, params value != "python-testing-project"'
216+
# pylint: disable=protected-access
217+
assert params._params.get("GCLOUD_PROJECT") is None, \
218+
"Failure, default param was stored when it should not have been"

0 commit comments

Comments
 (0)