15
15
Internal utils tests.
16
16
"""
17
17
from os import environ , path
18
- from firebase_functions .private .util import firebase_config , microsecond_timestamp_conversion , nanoseconds_timestamp_conversion , is_precision_timestamp , normalize_path , deep_merge
18
+ from firebase_functions .private .util import firebase_config , microsecond_timestamp_conversion , nanoseconds_timestamp_conversion , get_precision_timestamp , normalize_path , deep_merge , PrecisionTimestamp , second_timestamp_conversion
19
19
import datetime as _dt
20
20
21
21
test_bucket = "python-functions-testing.appspot.com"
@@ -80,6 +80,23 @@ def test_nanosecond_conversion():
80
80
assert nanoseconds_timestamp_conversion (
81
81
input_timestamp ) == expected_datetime
82
82
83
+ def test_second_conversion ():
84
+ """
85
+ Testing seconds_timestamp_conversion works as intended
86
+ """
87
+ timestamps = [
88
+ ("2023-01-01T12:34:56Z" , "2023-01-01T12:34:56Z" ),
89
+ ("2023-02-14T14:37:52Z" , "2023-02-14T14:37:52Z" ),
90
+ ("2023-03-21T06:43:58Z" , "2023-03-21T06:43:58Z" ),
91
+ ("2023-10-06T07:00:00Z" , "2023-10-06T07:00:00Z" ),
92
+ ]
93
+
94
+ for input_timestamp , expected_output in timestamps :
95
+ expected_datetime = _dt .datetime .strptime (expected_output ,
96
+ "%Y-%m-%dT%H:%M:%SZ" )
97
+ expected_datetime = expected_datetime .replace (tzinfo = _dt .timezone .utc )
98
+ assert second_timestamp_conversion (
99
+ input_timestamp ) == expected_datetime
83
100
84
101
def test_is_nanoseconds_timestamp ():
85
102
"""
@@ -95,19 +112,28 @@ def test_is_nanoseconds_timestamp():
95
112
nanosecond_timestamp3 = "2023-03-21T06:43:58.564738291Z"
96
113
nanosecond_timestamp4 = "2023-08-15T22:22:22.222222222Z"
97
114
98
- assert is_precision_timestamp (microsecond_timestamp1 ) is False
99
- assert is_precision_timestamp (microsecond_timestamp2 ) is False
100
- assert is_precision_timestamp (microsecond_timestamp3 ) is False
101
- assert is_precision_timestamp (microsecond_timestamp4 ) is False
102
- assert is_precision_timestamp (nanosecond_timestamp1 ) is True
103
- assert is_precision_timestamp (nanosecond_timestamp2 ) is True
104
- assert is_precision_timestamp (nanosecond_timestamp3 ) is True
105
- assert is_precision_timestamp (nanosecond_timestamp4 ) is True
115
+ second_timestamp1 = "2023-01-01T12:34:56Z"
116
+ second_timestamp2 = "2023-02-14T14:37:52Z"
117
+ second_timestamp3 = "2023-03-21T06:43:58Z"
118
+ second_timestamp4 = "2023-08-15T22:22:22Z"
119
+
120
+ assert get_precision_timestamp (microsecond_timestamp1 ) is PrecisionTimestamp .MICROSECONDS
121
+ assert get_precision_timestamp (microsecond_timestamp2 ) is PrecisionTimestamp .MICROSECONDS
122
+ assert get_precision_timestamp (microsecond_timestamp3 ) is PrecisionTimestamp .MICROSECONDS
123
+ assert get_precision_timestamp (microsecond_timestamp4 ) is PrecisionTimestamp .MICROSECONDS
124
+ assert get_precision_timestamp (nanosecond_timestamp1 ) is PrecisionTimestamp .NANOSECONDS
125
+ assert get_precision_timestamp (nanosecond_timestamp2 ) is PrecisionTimestamp .NANOSECONDS
126
+ assert get_precision_timestamp (nanosecond_timestamp3 ) is PrecisionTimestamp .NANOSECONDS
127
+ assert get_precision_timestamp (nanosecond_timestamp4 ) is PrecisionTimestamp .NANOSECONDS
128
+ assert get_precision_timestamp (second_timestamp1 ) is PrecisionTimestamp .SECONDS
129
+ assert get_precision_timestamp (second_timestamp2 ) is PrecisionTimestamp .SECONDS
130
+ assert get_precision_timestamp (second_timestamp3 ) is PrecisionTimestamp .SECONDS
131
+ assert get_precision_timestamp (second_timestamp4 ) is PrecisionTimestamp .SECONDS
106
132
107
133
108
134
def test_normalize_document_path ():
109
135
"""
110
- Testing "document" path passed to Firestore event listener
136
+ Testing "document" path passed to Firestore event listener
111
137
is normalized.
112
138
"""
113
139
test_path = "/test/document/"
0 commit comments