-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathtest_storage_fn.py
More file actions
61 lines (45 loc) · 1.68 KB
/
Copy pathtest_storage_fn.py
File metadata and controls
61 lines (45 loc) · 1.68 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
56
57
58
59
60
61
"""
Tests for the storage function.
"""
import unittest
from unittest.mock import Mock
from cloudevents.http import CloudEvent
from firebase_functions import core, storage_fn
class TestStorage(unittest.TestCase):
"""
Storage function tests.
"""
def test_storage_decorator_retry_option(self):
func = Mock(__name__="example_func")
decorated_func = storage_fn.on_object_finalized(bucket="bucket", retry=True)(func)
endpoint = decorated_func.__firebase_endpoint__
self.assertIsNotNone(endpoint.eventTrigger)
self.assertTrue(endpoint.eventTrigger["retry"])
def test_storage_decorator_retry_defaults_false(self):
func = Mock(__name__="example_func")
decorated_func = storage_fn.on_object_finalized(bucket="bucket")(func)
endpoint = decorated_func.__firebase_endpoint__
self.assertIsNotNone(endpoint.eventTrigger)
self.assertFalse(endpoint.eventTrigger["retry"])
def test_calls_init(self):
hello = None
@core.init
def init():
nonlocal hello
hello = "world"
func = Mock(__name__="example_func")
event = CloudEvent(
attributes={"source": "source", "type": "type"},
data={
"bucket": "bucket",
"generation": "generation",
"id": "id",
"metageneration": "metageneration",
"name": "name",
"size": "size",
"storageClass": "storageClass",
},
)
decorated_func = storage_fn.on_object_archived(bucket="bucket")(func)
decorated_func(event)
self.assertEqual("world", hello)