Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_postgresql_converters.py
Show All 29 Lines | [ | ||||
"offset": 0, | "offset": 0, | ||||
"neg_utc_offset": None, | "neg_utc_offset": None, | ||||
"offset_bytes": None, | "offset_bytes": None, | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=1234567890, microseconds=0,), | timestamp=Timestamp(seconds=1234567890, microseconds=0,), | ||||
offset=120, | |||||
negative_utc=False, | |||||
offset_bytes=b"+0200", | offset_bytes=b"+0200", | ||||
), | ), | ||||
{ | { | ||||
"timestamp": "2009-02-13T23:31:30+00:00", | "timestamp": "2009-02-13T23:31:30+00:00", | ||||
"offset": 120, | "offset": 120, | ||||
"neg_utc_offset": False, | "neg_utc_offset": False, | ||||
"offset_bytes": b"+0200", | "offset_bytes": b"+0200", | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=1123456789, microseconds=0,), | timestamp=Timestamp(seconds=1123456789, microseconds=0,), | ||||
offset=0, | |||||
negative_utc=True, | |||||
offset_bytes=b"-0000", | offset_bytes=b"-0000", | ||||
), | ), | ||||
{ | { | ||||
"timestamp": "2005-08-07T23:19:49+00:00", | "timestamp": "2005-08-07T23:19:49+00:00", | ||||
"offset": 0, | "offset": 0, | ||||
"neg_utc_offset": True, | "neg_utc_offset": True, | ||||
"offset_bytes": b"-0000", | "offset_bytes": b"-0000", | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=1234567890, microseconds=0,), | timestamp=Timestamp(seconds=1234567890, microseconds=0,), | ||||
offset=42, | |||||
negative_utc=False, | |||||
offset_bytes=b"+0042", | offset_bytes=b"+0042", | ||||
), | ), | ||||
{ | { | ||||
"timestamp": "2009-02-13T23:31:30+00:00", | "timestamp": "2009-02-13T23:31:30+00:00", | ||||
"offset": 42, | "offset": 42, | ||||
"neg_utc_offset": False, | "neg_utc_offset": False, | ||||
"offset_bytes": b"+0042", | "offset_bytes": b"+0042", | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=1634366813, microseconds=0,), | timestamp=Timestamp(seconds=1634366813, microseconds=0,), | ||||
offset=-120, | |||||
negative_utc=False, | |||||
offset_bytes=b"-0200", | offset_bytes=b"-0200", | ||||
), | ), | ||||
{ | { | ||||
"timestamp": "2021-10-16T06:46:53+00:00", | "timestamp": "2021-10-16T06:46:53+00:00", | ||||
"offset": -120, | "offset": -120, | ||||
"neg_utc_offset": False, | "neg_utc_offset": False, | ||||
"offset_bytes": b"-0200", | "offset_bytes": b"-0200", | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=0, microseconds=0,), | timestamp=Timestamp(seconds=0, microseconds=0,), offset_bytes=b"-0200", | ||||
offset=-120, | |||||
negative_utc=False, | |||||
offset_bytes=b"-0200", | |||||
), | ), | ||||
{ | { | ||||
"timestamp": "1970-01-01T00:00:00+00:00", | "timestamp": "1970-01-01T00:00:00+00:00", | ||||
"offset": -120, | "offset": -120, | ||||
"neg_utc_offset": False, | "neg_utc_offset": False, | ||||
"offset_bytes": b"-0200", | "offset_bytes": b"-0200", | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=0, microseconds=1,), | timestamp=Timestamp(seconds=0, microseconds=1,), offset_bytes=b"-0200", | ||||
offset=-120, | |||||
negative_utc=False, | |||||
offset_bytes=b"-0200", | |||||
), | ), | ||||
{ | { | ||||
"timestamp": "1970-01-01T00:00:00.000001+00:00", | "timestamp": "1970-01-01T00:00:00.000001+00:00", | ||||
"offset": -120, | "offset": -120, | ||||
"neg_utc_offset": False, | "neg_utc_offset": False, | ||||
"offset_bytes": b"-0200", | "offset_bytes": b"-0200", | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=-1, microseconds=0,), | timestamp=Timestamp(seconds=-1, microseconds=0,), offset_bytes=b"-0200", | ||||
offset=-120, | |||||
negative_utc=False, | |||||
offset_bytes=b"-0200", | |||||
), | ), | ||||
{ | { | ||||
"timestamp": "1969-12-31T23:59:59+00:00", | "timestamp": "1969-12-31T23:59:59+00:00", | ||||
"offset": -120, | "offset": -120, | ||||
"neg_utc_offset": False, | "neg_utc_offset": False, | ||||
"offset_bytes": b"-0200", | "offset_bytes": b"-0200", | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=-1, microseconds=1,), | timestamp=Timestamp(seconds=-1, microseconds=1,), offset_bytes=b"-0200", | ||||
offset=-120, | |||||
negative_utc=False, | |||||
offset_bytes=b"-0200", | |||||
), | ), | ||||
{ | { | ||||
"timestamp": "1969-12-31T23:59:59.000001+00:00", | "timestamp": "1969-12-31T23:59:59.000001+00:00", | ||||
"offset": -120, | "offset": -120, | ||||
"neg_utc_offset": False, | "neg_utc_offset": False, | ||||
"offset_bytes": b"-0200", | "offset_bytes": b"-0200", | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=-3600, microseconds=0,), | timestamp=Timestamp(seconds=-3600, microseconds=0,), | ||||
offset=-120, | |||||
negative_utc=False, | |||||
offset_bytes=b"-0200", | offset_bytes=b"-0200", | ||||
), | ), | ||||
{ | { | ||||
"timestamp": "1969-12-31T23:00:00+00:00", | "timestamp": "1969-12-31T23:00:00+00:00", | ||||
"offset": -120, | "offset": -120, | ||||
"neg_utc_offset": False, | "neg_utc_offset": False, | ||||
"offset_bytes": b"-0200", | "offset_bytes": b"-0200", | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=-3600, microseconds=1,), | timestamp=Timestamp(seconds=-3600, microseconds=1,), | ||||
offset=-120, | |||||
negative_utc=False, | |||||
offset_bytes=b"-0200", | offset_bytes=b"-0200", | ||||
), | ), | ||||
{ | { | ||||
"timestamp": "1969-12-31T23:00:00.000001+00:00", | "timestamp": "1969-12-31T23:00:00.000001+00:00", | ||||
"offset": -120, | "offset": -120, | ||||
"neg_utc_offset": False, | "neg_utc_offset": False, | ||||
"offset_bytes": b"-0200", | "offset_bytes": b"-0200", | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
TimestampWithTimezone( | TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=1234567890, microseconds=0,), | timestamp=Timestamp(seconds=1234567890, microseconds=0,), | ||||
offset=120, | |||||
negative_utc=False, | |||||
offset_bytes=b"+200", | offset_bytes=b"+200", | ||||
), | ), | ||||
{ | { | ||||
"timestamp": "2009-02-13T23:31:30+00:00", | "timestamp": "2009-02-13T23:31:30+00:00", | ||||
"offset": 120, | "offset": 120, | ||||
"neg_utc_offset": False, | "neg_utc_offset": False, | ||||
"offset_bytes": b"+200", | "offset_bytes": b"+200", | ||||
}, | }, | ||||
), | ), | ||||
], | ], | ||||
) | ) | ||||
def test_date(model_date, db_date): | def test_date(model_date, db_date): | ||||
assert converters.date_to_db(model_date) == db_date | assert converters.date_to_db(model_date) == db_date | ||||
assert ( | assert ( | ||||
converters.db_to_date( | converters.db_to_date( | ||||
date=None | date=None | ||||
if db_date["timestamp"] is None | if db_date["timestamp"] is None | ||||
else datetime.datetime.fromisoformat(db_date["timestamp"]), | else datetime.datetime.fromisoformat(db_date["timestamp"]), | ||||
offset=db_date["offset"], | |||||
neg_utc_offset=db_date["neg_utc_offset"], | |||||
offset_bytes=db_date["offset_bytes"], | offset_bytes=db_date["offset_bytes"], | ||||
) | ) | ||||
== model_date | == model_date | ||||
) | ) | ||||
def test_db_to_author(): | def test_db_to_author(): | ||||
# when | # when | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |