-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathtest_rfc3339.py
67 lines (57 loc) · 2.99 KB
/
test_rfc3339.py
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
62
63
64
65
66
67
# Copyright 2020 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test cases for the firebase_admin._rfc3339 module."""
import pytest
from firebase_admin import _rfc3339
def test_epoch():
expected = pytest.approx(0)
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00Z") == expected
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00z") == expected
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00+00:00") == expected
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00-00:00") == expected
assert _rfc3339.parse_to_epoch("1970-01-01T01:00:00+01:00") == expected
assert _rfc3339.parse_to_epoch("1969-12-31T23:00:00-01:00") == expected
def test_pre_epoch():
expected = -5617641600
assert _rfc3339.parse_to_epoch("1791-12-26T00:00:00Z") == expected
assert _rfc3339.parse_to_epoch("1791-12-26T00:00:00+00:00") == expected
assert _rfc3339.parse_to_epoch("1791-12-26T00:00:00-00:00") == expected
assert _rfc3339.parse_to_epoch("1791-12-26T01:00:00+01:00") == expected
assert _rfc3339.parse_to_epoch("1791-12-25T23:00:00-01:00") == expected
def test_post_epoch():
expected = 904892400
assert _rfc3339.parse_to_epoch("1998-09-04T07:00:00Z") == expected
assert _rfc3339.parse_to_epoch("1998-09-04T07:00:00+00:00") == expected
assert _rfc3339.parse_to_epoch("1998-09-04T08:00:00+01:00") == expected
assert _rfc3339.parse_to_epoch("1998-09-04T06:00:00-01:00") == expected
def test_micros_millis():
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00Z") == pytest.approx(0)
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00.1Z") == pytest.approx(0.1)
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00.001Z") == pytest.approx(0.001)
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00.000001Z") == pytest.approx(0.000001)
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00+00:00") == pytest.approx(0)
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00.1+00:00") == pytest.approx(0.1)
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00.001+00:00") == pytest.approx(0.001)
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00.000001+00:00") == pytest.approx(0.000001)
def test_nanos():
assert _rfc3339.parse_to_epoch("1970-01-01T00:00:00.0000001Z") == pytest.approx(0)
@pytest.mark.parametrize('datestr', [
'not a date string',
'1970-01-01 00:00:00Z',
'1970-01-01 00:00:00+00:00',
'1970-01-01T00:00:00',
])
def test_bad_datestrs(datestr):
with pytest.raises(ValueError):
_rfc3339.parse_to_epoch(datestr)