-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest_db.py
More file actions
55 lines (43 loc) · 1.37 KB
/
test_db.py
File metadata and controls
55 lines (43 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Tests for the db module.
"""
import unittest
from unittest import mock
from cloudevents.http import CloudEvent
from firebase_functions import core, db_fn
class TestDb(unittest.TestCase):
"""
Tests for the db module.
"""
def test_calls_init_function(self):
hello = None
@core.init
def init():
nonlocal hello
hello = "world"
func = mock.Mock(__name__="example_func")
decorated_func = db_fn.on_value_created(reference="path")(func)
event = CloudEvent(
attributes={
"specversion": "1.0",
"id": "id",
"source": "source",
"subject": "subject",
"type": "type",
"time": "2024-04-10T12:00:00.000Z",
"instance": "instance",
"ref": "ref",
"firebasedatabasehost": "firebasedatabasehost",
"location": "location",
"authtype": "app-user",
"authid": "auth-id",
},
data={"delta": "delta"},
)
decorated_func(event)
func.assert_called_once()
event = func.call_args.args[0]
self.assertIsNotNone(event)
self.assertEqual(event.auth_type, "app-user")
self.assertEqual(event.auth_id, "auth-id")
self.assertEqual(hello, "world")