Skip to content

Commit 7481ddf

Browse files
committed
fix: lints
1 parent cff357e commit 7481ddf

File tree

2 files changed

+55
-36
lines changed

2 files changed

+55
-36
lines changed

Diff for: src/firebase_functions/firestore_fn.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Event(_core.CloudEvent[_core.T]):
8888
_C2 = _typing.Callable[[_E2], None]
8989

9090
AuthType = _typing.Literal["service_account", "api_key", "system",
91-
"unauthenticated", "unknown"]
91+
"unauthenticated", "unknown"]
9292

9393

9494
@_dataclass.dataclass(frozen=True)
@@ -106,10 +106,10 @@ class EventWithAuthContext(Event[_core.T]):
106106

107107

108108
def _firestore_endpoint_handler(
109-
func: _C1 | _C2 | _C3 | _C4,
110-
event_type: str,
111-
document_pattern: _path_pattern.PathPattern,
112-
raw: _ce.CloudEvent,
109+
func: _C1 | _C2 | _C3 | _C4,
110+
event_type: str,
111+
document_pattern: _path_pattern.PathPattern,
112+
raw: _ce.CloudEvent,
113113
) -> None:
114114
event_attributes = raw._get_attributes()
115115
event_data: _typing.Any = raw.get_data()
@@ -266,7 +266,7 @@ def on_document_written_wrapped(raw: _ce.CloudEvent):
266266

267267
@_util.copy_func_kwargs(FirestoreOptions)
268268
def on_document_written_with_auth_context(**kwargs
269-
) -> _typing.Callable[[_C1], _C1]:
269+
) -> _typing.Callable[[_C1], _C1]:
270270
"""
271271
Event handler that triggers when a document is created, updated, or deleted in Firestore.
272272
This trigger will also provide the authentication context of the principal who triggered
@@ -365,7 +365,7 @@ def on_document_updated_wrapped(raw: _ce.CloudEvent):
365365

366366
@_util.copy_func_kwargs(FirestoreOptions)
367367
def on_document_updated_with_auth_context(**kwargs
368-
) -> _typing.Callable[[_C1], _C1]:
368+
) -> _typing.Callable[[_C1], _C1]:
369369
"""
370370
Event handler that triggers when a document is updated in Firestore.
371371
This trigger will also provide the authentication context of the principal who triggered
@@ -464,7 +464,7 @@ def on_document_created_wrapped(raw: _ce.CloudEvent):
464464

465465
@_util.copy_func_kwargs(FirestoreOptions)
466466
def on_document_created_with_auth_context(**kwargs
467-
) -> _typing.Callable[[_C2], _C2]:
467+
) -> _typing.Callable[[_C2], _C2]:
468468
"""
469469
Event handler that triggers when a document is created in Firestore.
470470
This trigger will also provide the authentication context of the principal who triggered
@@ -563,7 +563,7 @@ def on_document_deleted_wrapped(raw: _ce.CloudEvent):
563563

564564
@_util.copy_func_kwargs(FirestoreOptions)
565565
def on_document_deleted_with_auth_context(**kwargs
566-
) -> _typing.Callable[[_C2], _C2]:
566+
) -> _typing.Callable[[_C2], _C2]:
567567
"""
568568
Event handler that triggers when a document is deleted in Firestore.
569569
This trigger will also provide the authentication context of the principal who triggered

Diff for: tests/test_firestore_fn.py

+46-27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
This module contains tests for the firestore_fn module.
3+
"""
4+
15
import json
26
from unittest import TestCase
37
from unittest.mock import MagicMock, Mock, patch
@@ -10,44 +14,59 @@
1014

1115

1216
class TestFirestore(TestCase):
17+
"""
18+
firestore_fn tests.
19+
"""
20+
1321
def test_firestore_endpoint_handler_calls_function_with_correct_args(self):
14-
with patch.dict('sys.modules', mocked_modules):
22+
with patch.dict("sys.modules", mocked_modules):
1523
from cloudevents.http import CloudEvent
16-
from firebase_functions import firestore_fn
24+
from firebase_functions.firestore_fn import _event_type_created_with_auth_context as event_type, \
25+
_firestore_endpoint_handler as firestore_endpoint_handler, EventWithAuthContext
1726
from firebase_functions.private import path_pattern
1827

1928
func = Mock(__name__="example_func")
2029

21-
event_type = firestore_fn._event_type_created_with_auth_context
2230
document_pattern = path_pattern.PathPattern("foo/{bar}")
23-
raw_event = CloudEvent(
24-
attributes={
25-
"specversion": "1.0",
26-
"type": event_type,
27-
"source": "https://example.com/testevent",
28-
"time": "2023-03-11T13:25:37.403Z",
29-
"subject": "test_subject",
30-
"datacontenttype": "application/json",
31-
"location": "projects/project-id/databases/(default)/documents/foo/{bar}",
32-
"project": "project-id",
33-
"namespace": "(default)",
34-
"document": "foo/{bar}",
35-
"database": "projects/project-id/databases/(default)",
36-
"authtype": "unauthenticated",
37-
"authid": "foo"
38-
},
39-
data=json.dumps({})
40-
)
41-
42-
firestore_fn._firestore_endpoint_handler(func=func,
43-
event_type=event_type,
44-
document_pattern=document_pattern,
45-
raw=raw_event)
31+
attributes = {
32+
"specversion":
33+
"1.0",
34+
"type":
35+
event_type,
36+
"source":
37+
"https://example.com/testevent",
38+
"time":
39+
"2023-03-11T13:25:37.403Z",
40+
"subject":
41+
"test_subject",
42+
"datacontenttype":
43+
"application/json",
44+
"location":
45+
"projects/project-id/databases/(default)/documents/foo/{bar}",
46+
"project":
47+
"project-id",
48+
"namespace":
49+
"(default)",
50+
"document":
51+
"foo/{bar}",
52+
"database":
53+
"projects/project-id/databases/(default)",
54+
"authtype":
55+
"unauthenticated",
56+
"authid":
57+
"foo"
58+
}
59+
raw_event = CloudEvent(attributes=attributes, data=json.dumps({}))
60+
61+
firestore_endpoint_handler(func=func,
62+
event_type=event_type,
63+
document_pattern=document_pattern,
64+
raw=raw_event)
4665

4766
func.assert_called_once()
4867

4968
event = func.call_args.args[0]
5069
self.assertIsNotNone(event)
51-
self.assertIsInstance(event, firestore_fn.EventWithAuthContext)
70+
self.assertIsInstance(event, EventWithAuthContext)
5271
self.assertEqual(event.auth_type, "unauthenticated")
5372
self.assertEqual(event.auth_id, "foo")

0 commit comments

Comments
 (0)