|
19 | 19 | from os import environ, path |
20 | 20 |
|
21 | 21 | from firebase_functions.private.util import ( |
22 | | - PrecisionTimestamp, |
23 | 22 | _unsafe_decode_id_token, |
24 | 23 | deep_merge, |
25 | 24 | firebase_config, |
26 | | - get_precision_timestamp, |
27 | | - microsecond_timestamp_conversion, |
28 | | - nanoseconds_timestamp_conversion, |
29 | 25 | normalize_path, |
30 | | - second_timestamp_conversion, |
| 26 | + timestamp_conversion, |
31 | 27 | ) |
32 | 28 |
|
33 | 29 | test_bucket = "python-functions-testing.appspot.com" |
@@ -56,88 +52,70 @@ def test_firebase_config_loads_from_env_file(): |
56 | 52 | ) |
57 | 53 |
|
58 | 54 |
|
59 | | -def test_microsecond_conversion(): |
| 55 | +def test_timestamp_conversion_supported_formats(): |
60 | 56 | """ |
61 | | - Testing microsecond_timestamp_conversion works as intended |
| 57 | + Testing shared timestamp conversion handles supported RTDB and CloudEvent formats. |
62 | 58 | """ |
63 | 59 | timestamps = [ |
64 | | - ("2023-06-20T10:15:22.396358Z", "2023-06-20T10:15:22.396358Z"), |
65 | | - ("2021-02-20T11:23:45.987123Z", "2021-02-20T11:23:45.987123Z"), |
66 | | - ("2022-09-18T09:15:38.246824Z", "2022-09-18T09:15:38.246824Z"), |
67 | | - ("2010-09-18T09:15:38.246824Z", "2010-09-18T09:15:38.246824Z"), |
| 60 | + ( |
| 61 | + "2024-04-10T12:00:00.000Z", |
| 62 | + _dt.datetime(2024, 4, 10, 12, 0, tzinfo=_dt.timezone.utc), |
| 63 | + ), |
| 64 | + ( |
| 65 | + "2024-04-10T12:00:00.123456Z", |
| 66 | + _dt.datetime(2024, 4, 10, 12, 0, 0, 123456, tzinfo=_dt.timezone.utc), |
| 67 | + ), |
| 68 | + ( |
| 69 | + "2024-04-10T12:00:00.123456+05:30", |
| 70 | + _dt.datetime( |
| 71 | + 2024, |
| 72 | + 4, |
| 73 | + 10, |
| 74 | + 12, |
| 75 | + 0, |
| 76 | + 0, |
| 77 | + 123456, |
| 78 | + tzinfo=_dt.timezone(_dt.timedelta(hours=5, minutes=30)), |
| 79 | + ), |
| 80 | + ), |
| 81 | + ( |
| 82 | + "2024-04-10T12:00:00.123456-0700", |
| 83 | + _dt.datetime( |
| 84 | + 2024, |
| 85 | + 4, |
| 86 | + 10, |
| 87 | + 12, |
| 88 | + 0, |
| 89 | + 0, |
| 90 | + 123456, |
| 91 | + tzinfo=_dt.timezone(-_dt.timedelta(hours=7)), |
| 92 | + ), |
| 93 | + ), |
| 94 | + ( |
| 95 | + "2023-01-01T12:34:56.123456789Z", |
| 96 | + _dt.datetime(2023, 1, 1, 12, 34, 56, 123456, tzinfo=_dt.timezone.utc), |
| 97 | + ), |
| 98 | + ( |
| 99 | + "2023-01-01T12:34:56.123456789+05:30", |
| 100 | + _dt.datetime( |
| 101 | + 2023, |
| 102 | + 1, |
| 103 | + 1, |
| 104 | + 12, |
| 105 | + 34, |
| 106 | + 56, |
| 107 | + 123456, |
| 108 | + tzinfo=_dt.timezone(_dt.timedelta(hours=5, minutes=30)), |
| 109 | + ), |
| 110 | + ), |
| 111 | + ( |
| 112 | + "2025-10-30T21:15:51Z", |
| 113 | + _dt.datetime(2025, 10, 30, 21, 15, 51, tzinfo=_dt.timezone.utc), |
| 114 | + ), |
68 | 115 | ] |
69 | 116 |
|
70 | | - for input_timestamp, expected_output in timestamps: |
71 | | - expected_datetime = _dt.datetime.strptime(expected_output, "%Y-%m-%dT%H:%M:%S.%fZ") |
72 | | - expected_datetime = expected_datetime.replace(tzinfo=_dt.timezone.utc) |
73 | | - assert microsecond_timestamp_conversion(input_timestamp) == expected_datetime |
74 | | - |
75 | | - |
76 | | -def test_nanosecond_conversion(): |
77 | | - """ |
78 | | - Testing nanoseconds_timestamp_conversion works as intended |
79 | | - """ |
80 | | - timestamps = [ |
81 | | - ("2023-01-01T12:34:56.123456789Z", "2023-01-01T12:34:56.123456Z"), |
82 | | - ("2023-02-14T14:37:52.987654321Z", "2023-02-14T14:37:52.987654Z"), |
83 | | - ("2023-03-21T06:43:58.564738291Z", "2023-03-21T06:43:58.564738Z"), |
84 | | - ("2023-08-15T22:22:22.222222222Z", "2023-08-15T22:22:22.222222Z"), |
85 | | - ] |
86 | | - |
87 | | - for input_timestamp, expected_output in timestamps: |
88 | | - expected_datetime = _dt.datetime.strptime(expected_output, "%Y-%m-%dT%H:%M:%S.%fZ") |
89 | | - expected_datetime = expected_datetime.replace(tzinfo=_dt.timezone.utc) |
90 | | - assert nanoseconds_timestamp_conversion(input_timestamp) == expected_datetime |
91 | | - |
92 | | - |
93 | | -def test_second_conversion(): |
94 | | - """ |
95 | | - Testing seconds_timestamp_conversion works as intended |
96 | | - """ |
97 | | - timestamps = [ |
98 | | - ("2023-01-01T12:34:56Z", "2023-01-01T12:34:56Z"), |
99 | | - ("2023-02-14T14:37:52Z", "2023-02-14T14:37:52Z"), |
100 | | - ("2023-03-21T06:43:58Z", "2023-03-21T06:43:58Z"), |
101 | | - ("2023-10-06T07:00:00Z", "2023-10-06T07:00:00Z"), |
102 | | - ] |
103 | | - |
104 | | - for input_timestamp, expected_output in timestamps: |
105 | | - expected_datetime = _dt.datetime.strptime(expected_output, "%Y-%m-%dT%H:%M:%SZ") |
106 | | - expected_datetime = expected_datetime.replace(tzinfo=_dt.timezone.utc) |
107 | | - assert second_timestamp_conversion(input_timestamp) == expected_datetime |
108 | | - |
109 | | - |
110 | | -def test_is_nanoseconds_timestamp(): |
111 | | - """ |
112 | | - Testing is_nanoseconds_timestamp works as intended |
113 | | - """ |
114 | | - microsecond_timestamp1 = "2023-06-20T10:15:22.396358Z" |
115 | | - microsecond_timestamp2 = "2021-02-20T11:23:45.987123Z" |
116 | | - microsecond_timestamp3 = "2022-09-18T09:15:38.246824Z" |
117 | | - microsecond_timestamp4 = "2010-09-18T09:15:38.246824Z" |
118 | | - |
119 | | - nanosecond_timestamp1 = "2023-01-01T12:34:56.123456789Z" |
120 | | - nanosecond_timestamp2 = "2023-02-14T14:37:52.987654321Z" |
121 | | - nanosecond_timestamp3 = "2023-03-21T06:43:58.564738291Z" |
122 | | - nanosecond_timestamp4 = "2023-08-15T22:22:22.222222222Z" |
123 | | - |
124 | | - second_timestamp1 = "2023-01-01T12:34:56Z" |
125 | | - second_timestamp2 = "2023-02-14T14:37:52Z" |
126 | | - second_timestamp3 = "2023-03-21T06:43:58Z" |
127 | | - second_timestamp4 = "2023-08-15T22:22:22Z" |
128 | | - |
129 | | - assert get_precision_timestamp(microsecond_timestamp1) is PrecisionTimestamp.MICROSECONDS |
130 | | - assert get_precision_timestamp(microsecond_timestamp2) is PrecisionTimestamp.MICROSECONDS |
131 | | - assert get_precision_timestamp(microsecond_timestamp3) is PrecisionTimestamp.MICROSECONDS |
132 | | - assert get_precision_timestamp(microsecond_timestamp4) is PrecisionTimestamp.MICROSECONDS |
133 | | - assert get_precision_timestamp(nanosecond_timestamp1) is PrecisionTimestamp.NANOSECONDS |
134 | | - assert get_precision_timestamp(nanosecond_timestamp2) is PrecisionTimestamp.NANOSECONDS |
135 | | - assert get_precision_timestamp(nanosecond_timestamp3) is PrecisionTimestamp.NANOSECONDS |
136 | | - assert get_precision_timestamp(nanosecond_timestamp4) is PrecisionTimestamp.NANOSECONDS |
137 | | - assert get_precision_timestamp(second_timestamp1) is PrecisionTimestamp.SECONDS |
138 | | - assert get_precision_timestamp(second_timestamp2) is PrecisionTimestamp.SECONDS |
139 | | - assert get_precision_timestamp(second_timestamp3) is PrecisionTimestamp.SECONDS |
140 | | - assert get_precision_timestamp(second_timestamp4) is PrecisionTimestamp.SECONDS |
| 117 | + for input_timestamp, expected_datetime in timestamps: |
| 118 | + assert timestamp_conversion(input_timestamp) == expected_datetime |
141 | 119 |
|
142 | 120 |
|
143 | 121 | def test_normalize_document_path(): |
|
0 commit comments