1515Internal utils tests.
1616"""
1717from 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
1919import datetime as _dt
2020
2121test_bucket = "python-functions-testing.appspot.com"
@@ -80,6 +80,23 @@ def test_nanosecond_conversion():
8080 assert nanoseconds_timestamp_conversion (
8181 input_timestamp ) == expected_datetime
8282
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
83100
84101def test_is_nanoseconds_timestamp ():
85102 """
@@ -95,19 +112,28 @@ def test_is_nanoseconds_timestamp():
95112 nanosecond_timestamp3 = "2023-03-21T06:43:58.564738291Z"
96113 nanosecond_timestamp4 = "2023-08-15T22:22:22.222222222Z"
97114
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
106132
107133
108134def test_normalize_document_path ():
109135 """
110- Testing "document" path passed to Firestore event listener
136+ Testing "document" path passed to Firestore event listener
111137 is normalized.
112138 """
113139 test_path = "/test/document/"
0 commit comments